I´m running micropython 1.9.4 on an esp8266-01 with a relay board that is switched via serial commands. I have the following code:
Code: Select all
import sys,socket,machine,ubinascii
port = 2222
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('0.0.0.0',port))
uart=machine.UART(0,9600)
uart.init(9600,bits=8,parity=None,stop=1)
while True:
data,addr = s.recvfrom(1024)
print(data)
command = data.decode("utf-8")
if command == "lampon\n":
uart.write(ubinascii.unhexlify('A00101A2'))
if command == "lampoff\n":
uart.write(ubinascii.unhexlify('A00100A1'))
If I remove that part from the code, the "print(data)" actually prints the data i send, but if I try to define uart, nothing is printed.
I read that UART is somehow used by repl, but then why would it work if I invoke everything from inside webrepl?
I tried searching the forum but found no hints for a difference between the two ways of invoking that code. If i missed to give some needed information for you to help me please tell me what I forgot.
Best regards,
Gregor