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.0k 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 Offline
    N Offline
    ntruchsess
    Plugin Developer
    wrote on last edited by
    #13

    intention is you may controll MySensor-actuators via mqtt-client-gateway by publishing messages to topic MyMQTT/<radioId>/<childId>/<variableType>

    1 Reply Last reply
    0
    • N Offline
      N Offline
      novicit
      wrote on last edited by
      #14

      SUCCESS! Found the reason I could not compile the MQTT Gtwy client.

      When I first looked for the PubSubClient library, used google and went to http://knolleary.net/arduino-client-for-mqtt/ which has a link to GitHub for the library. That is the one I used. When @Victor-Klijmeij suggested I look at @ntruchsess suggested changes again - I noticed the line numbers were not the same as mine, but the code was. Bottom line .... I had an old version of PubSubClient. When I used the version @ntruchsess made changes to, it compiled immediately after his suggested changes. The old PubSubClient .cpp file was ~70 lines of code shorter than the current version.

      Thank you both again for your help, much appreciated! @ntruchsess, great job, thanks for sharing the code.

      1 Reply Last reply
      0
      • b0rmannB Offline
        b0rmannB Offline
        b0rmann
        wrote on last edited by
        #15

        PubSubClient library cannot currently be used with hardware based on the ENC28J60 :(

        N 1 Reply Last reply
        0
        • b0rmannB b0rmann

          PubSubClient library cannot currently be used with hardware based on the ENC28J60 :(

          N Offline
          N Offline
          ntruchsess
          Plugin Developer
          wrote on last edited by
          #16

          @b0rmann
          PubSubClient and ENC28J60 require more memory than an Uno provides. It should run on a Mega256 though.

          1 Reply Last reply
          0
          • b0rmannB Offline
            b0rmannB Offline
            b0rmann
            wrote on last edited by
            #17

            DEBUG:

            0;0;3;0;9;read: 16-16-0 s=61,c=1,t=0,pt=7,l=5:38.0
            publish: MyMQTT/16/61/V_TEMP 38.0
            0;0;3;0;9;send: 0-0-16-16 s=61,c=1,t=0,pt=0,l=5,st=ok:38.00 
            0;0;3;0;9;send: 0-0-18-18 s=1,c=1,t=2,pt=0,l=5,st=ok:18.00
            

            mqtt payload for node 18 contain only string '1' (it's relay), '8.00'- trash from previous message :(
            yes, '18.00' may by interprait as boolean TRUE, but '01.00' (next par of log is not FALSE :(

            0;0;3;0;9;read: 16-16-0 s=91,c=1,t=0,pt=7,l=5:61.0
            publish: MyMQTT/16/91/V_TEMP 61.0
            0;0;3;0;9;send: 0-0-16-16 s=91,c=1,t=0,pt=0,l=5,st=ok:61.00
            0;0;3;0;9;send: 0-0-18-18 s=4,c=1,t=2,pt=0,l=5,st=ok:01.00
            

            dirty hack - i use '000000000000' instead '0' to rewrite old data

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DirkB19
              wrote on last edited by DirkB19
              #18

              Hi Norbert, Bormann or Novicit,

              I'm an Arduino newbie and so far haven't found a way to get the MqttClientGateway to compile.
              Obviously I'm using the wrong include files (libraries), so could someone give me some precise links as to where to download the right PubSubClient stuff, or other libraries, if any needed to compile. (I'm not really finding my way in Github).

              My setup is Arduino UNO+W5100, Mosquitto on RPi (working :-) and Openhab (working :-). On the Raspberry I already have the mqtt-gpio-monitor working with Mosquitto and Openhab, now I want to add Mysensors;

              Thanks in advance,
              DirkB

              UPDATE :+1:
              Ok, I found it meanwhile. Everything works now. Was complicated for a newbie, had some issues with libraries not being in the right folders as well.
              Thanks.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SagittaTheArrow
                wrote on last edited by
                #19

                Has anybody tried to get this compiled with the development branch (1.4.1) with the RFM69 radios? I have been trying to get a successful compile, but no luck thus far. I do have it working with the stable branch, but I am not happy with the radios and would love to get this client working with the RFM69 radios. I have looked over the code and started to merge the two, but I am not a C++ programmer and have had some difficulty with the following error:
                yMQTTClient.cpp:16:14: error: variable 'VAR_0' must be const in order to be put into read-only section by means of 'attribute((progmem))'
                char VAR_0[] PROGMEM = "TEMP"; //V_TEMP
                I tried some of the workarounds that I found (const char VAR_0) but then the GetType functions break and I do not understand enough of the code to correct that issue. Anyway, I thought I would check here to see if anybody else has made some headway.

                Thanks in advance for any information / help.

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

                  what happens if you add const as the compiler suggest?

                  const char VAR_0[] PROGMEM = "TEMP";

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SagittaTheArrow
                    wrote on last edited by
                    #21

                    If I change the lines to this:
                    const char VAR_63[] PROGMEM = "UNKNOWN"; //Custom for MQTTGateway

                    And leave this line alone:
                    PROGMEM const char *VAR_Type[] = [<removed to keep short>]

                    I get this error:
                    MyMQTTClient.cpp:82:30: error: variable 'VAR_Type' must be const in order to be put into read-only section by means of 'attribute((progmem))'
                    PROGMEM const char *VAR_Type[] =

                    I tried const char VAR_Type[] PROGMEM = [ ]; and char const VAR_Type[] PROGMEM = ; but I get the same error. I"m going to do some reading on PROGMEM to see if I can find out what it does.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SagittaTheArrow
                      wrote on last edited by SagittaTheArrow
                      #22

                      and then changing the getType function to: char * MyMQTTClient::getType(char *b, const char *const *index)

                      Now onto trying to merge the the SerialGateway and MQTTClientGateway. Need to see if it would be easier to merge the MQTTClientGateway into the new SerialGateway or the other way around. Time to study some code.

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

                        Thanks Norbert for the great work! Works very well with mosquitto.

                        I added support for gw.requestTime(...); by modifying MyMQTTClient.cpp after the lines handling I_CONFIG)

                          else if (msg.type == I_TIME)
                          {
                            txBlink(1);
                            if (!sendRoute(
                                  build(msg, GATEWAY_ADDRESS, msg.sender, 255, C_INTERNAL,
                                        I_TIME, 0).set(now())))
                              errBlink(1);
                          }
                        

                        Now I have a timebase for low power (deep standby) sensors.

                        Next I will try to set the time on the gateway with a MQTT Message or NTP....

                        1 Reply Last reply
                        1
                        • 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
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          16

                                          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