Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comms: MQTT #21

Open
11 of 19 tasks
mitra42 opened this issue Sep 28, 2024 · 5 comments
Open
11 of 19 tasks

Comms: MQTT #21

mitra42 opened this issue Sep 28, 2024 · 5 comments

Comments

@mitra42
Copy link
Owner

mitra42 commented Sep 28, 2024

Part of #20

The node needs to connect to a MQTT broker and send/receive messages from it.

There are a LOT of MQTT libraries, and its not clear which is the best - comments are welcome.

My plan is to build on one of them for the POC, and then allow for coming back and re-engineering, ideally just this module, if there is a better one to use.

Its dependent on WiFi connectivity.

@mitra42
Copy link
Owner Author

mitra42 commented Sep 28, 2024

I'm leaning towards lwmqtt because it claims to be simple and light/

There is also a wrapper arduino-mqtt which uses callbacks. And it looks like this is what is needed as the other is a non-arduino (e.g. uses pthreads)

@mitra42
Copy link
Owner Author

mitra42 commented Sep 28, 2024

Base level works as a demo - sends and receives a hello world message. Probably needs some kind of broker on my naturalinnovation.org server, and then to add authentication.

@mitra42
Copy link
Owner Author

mitra42 commented Sep 28, 2024

Need to also think through structure for MQTT variables and payloads. I think this will need copying the payload out of the buffer which might mean dealing with the type.

@mitra42
Copy link
Owner Author

mitra42 commented Sep 28, 2024

Design straw person .....

  • sensor_xxx::loop calls xMqtt:send(topic, value) when value changes.
    • calls ok with floating point, but needs to test for change
  • - cDemoMqtt::setup calls xMqtt_subscribe(topic, *cDemoMqtt::messageReceived)
  • - xMqtt_subscribe calls client.subscribe(topic)
  • - xMqtt::messageReceived looks up topic and calls cXxx::messageReceived with the payload
  • - cDemoMqtt::messageReceived converts incoming floating text to point
  • - makes a copy of the payload if required.
  • - takes action e.g. calling an actuator.
  • - cDemoMqtt::messageReceived send actuator result back via MQTT
  • - aLedbuiltin::setup calls xMqtt_subscribe(topic, *aLEDbuiltin::messageReceived)
  • - aLedbuiltin::messageReceived to control LED based on result

Next steps would be to do this with the SHT31 sensor, and then an actuator (which could be on a separate device) to turn on LEDS when humidity exceeds base level

@mitra42 mitra42 mentioned this issue Sep 28, 2024
4 tasks
@mitra42
Copy link
Owner Author

mitra42 commented Oct 3, 2024

There is now a live working demo where a SHT30 sensor detects humidity , sends it to the MQTT broker. Then control_demo_mqtt receives that value, checks against a reference humidity and sends a value via the MQTT server to actuator_ledblinken.

Note that this should work even if the LED and SHT30 are on different devices, but I don't currently have a way to test that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant