sim800 at command post data to server

亡梦爱人 提交于 2019-12-03 09:31:23

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)
trojan_spike

I managed to get it to do what I need, this code-snippet will likely help others

AT+CGATT=1                  # enter GPRS configuration mode 
AT+CIPMUX=0                 # Disable multi IP connection mode.  Single IP cnxn only
AT+CSTT="APN","USER","PASS"
AT+CIICR                    # bring up wireless connection with GPRS and CSD 
AT+CIFSR                    # ip up - gprs working
AT+CIPSHUT                  # Exit GPRS configuration mode

# Now do a post request to remote server api in json format. 
# Change IP_ADDR|DOMAIN for the IP or domain name of your server.  
# Change 2000 to its port
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 stuck on it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!