BGS2T Question - HTTP post with header and body content with data exceeding 128 characters | Telit Cinterion IoT Developer Community
November 1, 2019 - 9:32am, 3962 views
Hi there :)
I’m having trouble with HTTP post using the BGS2T with data of more than 120 characters, with headers and data content in the HTTP Post body.
After reading the documentation (page 256 of BGS2T AT command specification document) I understand this is due to the hcContLen setting that I need to set correctly and then to use the AT^SISW command.
I have attached screenshots of an example of the required implementation using APITester for simulating the http request and PTSV2 to confirm receiving the http post request.
HTTP Post request settings on API tester:
Result of http post received on PTSV2:
Here is my current working method for more than 120 characters using a terminal program and the BGS2T modem:
AT
OK
AT^SCFG="TCP/WithURCs","on" ^SCFG: "Tcp/WithURCs","on"
OK
AT^SICS=2,"conType","GPRS0"
OK
AT^SISS=2,"srvType","http"
OK
AT^SISS=2,"conId","2"
OK
AT^SISS=2,"alphabet","1"
OK
AT^SISS=2,hcMethod,1
OK
AT^SISS=2,"address","http://ptsv2.com/t/UBIDOTS/post"
OK
AT^SISS=2,"hcContent","{In computing POST is a request method supported by HTTP used by the World Wide Web By design the POST request method r}"
OK
AT^SISS=2,"hcProp","Content-Type: application/json"
OK
AT^SISO=2
OK
^SIS: 2, 0, 2201, "HTTP/1.1 200 OK"
^SISR: 2, 1
AT^SISR=2,1000
^SISR: 2, 54
Thank you for this dump. I hope you have a lovely day!
OK
^SISR: 2, 2
Can you please assist me by providing an example AT command set for making an http post with more than 120 characters that also contains data content (body) and a header?
(Perhaps by editing my working AT command in this thread) set to achieve this)
Thank you,
Kind regards,
Hermann
Hello,
To send more data you need not to use "hcContent" but send the data with AT^SISW command. Please see the example from the AT commands specification document:
at^siss=1,srvType,"Http"
OK
at^siss=1,conId,1
OK
at^siss=1,hcMethod,1
OK
at^siss=1,address,"http://192.168.1.3/datafiles/dummy/dummy.txt"
OK
at^siss=1,hcContLen,180
OK
at^siso=1
OK
at^sisw=1,100
^SISW: 1,100,0
OK
at^sisw=1,100
^SISW: 1,80,0
OK
...
Regards,
Bartłomiej
Hi Bartlomiej,
I have tried the example, however, the modem "hangs" after receiving the response after the at^siso=1 command. (Only turning the modem on and off resumes operation of the modem.). I have waited for 5 minutes after the command and I have tried a different modem as well, but I get the same response.
I have tried adding some content as well (thinking that the modem might be getting errors due to the message being empty and thus hcContLen,180 causing problems, but this has not worked either:
ATTEMPT 1
AT^SCFG="TCP/WithURCs","on"
^SCFG: "Tcp/WithURCs","on"
OK
AT^SICS=1,"conType","GPRS0"
OK
at^siss=1,srvType,"Http"
OK
at^siss=1,conId,1
OK
at^siss=1,hcMethod,1
OK
AT^SISS=1,"address","http://ptsv2.com/t/UBIDOTS/post"
OK
at^siss=1,hcContLen,180
OK
at^siso=1
OK
^SISW: 1, 1
at^sisw=1,100
^SISW: 1, 100, 0
(The modems “hangs” at this point and cannot receive further AT commands. Only turning the modem on and off allows the modem to recover)
ATTEMPT 2
AT^SCFG="TCP/WithURCs","on" ^SCFG: "Tcp/WithURCs","on"
OK
AT^SICS=1,"conType","GPRS0"
OK
at^siss=1,srvType,"Http"
OK
at^siss=1,conId,1
OK
at^siss=1,hcMethod,1
OK
AT^SISS=1,"address","http://ptsv2.com/t/UBIDOTS/post"
OK
AT^SISS=1,"hcContent","*****"
OK
at^siss=1,hcContLen,5
OK
at^siso=1
OK
^SISW: 1, 1
at^sisw=1,100 ^SISW: 1, 5, 0
(The modems “hangs” at this point and cannot receive further AT commands. Only turning the modem on and off allows the modem to recover)
I have also tried the http post example from https://iot-developer.thalesgroup.com/showcase/zoc-script-internet-services-example-http-post-get-bgs2ehs6 but I receive an error when trying:
Here is the information with regards to the modem firmware:
ATI1
Cinterion
BGS2-W
REVISION 01.301
A-REVISION 01.000.16
OK
Regards,
Hermann
**Correction, the modem hangs after the at^sisw=1,100 response
Hello,
I have also tried and in my case it did work.
Here's my log:
at^siso=1
OK
^SISW: 1, 1
at^sisw=1,180
^SISW: 1, 180, 0
// here the AT interface is switched to data **** and expects 180 characters to be sent
// after all the declared charactes are sent the module returns the reply
OK
^SISW: 1, 2
^SIS: 1, 0, 2201, "HTTP/1.1 200 OK"
^SISR: 1, 1
at^sisr=1,1000
^SISR: 1, 54
Thank you for this dump. I hope you have a lovely day!
OK
^SISR: 1, 2
at^sisc=1
OK
Did you send all the data after ^SISW: URC? If not this may be the reason why the module did not reply to AT commands.
Regards,
Bartłomiej
Hi Bartlomiej,
Thank you for the info and for checking on your side... I have checked the information on https://ptsv2.com/t/UBIDOTS
I see that an http GET request has been performed on your side: https://ptsv2.com/t/UBIDOTS/d/420070764
Just to confirm, I'm trying to implement a http POST request with information in the post body (more than 128 characters), such as the following: https://ptsv2.com/t/UBIDOTS/d/402792172
Would it be possible to please send an example of this with the entire AT command sequence? (I'm assuming you set at^siss=0,hcMethod,0 which resulted in a get request)
Thank you,
Kind regards,
Hermann
Hello,
I didn't use your address for my test. I have created my own 'toilet' - please see here: http://ptsv2.com/t/8htaf-1572968625
For my test I have used the commands from your attempt 1 log.
The only difference was the address:
AT^SISS=1,"address","http://ptsv2.com/t/8htaf-1572968625/post"
and I have also confiured APN to be able to connect:
AT^SICS=1,"apn","internet"
I have used the same content length:
at^siss=1,hcContLen,180
and after opening the connection I was entering random characters from the keyboard after '^SISW: 1, 180, 0' URC until I got the 'OK' reply.
Best regards,
Bartłomiej
Hi Bartlomiej,
Thank you for clarifying that to me, that is the info I needed to get it working :)
For future reference to anyone reading this thread and struggling with the same problem, here is a step by step post on how to perform an HTTP post with header and body content with data exceeding 128 characters. (AT commands sent to the module are in bold, responses are in itallics and additional comments by me are underlined)
AT
OK
AT^SCFG="TCP/WithURCs","on" ^SCFG: "Tcp/WithURCs","on"
OK
AT^SICS=1,"conType","GPRS0"
OK
AT^SISS=1,"srvType","http"
OK
AT^SISS=1,"conId","1"
OK
AT^SISS=1,"alphabet","1"
OK
AT^SISS=1,hcMethod,1
OK
AT^SISS=1,"hcProp","Content-Type: application/json"
(This is only required if you need to add headers in your http post)
OK
AT^SISS=1,"address","http://ptsv2.com/t/UBIDOTS/post"
OK
(Create your own “dump” on PTSV2 to test)
AT^SISS=1,hcContLen,312
OK
(This command specifies that the message will be 312 characters. This information must be set correctly)
AT^SISO=1
OK
^SISW: 1, 1
AT^SISW=1,312
^SISW: 1, 312, 0
(Here you need to send the http body. The message has to be the correct length as stated in the previous command)
{In computing POST is a request method supported by HTTP used by the World Wide Web By design the POST request method requests that a web server accepts the data enclosed in the body of the request message most likely for storing it It is often used when uploading a file or when submitting a completed web form}
OK
^SISW: 1, 2
^SIS: 1, 0, 2201, "HTTP/1.1 200 OK"
^SISR: 1, 1
AT^SISR=1,1000
(This portion is not required, but is useful to ensure the expected response from the server is received)
^SISR: 1, 54
Thank you for this dump. I hope you have a lovely day!
OK
^SISR: 1, 2
AT^SISC=1
OK
Thank you again,
Kind regards,
Hermann
Hi Hermann,
Great that it also worked for you!
Thank you for this summary!
Best regards,
Bartłomiej