-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathA7600X.py
39 lines (33 loc) · 1.1 KB
/
A7600X.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from machine import UART, Pin
from time import sleep
import ujson
class A7600X:
def __init__(self, interface, baudrate, txpin, rxpin):
self.uart = UART(interface,
baudrate=baudrate,
bits=8,
parity=None,
stop=1,
tx=Pin(txpin),
rx=Pin(rxpin))
def _exe_command(self, command):
self.uart.write(command+'\r\n')
sleep(2)
response = self.uart.read()
print(response.decode('utf-8'))
return response
def _http_post(self, url, type, data):
json_data = ujson.dumps(data)
data_length = len(json_data)
uart_commands = [
'AT+HTTPINIT',
'AT+HTTPPARA="URL","' + url + '"',
'AT+HTTPPARA="CONTENT","' + type + '"',
'AT+HTTPDATA={},10000'.format(data_length),
json_data,
'AT+HTTPACTION=1',
'AT+HTTPHEAD',
'AT+HTTPTERM'
]
for command in uart_commands:
self._exe_command(command)