31 lines
687 B
Python
31 lines
687 B
Python
|
import socket
|
||
|
from machine import Pin, ADC
|
||
|
from utime import sleep_ms
|
||
|
import os
|
||
|
|
||
|
while not wlan.isconnected():
|
||
|
sleep_ms(100)
|
||
|
|
||
|
adc = ADC(0)
|
||
|
forward = Pin(16, Pin.IN)
|
||
|
backward = Pin(4, Pin.IN)
|
||
|
calibration = adc.read()
|
||
|
|
||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
|
||
|
sock.bind(("", 37020))
|
||
|
|
||
|
while True:
|
||
|
try:
|
||
|
sockaddr = socket.getaddrinfo('sumo-%s' % config["remote-id"], 44444)[0][-1]
|
||
|
except OSError:
|
||
|
sleep_ms(500)
|
||
|
else:
|
||
|
break
|
||
|
|
||
|
# sockaddr = "192.168.1.255", 44444
|
||
|
|
||
|
while True:
|
||
|
msg = "%d:%d:%d" % (adc.read()-calibration, not forward.value(), not backward.value())
|
||
|
sock.sendto(msg.encode("ascii"), sockaddr)
|
||
|
sleep_ms(30)
|