Thanks to visit codestin.com
Credit goes to github.com

Skip to content

socket hang after REPL disconnection #9150

Open
@kevin-tritz

Description

@kevin-tritz

CircuitPython version

Adafruit CircuitPython 9.0.0-rc.0 on 2024-03-08; W5500-EVB-Pico with rp2040

Code/REPL

import asyncio
import collections
import supervisor
import mqtt
import ntp as my_ntp
from sensor import Sensor

supervisor.runtime.autoreload = False


class Stop:
    def __init__(self):
        self.value = False


async def proc_cmds(cmd_queue, stop):
    while not stop.value:
        while len(cmd_queue):
            cmd = cmd_queue.popleft()
            if cmd in ['stop', 'STOP']:
                stop.value = True
                continue
        await asyncio.sleep(0.01)


async def sensor_data(sensor, data_queue, ntp, stop):
    while not stop.value:
        data_queue.append(f"{sensor.name}:{sensor.get_data()}:{ntp.timestamp()}")
        await asyncio.sleep(0.01)


async def main():
    stop = Stop()

    sensors = []
    sensors.append(Sensor("sensor1"))
    sensors.append(Sensor("sensor2"))
    sensors.append(Sensor("sensor3"))
    data_queue = collections.deque((), 100)
    cmd_queue = collections.deque((), 10)

    client, pool = mqtt.init()
    client.data_queue = data_queue
    client.cmd_queue = cmd_queue
    ntp = my_ntp.init(pool)

    mqtt_tasks = mqtt.create_tasks(client, stop)
    time_task = asyncio.create_task(my_ntp.update(ntp, stop))
    data_tasks = [asyncio.create_task(sensor_data(
        sensor, data_queue, ntp, stop)) for sensor in sensors]
    cmd_task = asyncio.create_task(proc_cmds(cmd_queue, stop))
    await asyncio.gather(time_task, cmd_task, *mqtt_tasks, *data_tasks)

    mqtt.deinit(client)

asyncio.run(main())

Behavior

I have a W550-EVB-PICO publishing a MQTT message to an rasppi5 broker once every second. It plugs away happily for hours/days at a time. However, if I ssh to the rasppi5, open minicom so I can see the pub messages that are printed to the REPL, and then close minicom or just terminate the ssh session, the PICO stops publishing after a few seconds. If I open up minicom again shortly after, it will resume MQTT publishing. If I wait a bit longer (~minute-ish) it won't resume publishing, and if I interrupt with a Ctrl-C, it shows it stuck here: File "/lib/adafruit_wiznet5k/adafruit_wiznet5k.py", line 532, in socket_available. Is there something about connecting/disconnecting from the serial that interferes with socket operations?

Description

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions