sim800 at command post data to server

trojan_spike picture trojan_spike · Oct 26, 2015 · Viewed 37.2k times · Source

I'm stumped with sending data to a remote server , I'm able to send a post request but not sure how to add data which is then received by the server.

I've went 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 post request. But how do I add data - I've tried adding it to the url ?key=val but no joy - any help here will be appreciated

Answer

Alan Alvarez picture Alan Alvarez · Dec 9, 2015

httpdata=100,10000 means that SIM800 should expect 100 bytes within 10 seconds.

This is how I accomplished this using the 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 "DOWNLOAD". Which means it's expecting your data. Send in your data; in my case:

{"location_id": 238, "fill_percent": 90}

Wait 10 seconds to send the rest of the commands. Then:

AT+HTTPACTION=1
AT+HTTPREAD
AT+HTTPTERM

That did it for me. Hope it helps.

This is where I got the 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)