How do I fetch live data received by MQTT client (also in elixir) via Phoenix? I’m building an IoT dashboard and I want to check on devices current state. I’m thinking in subscribing to a topic (corresponding to a device) when a user connects via websockets and wait for any data sent by the MQTT client to this topic.
What’s the best approach to achieve this?
(Just a simple illustration of my problem)
Client <–websocket–> Phoenix <-- ?? --> MQTT Client
Caveat: Just some information based on some hasty online searches …
My first rough sketch:
See if its possible to use a plugin to store information in a “data-repo” application. Then use Phoenix “Phoenix-is-not-your-application style” to serve as the web front end for the data repo application.
Thank you for the reply @peerreynders. The broker is not the problem (I’m already using VerneMQ). I forgot to mention it on the diagram but it would be on the far right. Like this:
Client <–websocket–> Phoenix <-- ?? --> MQTT Client < ----> Broker < — > device
What do you mean with “Data repo app”? :s
The mqtt client is already persisting all incoming data from the broker to a database which can be queried by phoenix. Since I also want to send live data to a client I want a mechanism to communicate from phoenix to the mqtt client and vice-versa. My initial idea was to use a pubsub approach but I just can’t set it up inside phoenix so I’m looking for alternatives.
(Sorry for the confusion, I just got started with elixir)
One possible solution might be to integrate Phoenix.PubSub into “the application that uses tortoise”. That way your web backend (built with Phoenix) can subscribe with that app to receive live updates via distributed Erlang/Elixir.