I have a regular cloud server set up, I have a mobile app talking to the server via HTTP requests. I also have a Wifi device that I need to send messages and I want to do that over MQTT. When some change happens on the mobile app, I want the cloud server to publish a topic via MQTT so that the wifi device can receive the message. Can a broker also be a client? Am I understanding it wrong?
0
votes
Just to confirm I understood correctly: - You have 4 components: 1) HTTP Server 2) MQTT Broker 3) Mobile App 4) Wifi Device - You want the MQTT Broker (2) to send a message to the Wifi Device (4) when a change happens on the mobile app (3). The mobile app (3) tells the HTTP Server (1) when a change happens. Did I get that right?
– Pierre-Luc
1 Answers
0
votes
I'm going to attempt an answer based on my understanding; sorry if I misunderstood your question.
The way I understand it, you will have three/four pieces of software:
- HTTP Server / MQTT Broker (these two services could run in the same application or in separate ones)
- Mobile application (communicates over HTTP)
- Wifi Device (communicates using MQTT protocol)
Scenario:
- The Wifi device will open a connection to the MQTT Broker and subscribe to a well defined topic. You can use a subscription with a QoS of 1 if you cannot afford to lose the messages. Any messages published prior to adding the subscription will not be received by your client. It might also be useful to open an MQTT connection using a non-clean session if your wifi connection is unstable (again, if you don't want to lose any messages).
- After a specific event, the mobile application which communicates with the HTTP server will send it information.
- Upon reception of the information, the HTTP server will then send an MQTT message to the MQTT Broker on the predefined topic (a topic that will match the Wifi Device's subscription).
- The MQTT broker will relay the message from the HTTP Server to the Wifi Device (and any other MQTT clients with a matching subscription).
I hope this clarifies, let me know if anything is unclear.
"Can a broker also be a client?" Not really, although I'm certain some specific brokers will publish messages to special subscriptions based on special events, it only acts as a broker. It receives messages from publishers and forwards messages to any client who has shown interest in that message using a subscription (the message could potentially be dropped by the broker if no subscriber (client) is interested in that message).