5

I am having a website which accepts json data with post method.It works fine when i try sending the request from POSTMAN rest client. When i am trying to the same using AT commands its failing.

enter image description here

This is the AT sequence i tried

AT
AT+CREG? 
AT+CGATT?
AT+CIPSHUT
AT+CIPSTATUS
AT+CIPMUX=0 
AT+CGDCONT=1,"IP","airtelgprs.com"
AT+CSTT="airtelgprs.com"
AT+CIICR
AT+CIFSR
AT+CIPSTATUS
AT+CIPSTART= "TCP","obdsam.herokuapp.com","80"
AT+CIPSEND
>
POST /newtasks HTTP/1.1 (Ctrl+M + Ctrl+J)
HOST: obdsam.herokuapp.com" (Ctrl+M + Ctrl+J)
Accept: application/json (Ctrl+M + Ctrl+J)
Content-Type: application/json (Ctrl+M + Ctrl+J)
{"RPM":"41","ECT":"20"} (Ctrl+M + Ctrl+J)
(ctrl+j)(ctrl+z)

What could be the issue?

This is the reply from serial terminal

enter image description here

ganeshredcobra
  • 1,881
  • 3
  • 28
  • 44

2 Answers2

2

Solved the issue. After AT+CIPSEND the message must be like this >

POST /newtasks HTTP/1.1 (Ctrl+M + Ctrl+J)
HOST: obdsam.herokuapp.com (Ctrl+M + Ctrl+J)
Accept: application/json (Ctrl+M + Ctrl+J)
Content-Type: application/json(Ctrl+M + Ctrl+J)
Content-Length: 23 (Ctrl+M + Ctrl+J) (Ctrl+M + Ctrl+J)
{"RPM":"55","ECT":"55"} (Ctrl+M + Ctrl+J)(ctrl+j)(ctrl+z)
ganeshredcobra
  • 1,881
  • 3
  • 28
  • 44
1

I personally have observed common mistakes in omitting (ctrl+m)(ctrl+j) combinations. In the above post , the first five lines belongs to HTTP header and the sixth line is the HTTP body. Note that the fifth line should end with two sets of carriage return and line feed to indicate end of HTTP header.

Also, wait until CIPSTART returns CONNECT OK, and wait until > appears afterCIPSEND`.

If you are GET/POST-ing a page with dynamic IP, your code should be quick enough to fetch/post the page before the IP changes.

Have a nice day....

Jadeye
  • 3,551
  • 4
  • 47
  • 63