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. Guide: Setting up and testing MQTT Client Gateway

Guide: Setting up and testing MQTT Client Gateway

Scheduled Pinned Locked Moved Development
78 Posts 18 Posters 53.1k Views 18 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.
  • M Mike Cayouette

    I have tried a few things but without success, I keep getting the following output on the gateway when I try to send a message to a sensor

    0;0;3;0;9;send: 0-0-0-106 s=3,c=1,t=2,pt=0,l=1,sg=0,st=fail:0
    

    Oddly the sensors have no problem sending a message to the gateway. For example when I reset my dimmer the serial output on the gateway is the following

    ;0;3;0;9;read: 106-106-0 s=255,c=0,t=17,pt=0,l=3,sg=0:1.5
    0;0;3;0;9;Sending message on topic: mygateway1-out/106/255/0/0/17
    0;0;3;0;9;read: 106-106-0 s=255,c=3,t=6,pt=1,l=1,sg=0:0
    0;0;3;0;9;Sending message on topic: mygateway1-out/106/255/3/0/6
    

    I have used an external power supply rather than connect the radio to the 3.3v pin on the nodemcu breakout board but that did not change anything, I also added the following but without luck

    #define MY_RF24_PA_LEVEL RF24_PA_LOW

    The only thing I have not done was compile the sensor with the library in the dev branch, but I was under the impression I did not need to.

    Any help would be appreciated.

    Thank you,

    Mike

    ahmedadelhosniA Offline
    ahmedadelhosniA Offline
    ahmedadelhosni
    wrote on last edited by
    #11

    @Mike-Cayouette Can you check what I have found and tell me whether it temporary solved your problem or not ? http://forum.mysensors.org/topic/2193/gatewayesp8266mqttclient-in-development-branch/11

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mike Cayouette
      wrote on last edited by Mike Cayouette
      #12

      @ahmedadelhosni That worked, I can now send messages from my gateway.

      Thank you for your help

      Mike

      ahmedadelhosniA 1 Reply Last reply
      0
      • M Mike Cayouette

        @ahmedadelhosni That worked, I can now send messages from my gateway.

        Thank you for your help

        Mike

        ahmedadelhosniA Offline
        ahmedadelhosniA Offline
        ahmedadelhosni
        wrote on last edited by
        #13

        @Mike-Cayouette Glad that it worked. Please note that these would be temporary workarounds for MQTT support only. I guess that won't work if the sensor node is far away from the gateway and needs a repeater in the middle, because in that workaround you don't check your look up table.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mike Cayouette
          wrote on last edited by
          #14

          @ahmedadelhosni I have not had to add any repeaters to my network yet so I should be good until a more permanent solution is worked into the library. Thank you again for you solution.

          @hek Do you expect a more permanent fix for this solution to be pushed to the dev branch?
          http://forum.mysensors.org/topic/2193/gatewayesp8266mqttclient-in-development-branch/11

          Thank you,

          Mike

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

            Ok, verified sending a message to a node here now when repeater mode is enabled. Works fine and message is received.

            Here is the change I made. Soon merged into development.
            https://github.com/mysensors/Arduino/pull/251

            ahmedadelhosniA 1 Reply Last reply
            0
            • L Offline
              L Offline
              Lars65
              wrote on last edited by
              #16

              Great work. I use an ESP8266 12E, and it works just fine. :)

              1 Reply Last reply
              0
              • JohnJ Offline
                JohnJ Offline
                John
                Plugin Developer
                wrote on last edited by
                #17

                All though this topic is related to the development branch, has the topic structure been fixed (except for prefix)?

                My Domotica project: http://www.pidome.org

                1 Reply Last reply
                0
                • hekH hek

                  Ok, verified sending a message to a node here now when repeater mode is enabled. Works fine and message is received.

                  Here is the change I made. Soon merged into development.
                  https://github.com/mysensors/Arduino/pull/251

                  ahmedadelhosniA Offline
                  ahmedadelhosniA Offline
                  ahmedadelhosni
                  wrote on last edited by
                  #18

                  @hek What about the first issue which I reported about ? Still returns TRUE and returns.

                  if (strcmp_P(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0) {
                  	// Message not for us or malformed!
                         	return;
                  }
                  

                  Is it reproducible at your side ?

                  hekH 1 Reply Last reply
                  0
                  • ahmedadelhosniA ahmedadelhosni

                    @hek What about the first issue which I reported about ? Still returns TRUE and returns.

                    if (strcmp_P(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0) {
                    	// Message not for us or malformed!
                           	return;
                    }
                    

                    Is it reproducible at your side ?

                    hekH Offline
                    hekH Offline
                    hek
                    Admin
                    wrote on last edited by
                    #19

                    @ahmedadelhosni

                    No, I couldn't reproduce any problems with topic naming.

                    I use the default subscribe/publish prefix in the sketch and can send messages without any problem.

                    1 Reply Last reply
                    0
                    • hekH hek

                      (this post currently applies to the development branch)

                      You can run the MQTT gateway on an Arduino+W5100 ethernet module or the ESP8266. Connect radio and ethernet module exactly like for the normal gateway.

                      Download and install the MySensors development branch

                      The use one of the following sketches depending on the hardware you use:
                      https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino
                      or
                      https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino

                      The topic resembles the serial protocol. You must define you preferred subscribe and publish prefix in the sketch. The topic is build like this:
                      MY_MQTT_PUBLISH_TOPIC_PREFIX/FROM-NODE-ID/SENSOR-ID/CMD-TYPE/ACK-FLAG/SUB-TYPE

                      Read more about the serial protocol here. An example topic for data received from your gateway could look like this:

                      mygateway1-out/2/1/1/0/49

                      If you want to send data to your sensors use MY_MQTT_SUBSCRIBE_TOPIC_PREFIX defined in your sketch. Should be looking like this (using default sketch):

                      mygateway1-in/2/1/1/0/49

                      You can test your gateway using mosquitto as broker.

                      Make sure to set MY_IP_GATEWAY_ADDRESS in gateway pointing to you computers ip-number (on the same lan).

                      Start the broker (leave this running):
                      > mosquitto

                      Now start your gateway and you should see something like this in the gateway log. Note that I have a GPS sensor running in my radio network which send data to the gateway all the time:

                      0;0;3;0;9;gateway started, id=0, parent=0, distance=0
                      0;0;3;0;9;Attempting MQTT connection...
                      0;0;3;0;9;MQTT connected
                      0;0;3;0;9;read: 2-2-0 s=1,c=1,t=49,pt=0,l=22,sg=0:55.722519;13.018120
                      0;0;3;0;9;Sending message on topic: mygateway1-out/2/1/1/0/49
                      0;0;3;0;9;read: 2-2-0 s=1,c=1,t=49,pt=0,l=22,sg=0:55.722519;13.018121
                      0;0;3;0;9;Sending message on topic: mygateway1-out/2/1/1/0/49
                      

                      Subscribe to messages (in another shell on your computer)
                      > mosquitto_sub -v -t 'mygateway1-out/#'

                      You should see the messages like you saw in the gateway-log showing up like this:

                      mygateway1-out/2/1/1/0/49 55.722519;13.018121;13
                      mygateway1-out/2/1/1/0/49 55.722519;13.018114;12
                      mygateway1-out/2/1/1/0/49 55.722527;13.018120;11
                      mygateway1-out/2/1/1/0/49 55.722534;13.018122;10
                      

                      Sending (publishing) messages to your sensor network:
                      > mosquitto_pub -t 'mygateway1-in/2/1/1/0/49' -m '0,29'

                      S Offline
                      S Offline
                      Samuel235
                      Hardware Contributor
                      wrote on last edited by
                      #20

                      @hek said:

                      You can run the MQTT gateway on an Arduino+W5100 ethernet module or the ESP8266. Connect radio and ethernet module exactly like for the normal gateway.

                      Have we managed to get a MQTT Gateway working on a Arduino with an ENC28J60 module rather than a w5100?

                      MySensors 2.1.1
                      Controller - OpenHAB (Virtual Machine)
                      Gateway - Arduino Mega MQTT Gateway W5100

                      hekH ahmedadelhosniA 2 Replies Last reply
                      0
                      • S Samuel235

                        @hek said:

                        You can run the MQTT gateway on an Arduino+W5100 ethernet module or the ESP8266. Connect radio and ethernet module exactly like for the normal gateway.

                        Have we managed to get a MQTT Gateway working on a Arduino with an ENC28J60 module rather than a w5100?

                        hekH Offline
                        hekH Offline
                        hek
                        Admin
                        wrote on last edited by
                        #21

                        @samuel235

                        I didn't bother trying. The ENC-library is gigantic and the MQTT implementation used does not support the ENC-module.

                        S 2 Replies Last reply
                        0
                        • S Samuel235

                          @hek said:

                          You can run the MQTT gateway on an Arduino+W5100 ethernet module or the ESP8266. Connect radio and ethernet module exactly like for the normal gateway.

                          Have we managed to get a MQTT Gateway working on a Arduino with an ENC28J60 module rather than a w5100?

                          ahmedadelhosniA Offline
                          ahmedadelhosniA Offline
                          ahmedadelhosni
                          wrote on last edited by
                          #22

                          @samuel235 I don't really encourage you to use ENC. I spent months trying to make it stable and I failed. There are several manufactures and as far as I know that there are several software workarounds to fix problem in the silicon chips. I turned to use W5100 and it is much better till now.
                          N.B.: Some people managed to run ENC with good stability but as I have said, there may be different manufacturers so I got confused and tried the W5100.

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

                            @ahmedadelhosni I have now turned to the W5100 shield myself. Works a charm, super smooth!

                            MySensors 2.1.1
                            Controller - OpenHAB (Virtual Machine)
                            Gateway - Arduino Mega MQTT Gateway W5100

                            1 Reply Last reply
                            1
                            • V Offline
                              V Offline
                              vickey
                              wrote on last edited by
                              #24

                              I tried to make MQTT client gateway but it is giving following error while compiling

                              C:\Users\Ahmed\AppData\Local\Temp\build8359488613260197686.tmp/arduino.ar(core_esp8266_postmortem.c.o): In function `abort':
                              C:\Users\Ahmed\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\2.0.0-rc2\cores\esp8266/core_esp8266_postmortem.c:177: multiple definition of `abort'
                              GatewayESP8266MQTTClient.cpp.o:C:\Users\Ahmed\Documents\Arduino\libraries\MySensors/core/MyMainESP8266.cpp:46: first defined here
                              collect2.exe: error: ld returned 1 exit status
                              Error compiling.
                              

                              Any suggestions @hek ?

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

                                @vickey
                                Sorry haven't seen this error. Which ESP board version do you have installed in the IDE? (See Board manager).

                                Please do no double post on the forum! Only creates annoyance.

                                1 Reply Last reply
                                0
                                • V Offline
                                  V Offline
                                  vickey
                                  wrote on last edited by
                                  #26

                                  @hek I am using Stable ESP8266 version 2.0.0 from stable release

                                  1 Reply Last reply
                                  0
                                  • C Offline
                                    C Offline
                                    ciprian
                                    wrote on last edited by
                                    #27

                                    If it helps:
                                    in ESP8266 ver. 2.0.0 was added abort in
                                    here
                                    cores/esp8266/core_esp8266_postmortem.c:

                                    void abort() __attribute__((noreturn));
                                    
                                    void abort(){
                                        // cause exception
                                        s_abort_called = true;
                                        do {
                                            *((int*)0) = 0;
                                        } while(true);
                                    } 
                                    

                                    i comment the lines in MySensors/core/MyMainESP8266.cpp and it compiled ok.

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

                                      @ciprian
                                      This has been fixed since a while back.

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

                                        Hello.

                                        I tried the development branch because I prefer having my gateway not as message broker.
                                        I had some problems resulting in conflicting entries for the gateway in MyConfig.h and the sketch. MyConfig.h always wins :D for the release it might be more transparent for the user if there is only one location, where the gateway settings are defined: example or MyConfig.h

                                        So much for the feedback, now to the problems:
                                        I use the w5100 version of the sketch with a static IP.

                                        In the serial monitor i see:

                                        0;0;3;0;9;Starting gateway (RNNGA-, 1.6.0-beta)
                                        0;0;3;0;9;Radio init successful.
                                        IP: 0.40.68.10
                                        0;0;3;0;9;Attempting MQTT connection...
                                        0;0;3;0;9;Attempting MQTT connection...
                                        0;0;3;0;9;Attempting MQTT connection...
                                        0;0;3;0;9;Attempting MQTT connection...
                                        0;0;3;0;9;Init complete, id=0, parent=0, distance=0
                                        0;0;3;0;9;Attempting MQTT connection...
                                        0;0;3;0;9;Attempting MQTT connection...
                                        0;0;3;0;9;Attempting MQTT connection...
                                        0;0;3;0;9;Attempting MQTT connection...
                                        

                                        in the log of the moquitto server i see:

                                        1450112394: New connection from 192.168.100.10 on port 1883.
                                        1450112394: New connection from 192.168.100.10 on port 1883.
                                        1450112394: Socket error on client <unknown>, disconnecting.
                                        1450112409: New connection from 192.168.100.10 on port 1883.
                                        1450112409: New connection from 192.168.100.10 on port 1883.
                                        

                                        The gateway tries to open a lot of connections and all of them seem to die after a short while
                                        Any idea?

                                        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
                                        • M Offline
                                          M Offline
                                          Mike Cayouette
                                          wrote on last edited by
                                          #30

                                          @dakky The gateway tries to open a lot of connections and all of them seem to die after a short while

                                          I had a similar problem a while back, not with the mysensors dev branch, but while using the subpub MQTT library on a ESP8266. After upgrading my MQTT (mosquitto) server to version 1.3.5 it corrected to the problem. You may want to take a look at the version you are running.

                                          Mike

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


                                          12

                                          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