Sim800 when sending data to the server
I am focused on sending data to a remote server, I can send a post request but not sure how to add the data which is then accepted by the server.
I have looked through the datasheet http://www.jarzebski.pl/datasheets/SIM900_https-121018-1.00.pdf
tried
# usual at+sapbr=1,1 set up
+HTTPINIT
+HTTPPARA = "CID",1
+HTTPPARA="URL","IP-ADDRESS:PORT"
+httpdata=100,10000
# Where do I add the post data ?
+httpaction=1
which sends the HTTP request. But how to add data - I tried to add it to url? Key = val but no joy - any help here would be appreciated
httpdata = 100,10000 means the SIM800 should wait for 100 bytes for 10 seconds.
This is how I did it using an HTTP client:
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://url.com/endPoint"
AT+HTTPPARA="CONTENT","application/json"
AT+HTTPDATA=40,10000
At this point, the SIM800 should respond with LOAD. This means that it is expecting your data. Send data; in my case:
{"location_id": 238, "fill_percent": 90}
Wait 10 seconds for the rest of the commands to be sent. Then:
AT+HTTPACTION=1 AT+HTTPREAD AT+HTTPTERM
This did it for me. Hope it helps.
Here I got information from: http://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands
In the backend, using Python Flask, this is the code I used
@app.route('/reportTrashLevel', methods=['POST'])
def report_trash_level():
data = request.get_json()
database.insert_trash_level(data)
return Response(status=200)
I managed to get it to do what I need, this piece of code will most likely help others
AT+CGATT=1
AT+CIPMUX=0
AT+CSTT="APN","USER","PASS"
AT+CIICR
AT+CIFSR # ip up - gprs working
AT+CIPSHUT # shut down
# Now do a post request to remote server api in json format. Express server
AT+CIPSTART="TCP","IP_ADDR|DOMAIN","2000"
AT+CIPSEND=119 # Num of char in tcp/ip data, \r & \n count as 1 char
POST /post HTTP/1.1
Host: **.**.***.***
Content-Type: application/json
Content-Length:23
{"postkey":"postvalue"}
Hope this helps the next person to get stuck on it.