How to post data to ThingSpeak using AT+UHTTPC command?

Abbas Atefi on 8 Mar 2022 (Edited on 8 Mar 2022)
Latest activity Reply by Abbas Atefi on 11 Mar 2022

Hi,

I am using Ublox SARA-R410M to send (cellular) data to ThingSpeak cloud. I found in the Ublox manual that AT+UHTTPC (POST data command) can do the job. The link below is the location which my data will be saved on ThingSpeak (field1):

"https://api.thingspeak.com/update?api_key=WRITE_API_KEY&field1="

Note that the "WRITE_API_KEY" is 16 characters (combination of letters and numbers).

AT command: AT+UHTTPC=<profile_id>,5, path,<filename>,<data>,<HTTP_content_type>

Based on the information above, which items should I use for path and filename? And how can I use this command in Arduino code?

I appreciate any help in advance.

Abbas

Christopher Stapels
Christopher Stapels on 9 Mar 2022 (Edited on 9 Mar 2022)

I would use GET, its a bit more simple. HTTP command 1 I think the path and filename are the url. You can find them in the write data documentation .

Here is the write format for the GET request. (which you have already in your post)

https://api.thingspeak.com/update.json?api_key=xxxxxxxxxxxxxxxx

I think "https:...com/" is the path and update.json is the filename. the rest are parameters

This document seems to say the syntax is AT+UHTTPC=<profile_id>,<http_ command>,<path>,<filename>[, param1[,<param2>[,<param3>]]] I think you wont need the content type for the GET request.

Abbas Atefi
Abbas Atefi on 9 Mar 2022 (Edited on 9 Mar 2022)

Hi Christopher,

Thank you for your reply. I can see AT+UHTTPC also has GET request, but I can not see any item for "data" (page 323 in the manual below). Any idea how can I use the GET request for sending data?

https://www.u-blox.com/en/docs/UBX-17003787#%5B%7B%22num%22%3A2272%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C59.527%2C572.677%2Cnull%5D

Thank you, Abbas

Christopher Stapels
Christopher Stapels on 9 Mar 2022 (Edited on 9 Mar 2022)

Definitely check out the write data documentation that I linked above.

You add the data as a parameter.

https://api.thingspeak.com/update.json?api_key=xxxxxxxxxxxxxxxx&field1=dataHere&field2=moreData&etc.

There are eight fields, plus status and three location fields.

Each one can hold 255 characters (of string data) but ThingSpeak will attempt to interpret integers and floats for you.

Abbas Atefi
Abbas Atefi on 9 Mar 2022 (Edited on 9 Mar 2022)

Christopher,

1) I can see in the manual that the parameters (parameter 1, parameter 2,etc.) are not allowed for the GET command. Since the parameter 1 is for "data value", it seems the GET command can not be used for sending the data. What do you think? Another question is in the "Write a Channel Feed" of my ThingSpeak, I just have "update" not "update.json". Which one should I use for sending the data using the AT command?

2) If I want to use the POST command, do you think the syntax below is correct (for path, file name, and parameter 1)?

AT+UHTTPC= 0,5,"https://api.thingspeak.com/","update.json","?api_key=xxxxxxxxxxxxxxxx&field1=data",0

Christopher Stapels
Christopher Stapels on 10 Mar 2022 (Edited on 10 Mar 2022)

I think you can just use 1 URL, without the quotes for each parameter.

AT+UHTTPC= 0,5,"https://api.thingspeak.com/update.json?api_key=xxxxxxxxxxxxxxxx&field1=dataHere&field2=moreData&etc"

You don't need the .json, that's the format for the response from ThingSpeak.

The GET command can definitely be used for sending data, I would just give it a try and see. ThingSpeak's GET format with data is not completely standard for RESTful interfaces. I'm not 100% familiar with the right syntax, so I suggest you try a few combinations till you get it. If you do get it working, please let us know.

Abbas Atefi
Abbas Atefi on 11 Mar 2022

Christopher,

Thank you for your reply. I will try it and let you know if it will be successful. Please inform me if you can test it and find the solution.

Thanks,

Abbas