Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. MQTT Client gateway

MQTT Client gateway

Scheduled Pinned Locked Moved Development
91 Posts 33 Posters 52.1k Views 14 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N ntruchsess

    I just took the time this afternoon and implemented a mqtt-gateway that works as mqtt-client:

    https://github.com/ntruchsess/MySensors/tree/mqttclient/libraries/MySensors/examples/MQTTClientGateway

    it is based on the work of @Damme (http://forum.mysensors.org/topic/260/mysensors-mqtt-gateway) and makes use of nick o'learys PubSubClient-library (http://knolleary.net/arduino-client-for-mqtt/)

    The main difference to the existing MyMQTT-gateway is that it will connect to an existing mqtt-broker (e.g. mosquitto). This is beneficial if you want to integrate with other mqtt-client-devices sharing a single broker for your automation solution. It also ensures your mqtt-client that is going to pick up the messages from the gateway will talk to a 'real' broker understanding the whole mqtt protocolls semantics

    It works both ways:
    on startup or reconnect it subscribes to "MyMQTT/#" (configurable as MQTT_PREFIX). Any publish-messages payload that is delivered by the broker to a topic that complies with the sheme <prefix>/<nodeId>/<childId>/<variable_type> is forwarded as a C_SET-msg to the MySensors radio.
    Any C_SET-message received from a node is published to the mqtt-broker using the same sheme.

    • Norbert
    M Offline
    M Offline
    mainali
    wrote on last edited by
    #24

    @ntruchsess said:

    <prefix>/<nodeId>/<childId>/<variable_type> is forwarded as a C_SET-msg to the MySensors radio.

    Hi, I followed the steps, gateway started but not able to use the existing mysensors sketch. I tried with relay and motion sensor but I get nothing in the serial monitor of MQTT client gateway.

    Am I missing something here ?

    1 Reply Last reply
    1
    • FrancoisF Offline
      FrancoisF Offline
      Francois
      wrote on last edited by
      #25

      @ntruschsess

      I am getting this compile error when I compile the MQTT Client gateway on lib1.4.1.

      In file included from MQTTClientGateway.ino:63:0:
      MyMQTTClient.h:43:35: error: 'RF24_PA_LEVEL_GW' was not declared in this scope
      void begin(rf24_pa_dbm_e paLevel=RF24_PA_LEVEL_GW, uint8_t channel=RF24_CHANNEL, rf24_datarate_e dataRate=RF24_DATARATE, uint8_t _rx=6, uint8_t _tx=5, uint8_t _er=4 );
      ^
      MQTTClientGateway.ino: In function 'void setup()':
      MQTTClientGateway.ino:136:12: error: 'RF24_PA_LEVEL_GW' was not declared in this scope
      Error compiling.

      1 Reply Last reply
      0
      • FotoFieberF Offline
        FotoFieberF Offline
        FotoFieber
        Hardware Contributor
        wrote on last edited by
        #26

        In MyMQTTClient.cpp the function
        MyMQTTClient::processMQTTMessage(char* topic, byte* payload, unsigned int length)
        does ignore length. This can lead to garbage transferred to the clients in the payload

        char* ca;
        ca = (char *)payload;
        ca += length;
        *ca = '\0';

        before
        msg.set((const char*)payload); //Payload

        (I am sure, this can be written in a more elegant way. :))

        1 Reply Last reply
        0
        • FotoFieberF Offline
          FotoFieberF Offline
          FotoFieber
          Hardware Contributor
          wrote on last edited by
          #27

          Added support for:

          • sketchinfo
          • sketchversion
          • time
          • batterylevel
          • dallas RTC and message to set time from outside

          https://github.com/FotoFieber/MySensors/tree/mqttclient/libraries/MySensors/examples/MQTTClientGateway

          1 Reply Last reply
          1
          • G Offline
            G Offline
            Gambituk
            wrote on last edited by
            #28

            @FotoFieber @ntruchsess i have a parallel post regarding this version of the controller, i did not know it was the same as this one when i opened the thread :8ball: but i am having some garbage issues, do you think this is the same problem as you have described 2 posts up? http://forum.mysensors.org/topic/921/strange-value-being-sent-from-controller-using-mixed-temp-relay-node thanks for any comments or pointers

            1 Reply Last reply
            0
            • FotoFieberF Offline
              FotoFieberF Offline
              FotoFieber
              Hardware Contributor
              wrote on last edited by
              #29

              @Gambituk

              This seems to be the problem I fixed with adding \0 at the end of the payload. Try the patch from above.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TommySharp
                wrote on last edited by
                #30

                Hi guys! Took me a while but I've finally got this compiling and uploading to the Arduino Uno.

                I can see the Uno on my ethernet network and it's visible as the IP address I set in the sketch.

                But my mosquitto MQTT broker never receives anything from the Uno, I was expecting even just a New Client Connection notification or something... But nothing.... I have OpenHAB talking to Mosquitto and the Mosquitto screen shows it receiving ping requests from OpenHAB so I know the broker side of things is working well.

                Anyone got any ideas? I'm confident that the IP address and port for my broker have been properly configured in the sketch.

                I just configured 4 things in the scketch..

                1. Broker IP Address
                2. Broker Port
                3. Arduino IP address
                4. Arduino MAC Address
                1 Reply Last reply
                0
                • FotoFieberF Offline
                  FotoFieberF Offline
                  FotoFieber
                  Hardware Contributor
                  wrote on last edited by
                  #31

                  Hi TommySharp

                  Question 1:
                  Do you see the connection on mosquitto:

                  mosquitto_sub -h mosquittoip -v -t '$SYS/broker/clients/active'

                  Question 2:
                  Do your mysensor-nodes get connected to the gateway? (You can have only one gateway.)

                  Tip 1:
                  Program your arduino with an isp (or arduinoisp): you then have more room as you don't need the bootloader and can enable debug.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    TommySharp
                    wrote on last edited by
                    #32

                    @FotoFieber
                    Thanks for the reply....

                    I'm running mosquitto on windows so not sure how to "run" the command you suggest? I can see the mosquitto DOS looking dialogue box onscreen and it shows OpenHAB pinging mosquitto every few minutes, not seeing any pings or subscriptions coming from the MySensors MQTTClient Gateway though?

                    This is the only gateway I am trying to setup and I have one wireless temperature/humidity sensor running and it's located about 1 meter from the gateway. I expected that even without any sensor nodes setup that at least the Gateway should connect to mosquitto in some way? I did mess about with trying the other MQTT gateway where it is also the broker and I did get a few temperature readings all the way into OpenHAB that way but OpenHAB randomly lost the connection to the broker and then I'd have to reboot everything. Just mentioning that because that tells me that my one sensor node is working properly I guess.

                    Tip 1 : I'll have to do some googling about an "isp" to see what that's all about....

                    1 Reply Last reply
                    0
                    • dakkyD Offline
                      dakkyD Offline
                      dakky
                      wrote on last edited by
                      #33

                      will this feature be ported back to the official repo?

                      Controller: Raspberry Pi 2 :: Openhab2 :: with @TimO MySensors Binding
                      Gateway: Arduino MEGA 2560 R3 :: W5100 :: Ethernet GW

                      Software: MySensors 2.0development

                      1 Reply Last reply
                      0
                      • dakkyD Offline
                        dakkyD Offline
                        dakky
                        wrote on last edited by dakky
                        #34

                        another question: i'm using the uno with the ethernet shield. Is the wiring the same as documented here?

                        I double checked the wiring but keep on receiving the "check wires" message in the serial monitor.

                        What did i do?

                        • wiring the nrf
                        • enabled DEBUG in myConfig.h
                        • threw the PubSubClient and DS1307RTC libraries in my lib folder
                        • "fixed" PubSub code as told by @ntruchsess somewhere in this thread
                        • configured mqtt server and port, arduino ip an mac (btw, commenting out the arduino IP, which should result in using DHCP, does not work, because local_ip is not configured anymore?)

                        the code itself compiled fine, but i keep on getting this wiring error :(
                        what confuses me too: the pins noted in the sketch: are they handled through the ethernetshield?

                        greetings
                        dakky

                        EDIT: Dammit .. i forgot to reenable SOFTSPI. Could this cause the wiring problem? and now the Sketch is too large (with debug enabled)

                        Controller: Raspberry Pi 2 :: Openhab2 :: with @TimO MySensors Binding
                        Gateway: Arduino MEGA 2560 R3 :: W5100 :: Ethernet GW

                        Software: MySensors 2.0development

                        1 Reply Last reply
                        0
                        • dakkyD Offline
                          dakkyD Offline
                          dakky
                          wrote on last edited by
                          #35

                          nobody ever tried tried to upload the sketch with SOFTSPI and debug enabled to an arduino uno? Even with optiboot the sketch seems to be too large :(

                          Controller: Raspberry Pi 2 :: Openhab2 :: with @TimO MySensors Binding
                          Gateway: Arduino MEGA 2560 R3 :: W5100 :: Ethernet GW

                          Software: MySensors 2.0development

                          1 Reply Last reply
                          0
                          • hekH Offline
                            hekH Offline
                            hek
                            Admin
                            wrote on last edited by
                            #36

                            Yep, it uses up all available ram. Debug prints have to be disabled. You could probably ad one or two Serial.println() yourself if you need to debug things.

                            1 Reply Last reply
                            1
                            • FotoFieberF Offline
                              FotoFieberF Offline
                              FotoFieber
                              Hardware Contributor
                              wrote on last edited by
                              #37

                              You can save program space by uploading it without a bootloader (ISP).

                              1 Reply Last reply
                              0
                              • GizMoCuzG Offline
                                GizMoCuzG Offline
                                GizMoCuz
                                wrote on last edited by
                                #38

                                Questions (Sorry)

                                I have rebuild the whole original MQTT sketch so it supports the standard mysensors protocol (the serial/ethernet gateway).
                                With this, we have all functionality that the original mysensor serial gateway supports.

                                What would be the downside with this implementation ?

                                The data being transferred is like

                                http://www.mysensors.org/download/serial_api_14

                                It is now also very easy to pass the payload an internal serial/ethernet gateway handler, but the payload is not easily interpreted as human text of course.

                                Would this be something to submit as a replacement of the original MQTT library?

                                Devs just need to push the payload to their original serial/ethernet handler, and sending messages is also in the same format

                                AWIA 1 Reply Last reply
                                0
                                • K Offline
                                  K Offline
                                  kunall
                                  wrote on last edited by
                                  #39

                                  I'm getting following error while compiling, any solution?

                                  Screen Shot 2015-05-05 at 12.35.34 PM.png

                                  1 Reply Last reply
                                  0
                                  • DNKROZD Offline
                                    DNKROZD Offline
                                    DNKROZ
                                    wrote on last edited by DNKROZ
                                    #40

                                    Remove PROGMEM from line 72 at the file PubSubClient.h

                                    Works for me, but I really don't know why, I remember to read it somewhere.... not sure if it is "safe" to do, but at least I can compile it and test it, and BTW, works fine with my mosquitto instance on my NAS, still have to do more tests.

                                    Regards.

                                    EDIT: The solution is on this thread XD

                                    1 Reply Last reply
                                    0
                                    • GizMoCuzG GizMoCuz

                                      Questions (Sorry)

                                      I have rebuild the whole original MQTT sketch so it supports the standard mysensors protocol (the serial/ethernet gateway).
                                      With this, we have all functionality that the original mysensor serial gateway supports.

                                      What would be the downside with this implementation ?

                                      The data being transferred is like

                                      http://www.mysensors.org/download/serial_api_14

                                      It is now also very easy to pass the payload an internal serial/ethernet gateway handler, but the payload is not easily interpreted as human text of course.

                                      Would this be something to submit as a replacement of the original MQTT library?

                                      Devs just need to push the payload to their original serial/ethernet handler, and sending messages is also in the same format

                                      AWIA Offline
                                      AWIA Offline
                                      AWI
                                      Hero Member
                                      wrote on last edited by
                                      #41

                                      @GizMoCuz Can you elaborate a little on your rebuild? ie. what was the objective?

                                      1 Reply Last reply
                                      0
                                      • T Offline
                                        T Offline
                                        TommySharp
                                        wrote on last edited by
                                        #42

                                        Could someone please post the latest working version of the MQTT Client gateway sketch?

                                        1 Reply Last reply
                                        0
                                        • TD22057T Offline
                                          TD22057T Offline
                                          TD22057
                                          Hardware Contributor
                                          wrote on last edited by
                                          #43

                                          Does anyone have a version of this reworked for the new 1.5 client? Looking through the MySensor class, it looks like a lot of the code in MyMQTTClient.cpp can be removed as it's now in the sensor class. I'd like to use this for my gateway as it's a much better system than the broker gateway that's in the standard library but it needs to support message signing and the newer 1.5 code base. If someone else finished this already I'll just use that, otherwise I'll start working on it. I have family coming in town so I don't expect to get much done in the next week but assuming that the MQTT code is working fine (I have no experience with that writing an MQTT client), it shouldn't take much work to refactor the client to use the new MySensor base.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          8

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular