Questo è il codice che uso per inviare il messaggio:
e nella pagina php ho solo la lettura in un file di log per vedere cosa arriva
Code:
#----------------------------------------import serialimport time#----------------------------------------# Serial speed# 75, 110, 150, 300, 600, 1200, 1800, # 2400, 4800, 9600, 14400, 19200, 57600, 115200ser = serial.Serial('/dev/myusb2', 19200, timeout=5, xonxoff = False, rtscts = False, bytesize = serial.EIGHTBITS, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE)ser.flushInput()#----------------------------------------def send_at(command, back, timeout): rec_buff = '' ser.write((command+'\r\n').encode()) time.sleep(timeout) if ser.inWaiting(): time.sleep(0.1 ) rec_buff = ser.read(ser.inWaiting()) if rec_buff != '': if back not in rec_buff.decode(): print(command + ' ERROR') print(command + ' back:\t' + rec_buff.decode()) return 0 else: print(rec_buff.decode()) return 1 else: print(command + ' no responce') return 0#----------------------------------------def sendMessage(url, data): size = len(data.encode("utf8")) try: #print(url) #print(data) #print(size) # Check the registration status send_at('AT+CREG?', 'OK', 1) send_at('AT+HTTPTERM', 'OK', 1) # Initialize HTTP service send_at('AT+HTTPINIT', 'OK', 1) # Set the HTTP URL send_at('AT+HTTPPARA="URL",\"'+url+'\"', 'OK', 2) # Set size send_at('AT+HTTPREAD=0,\"'+size+'\"', '', 1) ser.write(data.encode()) if 1 == send_at(b'\x1a'.decode(), 'OK', 5): print('send message successfully!') # Set up the HTTP action 0:READ 1:POST 2:HEAD send_at('AT+HTTPACTION=1', 'OK', 1) # Do a HTTP read #send_at('AT+HTTPREAD', '', 1) # Terminate the HTTP service send_at('AT+HTTPTERM', 'OK', 1) except: if ser != None: ser.close()#----------------------------------------url = "https://www.site_name.com/readData.php"data = "8.00,3.00,5.00,882.00,52.00,66.00,16.00,37.00,438,55"#----------------------------------------sendMessage(url, data)Code:
<?phpfile_put_contents('read.log', print_r($_POST, true), FILE_APPEND);?>Statistics: Posted by PaoloPK — Fri Jan 02, 2026 7:35 am