BGS2T - Post data to UBIDOTS server (HTTP Post with header and body) | Telit Cinterion IoT Developer Community
May 6, 2019 - 4:15pm, 3644 views
Hi there,
I'm trying to post data to the "Ubidots" IOT platform with a BGS2T ****m.
The Ubidots API documentation can be found here: https://ubidots.com/docs/hw/#send-data)
At the moment I can post data using apitester.com as shown below: (The token has been crossed out)

I assume (and please correct me if I am wrong) that hcProp is the equivalent of "request header" and hcContent is the equivalent of "post data".
I am sending the following AT commands using Teraterm. The token number has been replaced by ____.
The command that is underlined in bold is giving an error, the ****m "does not like" the extra quotation marks.
AT
AT^SCFG="Tcp/WithURCs","on"
AT^SICS=1,"conType","GPRS0"
AT^SISS=1,"srvType","http"
AT^SISS=1,"conId","1"
AT^SISS=1,"address","http://industrial.api.ubidots.com/api/devices/cellular-****m-1/?token=__..."
AT^SISS=1,"hcContLen","0"
AT^SISS=1,"hcContent","{"temperature": 10}"
AT^SISS=1,"hcProp","Content-Type: application/json"
AT^SISO=1
AT^SISR=1,500
AT^SISC=1
AT^SCFG="Tcp/WithURCs","on"
AT^SICS=1,"conType","GPRS0"
AT^SISS=1,"srvType","http"
AT^SISS=1,"conId","1"
AT^SISS=1,"address","http://industrial.api.ubidots.com/api/devices/cellular-****m-1/?token=__..."
AT^SISS=1,"hcContLen","0"
AT^SISS=1,"hcContent","{"temperature": 10}"
AT^SISS=1,"hcProp","Content-Type: application/json"
AT^SISO=1
AT^SISR=1,500
AT^SISC=1
Can you please advise if my assumption of the "Header=hcProp" and "Post data=hcContent" is correct and how to allow for quotations marks in the hcContent field. (If I am implementing the http post correctly)
Thank you!
Hello,
You are right - what you put into hpProp is added to HTTP header and what you put into hcContent is sent as POST data in case of POST. If there is more data you can set hcContLen to value grater than 0 and send the data with AT^SISW command. There was ERROR reply because the quotation mark was treated by the command parser as end of data and after that there was more characters. To send quotation mark in this way you can use an escape sequence \22 instead of quotation mark.
Best regards,
Bartłomiej
Hi Bartlomiej,
Thank you for the reply... Unfortunately have not been able to get the post working. Here is a comparison for the received vs the expected response from the UBIDOTS server. I think I am missing something else as well, because if I simulate "wrong" data in the "Post data" field in API tester I still get a "200/201" response.
Expected Response
Response Headers
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 27 Jun 2019 06:44:15 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Allow: GET, POST, HEAD, OPTIONS
Vary: Origin, ******
Response Body
{"{/22temperature/22: 10}": [{"status_code": 400, "errors": {"value": ["This field may not be null."], "variable": "field missing"}}]}
Current response:
{"id": "5cbf03ee1d84726ddcb27064", "organization_data": {"id": 19823, "name": "T
urbex", "properties": {"color": "#00BCD4"}}, "organization": 19823, "enabled": t
rue, "owner": "http://industrial.api.ubidots.com/api/v1.6/users/23697", "label":
"cellular-modem-1", "parent": null, "name": "cellular-modem-1", "url": "http://
industrial.api.ubidots.com/api/v1.6/datasources/5cbf03ee1d84726ddcb27064", "cont
ext": {"": null, "_config": {"": {"text": "", "type": "text", "description": ""}
}}, "tags": [], "cre
Can you please see if I am doing something else wrong in this example or perhaps make an example of posting to the Ubidots server? (Ubidots might even add this to their user guides and add the BGS2T modem for their example hardware)
Thank you!
Kind regards,
Hermann Havenstein
Hello,
So it seems now that POST sending from the module is possible.
I'm not sure if you get the wrong reply while sending POST from the module only while it's proper when you use other software or it's always not correct regardless how you send the POST.
Anyway I think that you could try to send the same POST to some public test server where you could see what was exactly received by the server (header and body) and compare it with what Ubidots expects. Maybe there will be some differences.
Regards,
Bartłomiej
Hi Bartlomiej,
I managed to find the problem... I was mixing up some of the http get and http post setup settings in the AT commands. I have posted the incorrect original attempt with the correct working attempt.
INCORRECT ORIGINAL ATTEMPT
CORRECT WORKING ATTEMPT
AT^SCFG="Tcp/WithURCs","on"
AT^SICS=1,"conType","GPRS0"
AT^SISS=1,"srvType","http"
AT^SISS=1,"conId","1"
AT^SISS=2,"alphabet","1"
AT^SISS=1,"address","http://ptsv2.com/t/UBIDOTS/post"
AT^SISS=1,"hcContLen","0"
AT^SISS=1,"hcContent","{"temperature": 10}"
AT^SISS=1,"hcProp","Content-Type: application/json"
AT^SISO=1
AT^SISC=1
AT^SCFG="Tcp/WithURCs","on"
AT^SICS=2,"conType","GPRS0"
AT^SISS=2,"srvType","http"
AT^SISS=2,"conId","2"
AT^SISS=2,"alphabet","1"
AT^SISS=2,hcMethod,1
AT^SISS=2,"address","http://ptsv2.com/t/UBIDOTS/post"
AT^SISS=2,"hcContent","{\22temperature: 10\22}"
AT^SISS=2,"hcProp","Content-Type: application/json"
AT^SISO=2
AT^SISC=2
The data is reflecting correctly on https://ptsv2.com/t/UBIDOTS#
Thank you!
Kind regards,
Hermann Havenstein
Sorry for the format, the table did not paste correctly and I cannot seem to edit or delete my comment. Here is the intended format:
Hello,
Thank you for the update. Great that it works!
I've assumed that you were finally able to send POST from the module and didn't notice that hcMethod was missing in your first log already where we concentrated on quotation marks problem...
Regards,
Bartłomiej