← index #7473Issue #4263
Off-topic · high · value 0.263
QUERY · ISSUE

esp8266 nonblocking ussl: `read(N)` never returns any data

openby vshymanskyyopened 2021-06-29updated 2021-06-30
port-esp8266

MicroPython version: esp8266-20210618-v1.16, esp8266-20210629-unstable-v1.16-39-g4ada56d4c

s = usocket.socket()
s.connect(usocket.getaddrinfo(server, port)[0][-1])
conn = ussl.wrap_socket(s, server_hostname=server)
s.settimeout(0)           # or s.setblocking(False)
conn.write(b"some data")  # OK: server gets the data and replies
while True:
    data = conn.read(1) # increasing count doesn't help
    print('>', data)

Outputs:

> None
> None
> None
> None
> None
> None
> None
> None
> None
> None
> None
> None
> b''
> b''
> b''
> b''
> b''
...

No data is received.

Observations:

  • If I set conn = s (i.e. use plain insecure TCP), it works
  • If I replace s.settimeout(0) with s.settimeout(1), it works for for some 5-10 seconds, then conn.read stops blocking for 1 second, returns quickly and no more data is received
  • If I replace s.settimeout(0) with s.settimeout(0.1), I get OSError: -261 on conn.read
  • Same code works on ESP32
CANDIDATE · ISSUE

ESP8266: UART not working

closedby xandatspainopened 2018-10-24updated 2018-10-24

I have a NodeMCU board with ESP8266.

MP version is: MicroPython v1.9.4-272-g46091b8a on 2018-07-18; ESP module with ESP8266

Also I have an IR controller attached to it. The problem is the UART is not working at all, not reading and I suspect no writing also. The IR controller works on RPi2 and the commands are copied as is from there.

I attach the code which is not working:

def test():
    import uos, machine, time, sys

    # detach repl
    uos.dupterm(None, 1)
    
    uart = machine.UART(0)
    uart.init(9600, bits=8, parity=None, stop=1)

    # do my stuff here
    #bytes_written = uart.write(bytearray(b'\xfa\xf6'))
    bytes_written = uart.write(bytes([0xfa, 0xf6]))
    time.sleep(5)
    #bytes_written = uart.write(bytearray(b'\xfa\xf2'))
    bytes_written = uart.write(bytes([0xfa, 0xf2]))
    time.sleep(5)
    
    frame = bytearray(25)
    uart.readinto(frame)
    
    # attach repl back
    uos.dupterm(machine.UART(0, 115200), 1)

    print('Written: ' + str(bytes_written))
    print('Read: ' + str(frame))

bytes_written = 2, but the frame is always filled with zeros. The connection to REPL is done via serial/usb.

Thanks in advance.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied