sim800 at 命令将数据发送到服务器 [英] sim800 at command post data to server
问题描述
我很难将数据发送到远程服务器,我可以发送 post 请求,但不确定如何添加服务器接收的数据.
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.
我已经浏览了数据表 http://www.jarzebski.pl/datasheets/SIM900_https-121018-1.00.pdf
尝试过
# 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
发送 http post 请求.但是我如何添加数据 - 我已经尝试将它添加到 url ?key=val 但没有任何乐趣 - 这里的任何帮助将不胜感激
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
推荐答案
httpdata=100,10000 表示 SIM800 应该在 10 秒内期望 100 个字节.
httpdata=100,10000 means that SIM800 should expect 100 bytes within 10 seconds.
这是我使用 HTTP 客户端完成此操作的方式:
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
此时,SIM800 应响应DOWNLOAD".这意味着它正在等待您的数据.发送您的数据;就我而言:
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}
等待 10 秒钟以发送其余命令.然后:
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.
我从这里获取信息:http://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands
在后端,使用Python Flask,这是我使用的代码
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)
这篇关于sim800 at 命令将数据发送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!