Skip to content

marilib: add MARI_MQTT_INSECURE and survive a failed broker connect - #177

Merged
geonnave merged 3 commits into
DotBots:mainfrom
geonnave:mari-edge-mqtt-insecure
Sep 22, 2026
Merged

geonnave merged 3 commits into
DotBots:mainfrom
geonnave:mari-edge-mqtt-insecure

Conversation

@geonnave

@geonnave geonnave commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

mari-edge connects to the broker from the serial reader thread, on the first GATEWAY_INFO. When the TLS handshake fails, for example against a broker whose certificate has expired, the exception killed that thread: the gateway was never read again while the display kept running as if nothing was wrong. There was also no way to skip certificate verification for a bench session.

Now:

  • A failed connect is printed with its reason and paho keeps retrying in the background; the serial thread survives. A certificate failure adds a hint pointing at MARI_MQTT_INSECURE=1.
  • MARI_MQTT_INSECURE=1 (1/true/yes/on) makes the TLS context skip certificate and hostname verification, with a warning. Otherwise marilib passes paho's verifying default, unchanged.
  • A broker that refuses the connection (bad or missing credentials) is reported with its reason and a hint naming MARI_MQTT_USER / MARI_MQTT_PASS, instead of a subscribe printed as if it had worked.
  • mari-edge, mari-cloud and examples/mari_edge_stats.py share one mqtt_options_from_env() instead of three copies of the credentials helper.

Breaking: the credentials are read from MARI_MQTT_USER / MARI_MQTT_PASS instead of DOTBOT_MQTT_USER / DOTBOT_MQTT_PASS, so marilib stops depending on another project's variable names. Programs that pass username / password to MQTTAdapter.from_url explicitly are unaffected; anyone running mari-edge or mari-cloud by hand against an authenticated broker must export the new names.

Validation: marilib suite passes (75 tests, 15 new cases for the env parsing, the TLS contexts and an unreachable broker not raising, and a refused CONNACK); ruff check clean. Live against a broker with an expired certificate: without the variable the reason and hint are printed and nothing raises; with MARI_MQTT_INSECURE=1 it connects and subscribes. Not yet run with a gateway attached.

Breaking: mari-edge and mari-cloud read MARI_MQTT_USER / MARI_MQTT_PASS
instead of DOTBOT_MQTT_USER / DOTBOT_MQTT_PASS. The edge connects from
the serial reader thread, so a refused TLS handshake (an expired broker
certificate) killed the thread and left the gateway unread; the failure
is now printed and paho keeps retrying in the background.

AI-assisted: Claude Opus 5
@geonnave
geonnave merged commit f2faf5b into DotBots:main Sep 22, 2026
6 checks passed
@geonnave
geonnave deleted the mari-edge-mqtt-insecure branch September 22, 2026 13:08
@geonnave geonnave mentioned this pull request Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant