-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
38 lines (30 loc) · 1.04 KB
/
main.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
from httpclient import HttpClient
import machine, network, time
uart_qr = machine.UART(1, baudrate=9600, bits=8, parity=None, stop=1, rx=22, tx=19, timeout=50)
pinTrig = machine.Pin(23, machine.Pin.OUT)
pinDled = machine.Pin(33, machine.Pin.IN)
pinBtn = machine.Pin(39, machine.Pin.IN)
pinTrig.value(1)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print('Connecting to network...')
wlan.connect('***', '**')
while not wlan.isconnected():
time.sleep_ms(50)
pass
print('Connected to network (', wlan.ifconfig(), ')')
print('Starting QR Code reading')
h = HttpClient()
while True:
time.sleep_ms(200)
if pinBtn.value() == 0:
print('Button Pressed')
pinTrig.value(0)
else:
pinTrig.value(1)
if uart_qr.any() > 0:
query_url = uart_qr.readline().decode('ascii').replace('\r', '').replace('\n', '')
url = 'http://192.168.1.250:6005/office' + query_url
resp = h.get(url)
print('{} -> status: {}'.format(url, resp.status_code))