somakeit / smib

1 stars 0 forks source link

MQTT for 2 way communication #107

Open sam57719 opened 1 month ago

sam57719 commented 1 month ago

MQTT for 2 way communication between smibpi and any smibhid devices. Rather than just req and resp.

Need to read into it more but looks promising.

sjefferson99 commented 1 month ago

Never played with message queues, but read a little about them previously and this sounds likely to be a good solution, unsure if Pico can run a server, but definitely able to participate as a client. One to explore.

sam57719 commented 1 month ago

MQTT is a message broker service. The broker would run as a container and then both SMIB and Each SMIBHID device would be a client. Micropython has a umqtt library.

The smib server and SMIBHID devices would subscribe to topics rather than using HTTP.

HTTP would probably be used for GET requests still.

Then SMIBHID could 'subscribe' to a 'smib/space/state/openclose' topic and automatically get notified when the state changes rather than polling

sjefferson99 commented 1 month ago

Sounds good, will look into it more on a Wednesday sometime when we plan next roadmap elements. Need to turn all these ideas into a what's next and what's later plan.

sam57719 commented 1 month ago

Blocked by #59

sjefferson99 commented 1 week ago

@sam57719 Looked into MQTT properly. Looks very cool and should replace HTTP ASAP as HTTP is slow and insecure and causing performance issues. Looks like we can do as you said above, so button pushes state change to broker, broker processes state change to slack and pushes state change confirmation out to change the LEDs.

Also looks like MQTT has a function to retain the message, but not sure if that's just on birth/death/will so in theory it joins and gets a push of the current state on subscription. Failing that we can fall back to get requests for when we first fire up or fall out of sync and keep in sync with mqtt.

I'll open a an issue to add publishing button push to a broker and consume state change for the LED from a broker. You can then use this issue to create that broker to support button push and state change and associated updates to slack and DB?

sam57719 commented 1 week ago

59 needs to be done first/at same time as per the blocked label and above comment.