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.
  • R ruslan

    to tomkhy: your gateway sketch compiles, but Arduino runs out of memory (I use Nano with W5100 ethernet module, SOFTSPI enabled). It does fit with MY_SIGNING_FEATURE and DEBUG disabled, but I need debug - somehow it is not registering with MQTT server. Please tell me how to reduce memory footprint.

    greglG Offline
    greglG Offline
    gregl
    Hero Member
    wrote on last edited by
    #55

    @ruslan said:

    to tomkhy: your gateway sketch compiles, but Arduino runs out of memory (I use Nano with W5100 ethernet module, SOFTSPI enabled). It does fit with MY_SIGNING_FEATURE and DEBUG disabled, but I need debug - somehow it is not registering with MQTT server. Please tell me how to reduce memory footprint.

    Looks like you have it working now, but just incase, Previously when I have had memory issues , I have upgraded my bootloader to use Optiboot which gives you a little bit more.

    HTH

    1 Reply Last reply
    0
    • A ahhk

      Hi,

      can this run on ESP8266 (as wifi-mqttclient-gateway), too?
      Greetings

      Andreas

      M Offline
      M Offline
      mlava
      wrote on last edited by
      #56

      @ahhk
      Hello all, first post here and a bit new to the mysensors field.
      I also want to know the answer as to whether this will run on the ESP8266 as hope to run a wifi gateway.
      Thanks in advance! :)

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chris021
        wrote on last edited by
        #57

        Also keen to run this on an ESP8266 would be a great for bridging.

        1 Reply Last reply
        0
        • John ConnollyJ Offline
          John ConnollyJ Offline
          John Connolly
          wrote on last edited by
          #58

          OK. I've got the gateway to compile and get the following:

          Started!
          0;0;3;0;9;read: 110-110-0 s=1,c=1,t=0,pt=7,l=5:13.2
          0;0;3;0;9;read: 105-105-0 s=0,c=1,t=1,pt=7,l=5:70.0
          0;0;3;0;9;read: 110-110-0 s=0,c=1,t=1,pt=7,l=5:58.3
          0;0;3;0;9;read: 105-105-0 s=0,c=1,t=1,pt=7,l=5:69.9
          0;0;3;0;9;read: 110-110-0 s=0,c=1,t=1,pt=7,l=5:58.2
          0;0;3;0;9;read: 105-105-0 s=0,c=1,t=1,pt=7,l=5:70.0
          0;0;3;0;9;read: 110-110-0 s=0,c=1,t=1,pt=7,l=5:58.3
          0;0;3;0;9;read: 105-105-0 s=0,c=1,t=1,pt=7,l=5:69.9
          0;0;3;0;9;read: 110-110-0 s=0,c=1,t=1,pt=7,l=5:58.2
          0;0;3;0;9;read: 110-110-0 s=0,c=1,t=1,pt=7,l=5:58.3
          0;0;3;0;9;read: 105-105-0 s=0,c=1,t=1,pt=7,l=5:69.8
          0;0;3;0;9;read: 110-110-0 s=1,c=1,t=0,pt=7,l=5:13.3
          0;0;3;0;9;read: 110-110-0 s=0,c=1,t=1,pt=7,l=5:58.5
          

          I can ping the MQTTClinetGateway from another machine and I've confirmed Mosquitto is running OK with a series of pub/subs from other machines/devices and that side of things is working perfectly fine.

          I'm not seeing any of the above gateway readings publish to my broker. Thoughts?

          Cheers.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tomkxy
            wrote on last edited by
            #59

            Following points to verify and check:

            • is the gateway connected to the broker. As far as I remember you can check that by subscribiing to Mosquitto status messages
            mosquitto_sub -v -t \$SYS/#
            

            If not check what the authentication method is mosquitto is. If it allows anonymous access make sure that "MQTT_AUTH_REQUIRED" is not defined in the MQTTClientGateway sketch. If username and password are set correctly.

            It seems that you are not using signing. So ensure that your MQTTClientGateway is compiled with the signing feature disabled. That are the two points I can imagine now provided that you are sure that you have of course a working ethernet connection.

            1 Reply Last reply
            0
            • John ConnollyJ Offline
              John ConnollyJ Offline
              John Connolly
              wrote on last edited by
              #60

              I downloaded and installed the development branch and got the MQTTClientGateway running on an UNO with a W5100 shield (that I'm suspicious of, in terms of its reliability). The sketch runs great for a while publishing data to Mosquitto on my Mac Mini, but then stops responding after a while. I'm pretty sure the cause of the problem is the ethernet shield as it bombs out when running other sketches - the webserver one for example.

              I have a few of these ENC28J60 boards and I'd like to use one of those instead, but have had some problems.

              http://www.aliexpress.com/item/ENC28J60-LAN-Ethernet-Network-Board-Module-for-arduino-25MHZ-Crystal-AVR-51-LPC-STM32-3-3V/1956963721.html

              I notice in the MQTTClientGateway sketch that I should just need to comment out the one W5100 Ethernet.h library and substitute with the UIPEthernet.h one, but I tried that and had no joy. Does anyone have a working sketch based on the ENC28J60 that they could post, along with the wiring diagram to connect that board in along with any additional tweaks necessary to get it running on an Uno? Thanks in advance. Cheers.

              1 Reply Last reply
              0
              • siodS Offline
                siodS Offline
                siod
                wrote on last edited by siod
                #61

                Hi Guys,

                I get this:

                Started!
                0;0;3;0;9;read: 0-0-0 s=0,c=0,t=0,pt=0,l=0:
                0;0;3;0;9;version mismatch
                0;0;3;0;9;read: 0-0-0 s=0,c=0,t=0,pt=0,l=0:
                0;0;3;0;9;version mismatch
                

                Also the Gateway does not answer to pings. Any suggestions?

                edit: after a rebbot I get valid readings in the Serial monitor of the Arduino IDE now:

                0;0;3;0;9;read: 20-20-0 s=3,c=1,t=16,pt=2,l=2:1
                0;0;3;0;9;read: 20-20-0 s=3,c=1,t=16,pt=2,l=2:0
                0;0;3;0;9;read: 20-20-0 s=3,c=1,t=16,pt=2,l=2:1
                0;0;3;0;9;read: 20-20-0 s=3,c=1,t=16,pt=2,l=2:0
                0;0;3;0;9;read: 20-20-0 s=3,c=1,t=16,pt=2,l=2:1
                0;0;3;0;9;read: 20-20-0 s=3,c=1,t=16,pt=2,l=2:0
                0;0;3;0;9;read: 20-20-0 s=3,c=1,t=16,pt=2,l=2:1
                0;0;3;0;9;read: 20-20-0 s=3,c=1,t=16,pt=2,l=2:0
                0;0;3;0;9;read: 20-20-0 s=3,c=1,t=16,pt=2,l=2:1
                0;0;3;0;9;read: 20-20-0 s=3,c=1,t=16,pt=2,l=2:0
                0;0;3;0;9;read: 20-20-0 s=3,c=1,t=16,pt=2,l=2:1
                

                But still, can´t ping the gw. Double checked IP and Port, seems to be fine.

                still learning...

                1 Reply Last reply
                0
                • John ConnollyJ Offline
                  John ConnollyJ Offline
                  John Connolly
                  wrote on last edited by
                  #62

                  I've ordered a new W5100 module - this time the red mini W5100 board missing the SD Card slot to see if I have better luck. Still keen to see code for an ENC based MQTTClientGateway though, as this will take a while to arrive... ;)

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    ruslan
                    wrote on last edited by
                    #63

                    To developers of the MQTT client:
                    I just tried the GatewayW5100MQTTClient in the latest development branch - it gives me "0;0;3;0;9;Radio init fail" error, while GatewayW5100 sketch works fine. What could be the reason? I noticed that the declarations parts in these sketches are rather different.
                    My setup: ARduino nano clone + W5100 module + NRF24L01 radio. All wired as in the MySensors ethernet gateway guide ([http://www.mysensors.org/build/ethernet_gateway])

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

                      For the W5100 SOFTSPI has to be enabled. I see that this is missing from the sketch..

                      Try adding (coming from the normal W5100 sketch)

                      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
                      //#define MY_W5100_SPI_EN 4  
                      
                      // Enable Soft SPI for NRF radio (note different radio wiring is required)
                      // The W5100 ethernet module seems to have a hard time co-operate with 
                      // radio on the same spi bus.
                      #if !defined(MY_W5100_SPI_EN)
                        #define MY_SOFTSPI
                        #define MY_SOFT_SPI_SCK_PIN 14
                        #define MY_SOFT_SPI_MISO_PIN 16
                        #define MY_SOFT_SPI_MOSI_PIN 15
                      #endif  
                      
                      

                      I'll update the repository.

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        ruslan
                        wrote on last edited by
                        #65

                        Hi, Hek!
                        You are correct. except I also had to add these 2 lines and then radio worked:

                        #define MY_RF24_CE_PIN 5
                        #define MY_RF24_CS_PIN 6
                        

                        Pls fix the repo. Looking forward to seeing mqtt client in the master branch.

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

                          Pushed to build server. Soon merged.
                          https://github.com/mysensors/Arduino/pull/241

                          1 Reply Last reply
                          0
                          • R Offline
                            R Offline
                            ruslan
                            wrote on last edited by
                            #67

                            What is the MQTT message to switch MQTT client gateway into inclusion mode?

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

                              Something like this should work...

                              Topic: mygateway/0/255/3/0/6
                              Payload: 1

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

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

                                Is this MQTTClientGateway in the dev branch only? I didn't see something like this in the 1.5 release/master.
                                I would prefer to use my gateway as client, but I am not skilled enough to use the dev branch and work around resulting problems :sa:

                                greetings
                                Dakky

                                edit:
                                @tomkxy said:

                                @tomkxy said:

                                here https://github.com/tomkxy/Arduino.git in the branch MQTTClient.

                                Did you have a look at my repository above? Functional wise it is the same adapted for version 1.5. I have it in use for quite a while now.

                                hmm is this repo still functional? with the signing_feature enabled i'm getting compile errors:

                                mqttClientGateway:175: error: 'signer' was not declared in this scope
                                             , signer
                                               ^
                                

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

                                Software: MySensors 2.0development

                                S 1 Reply Last reply
                                0
                                • dakkyD dakky

                                  Is this MQTTClientGateway in the dev branch only? I didn't see something like this in the 1.5 release/master.
                                  I would prefer to use my gateway as client, but I am not skilled enough to use the dev branch and work around resulting problems :sa:

                                  greetings
                                  Dakky

                                  edit:
                                  @tomkxy said:

                                  @tomkxy said:

                                  here https://github.com/tomkxy/Arduino.git in the branch MQTTClient.

                                  Did you have a look at my repository above? Functional wise it is the same adapted for version 1.5. I have it in use for quite a while now.

                                  hmm is this repo still functional? with the signing_feature enabled i'm getting compile errors:

                                  mqttClientGateway:175: error: 'signer' was not declared in this scope
                                               , signer
                                                 ^
                                  
                                  S Offline
                                  S Offline
                                  Samuel235
                                  Hardware Contributor
                                  wrote on last edited by
                                  #70

                                  @dakky It is currently only in the Dev branch, yes.

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

                                  1 Reply Last reply
                                  0
                                  • maxtoxM Offline
                                    maxtoxM Offline
                                    maxtox
                                    wrote on last edited by
                                    #71

                                    I Think HERE is the answer of our problem!!!!

                                    http://electronics.stackexchange.com/questions/67212/how-to-avoid-sd-card-and-w1500-spi-mixup-on-the-ethernet-shield

                                    Arduino Mega 2560 with iobroker.net (MQTT, node-red, etc..)

                                    1 Reply Last reply
                                    0
                                    • cowen71C Offline
                                      cowen71C Offline
                                      cowen71
                                      wrote on last edited by
                                      #72

                                      Good afternoon gents!

                                      So I have been playing with openHab and an arduino as a mqtt gateway and this has been successful. The only thing I don't like is that the arduino does not seem to like multiple connections to the MQTT broker.

                                      My next step then is to use an MQTT broker (mosquitto) on the pi and then subscribe to this from the arduino. If I understand correctly, this is exactly what this thread is discussing.

                                      So - I have downloaded the codes and without changing anything, tried to compile. This fails with numerous errors. I have te latest libraries installed and to be honest, I am a little lost as to what is wrong. Before I post lots of error messages, are there any known 'tricks' to get the latest version working?

                                      Hopefully someone can help - Thanks guys :-)

                                      S 1 Reply Last reply
                                      0
                                      • cowen71C cowen71

                                        Good afternoon gents!

                                        So I have been playing with openHab and an arduino as a mqtt gateway and this has been successful. The only thing I don't like is that the arduino does not seem to like multiple connections to the MQTT broker.

                                        My next step then is to use an MQTT broker (mosquitto) on the pi and then subscribe to this from the arduino. If I understand correctly, this is exactly what this thread is discussing.

                                        So - I have downloaded the codes and without changing anything, tried to compile. This fails with numerous errors. I have te latest libraries installed and to be honest, I am a little lost as to what is wrong. Before I post lots of error messages, are there any known 'tricks' to get the latest version working?

                                        Hopefully someone can help - Thanks guys :-)

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

                                        @cowen71 - Could you please give us a little more information to help troubleshoot your issues.

                                        What ethernet module are you using? W5100? If so you need to makesure that you have enabled soft SPI for NRF radio as it doesn't like it being on the same bus. We also have to move the CE/CSN pins for the radio too. All this is explained inside of the sketch itself.

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

                                        1 Reply Last reply
                                        0
                                        • cowen71C Offline
                                          cowen71C Offline
                                          cowen71
                                          wrote on last edited by cowen71
                                          #74

                                          Hi Samuel,

                                          OK, I was hoping there was a known 'trick' to get things working, but maybe I was just dreaming. Of course, if not - much more information is needed!

                                          At the moment I am testing with a Mega2560 with an arduino ethernet shield attached. This has (and still does) work well with the mqtt gateway downloaded from mysensors after a few minor pin assignment changes.

                                          The problem I am having is that I cannot compile the mqttClientGateway code. I get errors. I have to be honest that whilst I had experience 20 years ago with PIC's and other uC's, I am incredibly rusty with C and completely new to Arduinos. So it is a steep learning curve currently. In this case, I would not be surprised if I have made a real schoolboy error!

                                          So what did I do?....
                                          At the moment I installed the PubSubLient library into the Arduino libraries file.
                                          I copied the code from here: https://github.com/ntruchsess/MySensors/tree/mqttclient/libraries/MySensors/examples/MQTTClientGateway
                                          creating the three files in my mqttClientGateway development folder.

                                          I changed nothing (accept target and com port and hit the compile button! This fails with the following error initially:

                                          sketch\MyMQTTClient.cpp:14:30: fatal error: utility/MsTimer2.h: No such file or directory
                                          #include "utility/MsTimer2.h"

                                          I modified the include text to: #include "MsTimer2.h"
                                          and tried to compile again again. The result is:

                                          sketch\MyMQTTClient.cpp: In constructor 'MyMQTTClient::MyMQTTClient(PubSubClient, uint8_t, uint8_t)':

                                          MyMQTTClient.cpp:106: error: no matching function for call to 'MySensor::MySensor(uint8_t&, uint8_t&)'

                                           MySensor(_cepin, _cspin), buffsize(0)
                                          
                                                                               ^
                                          

                                          sketch\MyMQTTClient.cpp:106:41: note: candidates are:

                                          In file included from sketch\MyMQTTClient.h:15:0,

                                                       from sketch\MyMQTTClient.cpp:13:
                                          

                                          C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:158:2: note: MySensor::MySensor(MyTransport&, MyHw&)

                                          MySensor(MyTransport &radio =*new MyTransportNRF24(), MyHw &hw=*new MyHwDriver()

                                          ^

                                          C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:158:2: note: no known conversion for argument 1 from 'uint8_t {aka unsigned char}' to 'MyTransport&'

                                          C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:149:7: note: constexpr MySensor::MySensor(const MySensor&)

                                          class MySensor

                                             ^
                                          

                                          C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:149:7: note: candidate expects 1 argument, 2 provided

                                          C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:149:7: note: constexpr MySensor::MySensor(MySensor&&)

                                          C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:149:7: note: candidate expects 1 argument, 2 provided

                                          sketch\MyMQTTClient.cpp: In member function 'void MyMQTTClient::begin(rf24_pa_dbm_e, uint8_t, rf24_datarate_e, uint8_t, uint8_t, uint8_t)':

                                          MyMQTTClient.cpp:146: error: 'setupRepeaterMode' was not declared in this scope

                                          setupRepeaterMode();

                                                           ^
                                          

                                          MyMQTTClient.cpp:152: error: 'setupRadio' was not declared in this scope

                                          setupRadio(paLevel, channel, dataRate);

                                                                              ^
                                          

                                          MyMQTTClient.cpp:153: error: 'BASE_RADIO_ID' was not declared in this scope

                                          RF24::openReadingPipe(WRITE_PIPE, BASE_RADIO_ID);

                                                                           ^
                                          

                                          MyMQTTClient.cpp:155: error: cannot call member function 'void RF24::startListening()' without object

                                          RF24::startListening();

                                          My suspicion is I have a compatibility problem between library versions and/or the sketch I have downloaded. The radio stuff I can probably solve (hopefully) its the issues before that I am struggling with.

                                          Any advice would be appreciated.

                                          Cheers

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


                                          7

                                          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