MQTT: Can somebody explain Gateway to a beginner?



  • Hello all,

    I've just begun trying to understand MQTT. Final goal is to connect openHAB and MySensors via MQTT, but this is far, far away.

    By now, I've set up mosquitto and can send and receive messages from command line.

    Now, I would like to send some simple messages from Arduino. I've looked at the code of MyMQTT.cpp, but I hardly understand anything. I can see that upon receive of a radio message (in function processRadioMessage), a MQTT message is built and sent via EthernetServer.write. But I absolutely don't understand, where this message is written to. Don't I have to configure the address of my MQTT broker somewhere? How can the arduino know where my Mosquitto is running?

    I've searched the forum, but everybody but me who is working with MQTT seems to have a basic understanding that I seem to lack. No questions I found were that basic like mine 😞 .

    Can you explain it to a newbie?

    Marcus.



  • Ah, I've found the Arduino MQTT library, With the simple example provided there, I really managed to send MQTT message to my broker (and display it on command line). But in that example, I had to provide the IP address of my broker.

    I will further investigate MyMQTT.cpp to find out what my basic misunderstanding is. Perhaps I will manage to combine MyMQTT.cpp and the MQTT library.

    Marcus.



  • Marcus, did you get this working ever?



  • A while back I tried this approach to setup a MQTT Client Gateway but I never got it fully working.

    At the moment I'm using the MQTT Gateway and it works well for receiving readings from sensors. Although I'm having some problems sending commands to things like relays etc

    I'm probably going to try the "client gateway" again and make it talk to my Mosquitto MQTT broker.



  • I always had a problem with ethernet gateway. So i used serial gateway instead to connect with my nodejs application on my RPI. Inside that node js application, i converted all messages into my own MQTT topics and publish them to a MQTT server(Mosquitto) on my RPI. On the openhab side, i just bind items to these MQTT topics.
    You can take a look at my system diagram.
    Capture.PNG


  • Hardware Contributor

    This i my understanding (which could be totally wrong of course): the MQTT gateway implements a very limited MQTT broker. You connect a client into it and it will send the sensor messages out. I'm going to do something similar to your drawing (using RabbitMQ as a central clearing house for messages). In that case, I think you need to either connect the RabbitMQ broker to the gateway broker (if broker->broker is possible) or write a thin client that connects to the gateway broker and republishes messages to the RabbitMQ broker.



  • The MQTT gateway is not a broker. It is a client.

    Let me try to explain MQTT architecture to my understanding. MQTT is just a protocol for which clients talk to each other. However, in order for clients to talk, they need a server. This server is called the broker which can be mosquitto or RabbitMQ, etc.

    MQTT gateway is a client(A publishing one) which publishes messages to the server(RabbitMQ). Any other clients(Subscribing ones) who wish to receive messages will have to subscribe to the topic through the server(RabbitMQ). In any case, if a subscribing client wants to listen to a publishing client, the subscribing client has to subscribe to the same topic the publishing client publishes to. Both clients have to connect to a broker(RabbitMQ).

    I have already implemented my design as in the diagram above and it works. 😃 I guess what you mean is that if your client does not understand the messages coming from the MQTT gateway by MySensors, then you would need another client who republishes the message in a format that your clients understand.


  • Hardware Contributor

    https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino

    In that gateway code is the TCP_IP and TCP_PORT the external broker IP and port numbers? The comments say those are the static IP and a port to listen on. I read that as saying it's the static IP of the gateway and the port for the broker to listen on but perhaps they mean the remote IP/Port of the broker to connect to.


  • Hardware Contributor

    See here: http://forum.mysensors.org/topic/1034/mqtt-gateway-openhab-mosquitto/2 which connects mosquitto to the gateway using the bridge input. Bridging is used for connecting two brokers together (see http://mosquitto.org/man/mosquitto-conf-5.html "configuring bridges").



  • @TD22057 said:

    https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino

    In that gateway code is the TCP_IP and TCP_PORT the external broker IP and port numbers? The comments say those are the static IP and a port to listen on. I read that as saying it's the static IP of the gateway and the port for the broker to listen on but perhaps they mean the remote IP/Port of the broker to connect to.

    I have'nt used MySensors's MQTT Gateway, but if I am not wrong, TCP_IP is the IP you want your arduino to have. TCP_Port is the port you want others to connect to your arduino. Using these two parameters, your arduino will create a ethernet server for others to connect to.



  • @TD22057 said:

    See here: http://forum.mysensors.org/topic/1034/mqtt-gateway-openhab-mosquitto/2 which connects mosquitto to the gateway using the bridge input. Bridging is used for connecting two brokers together (see http://mosquitto.org/man/mosquitto-conf-5.html "configuring bridges").

    I think MySensor's MQTT Gateway is already a broker by itself where clients like OpenHab can connect to. However, if there is a need, you can use a bridge which forwards the messages from a remote broker(MySensor's MQTT Gateway) to a local broker(Mosquitto). Then clients could now also connect to Mosquitto.


Log in to reply
 

Suggested Topics

  • 4
  • 20
  • 9
  • 15
  • 9
  • 2

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts