如何通过AT命令发布数据?

时间:2019-04-12 06:16:53

标签: python-2.7 raspberry-pi3 at-command ftdi sim800

我正在使用树莓派和SIM800L(USB连接)通过HTTP POST REQUEST发送数据。这是我在Python中的代码:
导入的库:

import time, serial, sys, json

发送功能

sim800l = serial.Serial("/dev/ttyUSB0",baudrate=9600,timeout=0,rtscts=0,xonxoff=0)
def sendat1(cmd, msg=None):
    if cmd == 'res' : sim800l.write('Z'); return
    if cmd == 'out' : sim800l.write(chr(26)); return
    if cmd == None  :
        if msg !=None :
            sim800l.write(msg);
            print(msg)
            return sim800l.read(32798)
    sim800l.write('AT+'+cmd+'\r')
    time.sleep(1)#3
    obu = str(sim800l.inWaiting())
    msg = sim800l.read(32798)
    print(obu+':\n'+msg)
    return msg

在此处启动命令

try:
    if sim800l.inWaiting()>0: sim800l.flushInput()
    sendat1('res')
    #HTTP SEND POST REQUEST
    sendat1('CMEE=2')
    sendat1('CSQ')
    sendat1('CGATT?')
    sendat1('SAPBR=3,1,"APN","CMNET"')
    sendat1('SAPBR=2,1')
    sendat1('HTTPSSL=1')# im using https 
    sendat1('HTTPTERM')
    sendat1('HTTPINIT')
    sendat1('HTTPPARA="CID",1')
    sendat1('HTTPPARA="URL","https://myweb.com/save/'+'longit'+'/'+'latit'+'"')
    sendat1('HTTPPARA="CONTENT","application/json"')
    data = open("face.png","r").read()
    data = json.dumps({'picture':data.encode('base64')})
    sendat1('HTTPDATA='+str(sys.getsizeof(data))+',15000')
    sendat1(None,data)
    sendat1('HTTPREAD')
    sendat1('HTTPACTION=1')#post request

    sendat1('out')
finally:
    sim800l.close()

当我执行程序时,我陷入了命令HTTPREAD的调用中,但从未调用过。 是因为数据太大还是什么?我该怎么办?

0 个答案:

没有答案