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. ESP8266 WiFi gateway port for MySensors

ESP8266 WiFi gateway port for MySensors

Scheduled Pinned Locked Moved Development
328 Posts 56 Posters 309.6k Views 39 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.
  • hekH Offline
    hekH Offline
    hek
    Admin
    wrote on last edited by
    #132

    You cannot mix MyConfig.h between branches.

    In the development brach all MySensors related defines has the prefix "MY_".

    1 Reply Last reply
    0
    • Frank HerrmannF Offline
      Frank HerrmannF Offline
      Frank Herrmann
      wrote on last edited by
      #133

      Hi, if it possible to show a sketch with an ESP8266 WIFI => MQTT gateway? I figure out, that the received sensor data will automatic publish to my MQTT Server running on my Raspi. Then i can install this pice of wonderfull work in every room from my house :)

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

        I created a simple ESP-MQTT sketch a while ago. I've only done some simple tests using it. Feedback appreciated.

        https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino

        Frank HerrmannF FotoFieberF V 3 Replies Last reply
        0
        • hekH hek

          I created a simple ESP-MQTT sketch a while ago. I've only done some simple tests using it. Feedback appreciated.

          https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino

          Frank HerrmannF Offline
          Frank HerrmannF Offline
          Frank Herrmann
          wrote on last edited by Frank Herrmann
          #135

          @hek Very nice! the code are magic :) Very nice solution, i'll test this next days.

          ...
          #include <ESP8266WiFi.h>
          #include <MySensor.h>
          
          void setup() { 
          }
          
          void presentation() {
            // Present locally attached sensors here    
          }
          
          
          void loop() {
            // Send locally attech sensors data here
          }
          
          1 Reply Last reply
          0
          • hekH hek

            I created a simple ESP-MQTT sketch a while ago. I've only done some simple tests using it. Feedback appreciated.

            https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino

            FotoFieberF Offline
            FotoFieberF Offline
            FotoFieber
            Hardware Contributor
            wrote on last edited by
            #136

            @hek said:

            I created a simple ESP-MQTT sketch a while ago. I've only done some simple tests using it. Feedback appreciated.

            https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino

            Testing the above sket from the development branch with a new sensbender micro I get:
            mygateway/255/255/3/0/3 (null) on MQTT

            This is an id request. I answer this request with
            mosquitto_pub -h ds -t "mygateway/255/255/3/0/4" -m 8
            which should set the ID 8 on the sensbender micro in my undestanding. I can see the message in the serial terminal on the ESP-8266 but the message doesn't arrive at the sensbender micro.

            Is my message to set the id correct?

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

              Yes, the response message looks ok. But I must confess that I haven't verified the MQTT gateway much yet. Probably something I've missed (=bug).

              Do you have the possibility to to see where the message ends up or being thrown away (debug-print-debugging is awesome, yes I know...) in the MQTT gateway?

              Or wait a few days until I've had time to look at it.

              FotoFieberF 1 Reply Last reply
              0
              • hekH hek

                Yes, the response message looks ok. But I must confess that I haven't verified the MQTT gateway much yet. Probably something I've missed (=bug).

                Do you have the possibility to to see where the message ends up or being thrown away (debug-print-debugging is awesome, yes I know...) in the MQTT gateway?

                Or wait a few days until I've had time to look at it.

                FotoFieberF Offline
                FotoFieberF Offline
                FotoFieber
                Hardware Contributor
                wrote on last edited by
                #138

                @hek said:

                ...
                Do you have the possibility to to see where the message ends up or being thrown away (debug-print-debugging is awesome, yes I know...) in the MQTT gateway?
                ...
                There seems to be a bug in incomingMQTT:
                replace
                for (str = strtok_r(topic, "/", &p); str && i < 5;
                with
                for (str = strtok_r(topic, "/", &p); str && i <= 5;

                or it will never send a message.

                There seems to be another problem:
                0;0;3;0;9;send: 0-0-0-255 s=255,c=3,t=4,pt=0,l=1,sg=0,st=fail:8

                Why is the payload in st=fail?

                The messages sent to MQTT seem to make a merry go round and come back.... :)

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

                  @FotoFieber said:

                  Why is the payload in st=fail?

                  The payload (8) seems correct. Gateway just never received any ack from node... which is fine for broadcast messages (to node 255) such as this.

                  The messages sent to MQTT seem to make a merry go round and come back....

                  Ok, like you suspected earlier? So we need to subscribe to something else than we publish to then...

                  FotoFieberF 1 Reply Last reply
                  0
                  • hekH hek

                    @FotoFieber said:

                    Why is the payload in st=fail?

                    The payload (8) seems correct. Gateway just never received any ack from node... which is fine for broadcast messages (to node 255) such as this.

                    The messages sent to MQTT seem to make a merry go round and come back....

                    Ok, like you suspected earlier? So we need to subscribe to something else than we publish to then...

                    FotoFieberF Offline
                    FotoFieberF Offline
                    FotoFieber
                    Hardware Contributor
                    wrote on last edited by
                    #140

                    @hek
                    Loaded the ethernet ESP-8266 gateway and entered with telnet:
                    255;255;3;0;4;8

                    It is working as it should. Now I have assigned the id 8.

                    Tried to solve the merry go round but it didn't help. Now I let the stage to the pros.. :)

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      Fabien
                      wrote on last edited by
                      #141

                      Do you think we can use this board with MySensors (with NRF24 or RFM69) ?
                      https://github.com/hallard/NodeMCU-Gateway

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

                        Hi,

                        If I want to use the GatewayESP8266MQTTClient sketch located in the development branch do I also need to use the mysensors libraries in that branch?

                        Thank you,

                        Mike

                        hekH 1 Reply Last reply
                        0
                        • M Mike Cayouette

                          Hi,

                          If I want to use the GatewayESP8266MQTTClient sketch located in the development branch do I also need to use the mysensors libraries in that branch?

                          Thank you,

                          Mike

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

                          @Mike-Cayouette

                          Yes

                          1 Reply Last reply
                          0
                          • hekH hek

                            I created a simple ESP-MQTT sketch a while ago. I've only done some simple tests using it. Feedback appreciated.

                            https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino

                            V Offline
                            V Offline
                            vickey
                            wrote on last edited by vickey
                            #144

                            @hek Thanks for the code. I have few questions in my mind. Firstly do I just have to upload this ESP8266MQTTClient.ino sketch on esp8266 12-E model? or does it needs anything to add in the sketch except SSID and password? I want to use ESP-8266-E and NRF24L01+ as gateway for openhab. If it is possible then, do I have to adopt the same procedure for configuring openhab as ethernet gateway? Secondly, Can I make two gateways using this sketch, is this possible? As I want to add sensors which are 500 meters away at my farmhouse.

                            hekH 1 Reply Last reply
                            0
                            • J Offline
                              J Offline
                              joshmosh
                              wrote on last edited by
                              #145

                              This is a bit off topic, but hopefully not too off ;-)
                              What about a port of the MySensors library /API to ESP8266 ? Instead of two "boards" (Arduino nano plus nRF24L01+) only one would be required. For simple sensors an ESP-01 would be sufficient - about the size of a nRF24, but with much more muscle than an Arduino. Of course, running off a battery probably would not work because of the high power consumption of the ESP.

                              Or am I asking for something which is already possible ?

                              Josh

                              1 Reply Last reply
                              0
                              • V vickey

                                @hek Thanks for the code. I have few questions in my mind. Firstly do I just have to upload this ESP8266MQTTClient.ino sketch on esp8266 12-E model? or does it needs anything to add in the sketch except SSID and password? I want to use ESP-8266-E and NRF24L01+ as gateway for openhab. If it is possible then, do I have to adopt the same procedure for configuring openhab as ethernet gateway? Secondly, Can I make two gateways using this sketch, is this possible? As I want to add sensors which are 500 meters away at my farmhouse.

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

                                @vickey said:

                                @hek Thanks for the code. I have few questions in my mind. Firstly do I just have to upload this ESP8266MQTTClient.ino sketch on esp8266 12-E model?

                                Yes

                                or does it needs anything to add in the sketch except SSID and password?

                                Entering SSID/PW should be enough.

                                I want to use ESP-8266-E and NRF24L01+ as gateway for openhab. If it is possible then, do I have to adopt the same procedure for configuring openhab as ethernet gateway?

                                I'm not an expert on openhab.. so I'll let someone else answer this one. But the ESP variant behaves exactly like the W5100 version.

                                Secondly, Can I make two gateways using this sketch, is this possible? As I want to add sensors which are 500 meters away at my farmhouse.

                                If openhab supports multiple gateways, sure. But you might wanna run sensor networks on different frequencies or changing MY_RF24_BASE_RADIO_ID.

                                @joshmosh

                                Or am I asking for something which is already possible ?

                                Yes, the code runs directly on the ESP8266.

                                1 Reply Last reply
                                0
                                • J Offline
                                  J Offline
                                  joshmosh
                                  wrote on last edited by
                                  #147

                                  @hek
                                  that's good news, thank you ! Now the most expensive part will be the power supply ;-)

                                  Cheers
                                  Josh

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

                                    @hek I have installed GatewayESP8266MQTTClient sketch on my ESP-8266 12E.
                                    Here is sketch I am using

                                    #include <EEPROM.h>
                                    #include <SPI.h>
                                    
                                    // Enable debug prints to serial monitor
                                    #define MY_DEBUG 
                                    
                                    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
                                    #define MY_BAUD_RATE 9600
                                    
                                    // Enables and select radio type (if attached)
                                    #define MY_RADIO_NRF24
                                    //#define MY_RADIO_RFM69
                                    
                                    #define MY_GATEWAY_MQTT_CLIENT
                                    
                                    // Set this nodes topic prefix
                                    #define MY_MQTT_TOPIC_PREFIX "mygateway"
                                    
                                    // Set MQTT client id
                                    #define MY_MQTT_CLIENT_ID "mysensors-1"
                                    
                                    // Enable these if your MQTT broker requires usenrame/password
                                    //#define MY_MQTT_USER "admin"
                                    //#define MY_MQTT_PASSWORD "MyPassword"
                                    
                                    // Set WIFI SSID and password
                                    #define MY_ESP8266_SSID "Ahmed"
                                    #define MY_ESP8266_PASSWORD "MyPassword"
                                    
                                    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
                                    #define MY_IP_ADDRESS 192,168,0,31
                                    
                                    // If using static ip you need to define Gateway and Subnet address as well
                                    #define MY_IP_GATEWAY_ADDRESS 192,168,0,1
                                    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
                                    
                                    
                                    // MQTT broker ip address.  
                                    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 0, 30
                                    
                                    // The MQTT broker port to to open 
                                    #define MY_PORT 1883      
                                    
                                     /*
                                    // Flash leds on rx/tx/err
                                    #define MY_LEDS_BLINKING_FEATURE
                                    // Set blinking period
                                    #define MY_DEFAULT_LED_BLINK_PERIOD 300
                                    
                                    // Enable inclusion mode
                                    #define MY_INCLUSION_MODE_FEATURE
                                    // Enable Inclusion mode button on gateway
                                    #define MY_INCLUSION_BUTTON_FEATURE
                                    // Set inclusion mode duration (in seconds)
                                    #define MY_INCLUSION_MODE_DURATION 60 
                                    // Digital pin used for inclusion mode button
                                    #define MY_INCLUSION_MODE_BUTTON_PIN  3 
                                    
                                    #define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
                                    #define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
                                    #define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
                                    */
                                    
                                    #include <ESP8266WiFi.h>
                                    #include <MySensor.h>
                                    
                                    void setup() { 
                                    }
                                    
                                    void presentation() {
                                      // Present locally attached sensors here    
                                    }
                                    
                                    
                                    void loop() {
                                      // Send locally attech sensors data here
                                    }
                                    

                                    Here is the debug

                                    0;0;3;0;9;Starting...
                                    scandone
                                    f 0, ....scandone
                                    state: 0 -> 2 (b0)
                                    .state: 2 -> 3 (0)
                                    state: 3 -> 5 (10)
                                    add 0
                                    aid 1
                                    cnt 
                                    
                                    connected with Ahmed, channel 1
                                    ip:192.168.0.31,mask:255.255.255.0,gw:192.168.0.1
                                    .IP: 192.168.0.31
                                    0;0;3;0;9;gateway started, id=0, parent=0, distance=0
                                    0;0;3;0;9;Attempting MQTT connection...
                                    

                                    And it keeps attempinng for MQTT connection.

                                    I have installed Domoticz on my RPi and added a hardware Mysensors Gateway with LAN interface with remote address i.e. 192.168.0.31 in my case and port 1883. Here is Domoticz log

                                    2015-10-17 12:50:26.675  Hardware Monitor: Fetching data (System sensors)
                                    2015-10-17 12:50:31.590  Error: MySensors: Error: Connection refused
                                    2015-10-17 12:50:31.590  Error: TCP: Error: Connection refused
                                    

                                    I don't have mosquitto installed in my Rpi.

                                    May someone suggest me any solution.

                                    1 Reply Last reply
                                    0
                                    • J Offline
                                      J Offline
                                      joshmosh
                                      wrote on last edited by
                                      #149

                                      @hek
                                      Good morning. I had wired up my nodemcu a nRF24L01+, loaded the gateway sketch and bingo ! Zero problems, works like charm. Thanks a lot !!!

                                      I am using Domoticz as controller, with a serial USB gateway to connect my various sensors. In the serial console of the ESP8266 gateway I see that the messages of my sensors show up, but since I have not yet announced the gateway to Domoticz, there seems to be no interference. If I connect the ESP8266 gateway to a controller (in my case Domoticz), I guess that it will be required that the nodes need to choose the respective gateway (by using the parentNodeId) with which they like to communicate ? Currently, I am using parentNodeId = AUTO in all my nodes.
                                      I will do some testing to get an idea of the reach of my WiFi compared to the reach of my serial USB gateway (I have a nRF24L01+ with external antanna and booster in my gateway, so I am able to "see" a portable node even outside my house and 50 m away.

                                      Again, thank you for this very useful extension of MySensors. I think I have not yet an estimate of the full potential of it

                                      Cheers
                                      Josh

                                      YveauxY 1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        gloob
                                        wrote on last edited by
                                        #150

                                        Hello,

                                        I also tried to build a WiFi gateway today.
                                        I get the following serial output when starting the gateway:

                                        ESP8266 MySensors Gateway
                                        Connecting to *************
                                        ...Connected!
                                        IP: 192.168.1.218
                                        0;0;3;0;9;gateway started, id=0, parent=0, distance=0
                                        

                                        Does this mean that everything is correct and I can integrate it into my FHEM solution?
                                        Currently I'm working with a serial gatway. Do I have to modify something in my sensors when I switch to the new gateway?

                                        YveauxY 1 Reply Last reply
                                        0
                                        • G gloob

                                          Hello,

                                          I also tried to build a WiFi gateway today.
                                          I get the following serial output when starting the gateway:

                                          ESP8266 MySensors Gateway
                                          Connecting to *************
                                          ...Connected!
                                          IP: 192.168.1.218
                                          0;0;3;0;9;gateway started, id=0, parent=0, distance=0
                                          

                                          Does this mean that everything is correct and I can integrate it into my FHEM solution?
                                          Currently I'm working with a serial gatway. Do I have to modify something in my sensors when I switch to the new gateway?

                                          YveauxY Offline
                                          YveauxY Offline
                                          Yveaux
                                          Mod
                                          wrote on last edited by
                                          #151

                                          @gloob said:

                                          I get the following serial output when starting the gateway:

                                          Looking good! Congrats!

                                          I have no experience using FHEM, but you should be able to use the WiFi gateway just like the regular ethernet gateway (as seen from FHEM).
                                          So look around on this forum for any posts regarding usage of FHEM & ethernet gateway and you should be good.

                                          http://yveaux.blogspot.nl

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


                                          17

                                          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