floitsch 05/16/2025 12:49 PMThe problem is, that you already opened the WiFi with wifi.open.
The mqtt client then tries to open the same WiFi, but this time through the system service.
A few ways to solve this:
- close the network you received with wifi.open and let the the system open the same network again. (basically: connection.close). Note that you can save the WiFi credentials with wifi.open ... --save)
- use the network you received from wifi.open for the MQTT connection.
In the latter case you would set the --net-open lambda of the client:
client := mqtt.Client --net-open=(:: connection) --host=HOST --port=PORT
Note that this isn't completely correct, as net-open can be called multiple times. In theory you would need to track whether this was the first call, and if not, establish a new connection.
Something like:
client := mqtt.Client --host=HOST --port=PORT --net-open=::
if connection.is-closed:
connection = wifi.open ...
connection