Tiny MQTT Broker

I wanted to test a small MQTT Broker that would run in TinyCLR. The use case is for a small network where a central broker isn’t available, and only a small number of pub/sub messages need to be sent. (The idea comes from Bambu Lab printers; they have an internal broker, so a monitoring app can connect directly to the printer without needing to add a broker to the network.)

I haven’t done a full test with a full functional application, and I am not convinced it will be useful in a commercial application. I have only run the broker by itself.

I am not sure what this group’s opinion is on using AI code assistance, but for this, I used Claude Code to refactor the Eclipse Paho M2Mqtt broker library. I can’t take credit for the work; I just came up with the prompts. :winking_face_with_tongue:

Anyway, the broker can be found here: GitHub - skeller2015/TinyMQTTBroker_v1: MQTT broker for TinyCLR OS 2.4 (GHI SITCore) — two-thread event-loop architecture · GitHub

It can easily be started using the following:

using TinyMQTTBroker;
using TinyMQTTBroker.Messages;

// Create and configure the broker
MqttSettings settings = MqttSettings.Instance;
var broker = new MqttBrokerLoop(1883, settings);

// Start accepting connections
broker.Start();

See the documentation for the other features/settings.

There is a Python test script found in the /tests directory.

If you have any questions or suggestions, let me know.

4 Likes

Thanks, that is very useful.

Would it be okay if we included this in our library?

That should be fine, but some additional testing by others would be good. I haven’t gone through the code line by line to see if it has any glaring issues. It does work, but some additional eyes in the code would be helpful to be sure I didn’t just create a bunch of AI slop.

2 Likes