💬 Building a WiFi Gateway using ESP8266
-
Hello! I'm so happy with the MySensors community the forum helped me so much to find answers, but I can't figure out the following:
I'm building an Wi-Fi Gateway using an ESP8266. That gateway is running now but I want to add the LEDS and inclusion mode button. In the comments of the code I find out that I have to use pin 16 for all the leds?// Flash leds on rx/tx/err // Led pins used if blinking feature is enabled above #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 LEDIs that correct? And with D? Pin do I have to use?
For the inclusion mode button I have to use pin D1:
// Digital pin used for inclusion mode button #define MY_INCLUSION_MODE_BUTTON_PIN D1But I can't compile this because I have to use an pin number and not just D1. How can I fix that? And how can I test/debug the button to see of it's in the inclusion mode?
Thanks in advance!
Robin -
Hello! I'm so happy with the MySensors community the forum helped me so much to find answers, but I can't figure out the following:
I'm building an Wi-Fi Gateway using an ESP8266. That gateway is running now but I want to add the LEDS and inclusion mode button. In the comments of the code I find out that I have to use pin 16 for all the leds?// Flash leds on rx/tx/err // Led pins used if blinking feature is enabled above #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 LEDIs that correct? And with D? Pin do I have to use?
For the inclusion mode button I have to use pin D1:
// Digital pin used for inclusion mode button #define MY_INCLUSION_MODE_BUTTON_PIN D1But I can't compile this because I have to use an pin number and not just D1. How can I fix that? And how can I test/debug the button to see of it's in the inclusion mode?
Thanks in advance!
RobinHi @b0wi, welcome to the forum!
Some boards (for example Wemos/Lolin) define the Dn pins. If your board does not use the Dn naming convention, or if you like the gpio numbers better, just use the (gpio) number.
Depending on your board, different pins can be used for different things. Some pins control boot behavior for example. See https://forum.mysensors.org/post/64783 for an earlier discussion on the same subject.
-
Hi @b0wi, welcome to the forum!
Some boards (for example Wemos/Lolin) define the Dn pins. If your board does not use the Dn naming convention, or if you like the gpio numbers better, just use the (gpio) number.
Depending on your board, different pins can be used for different things. Some pins control boot behavior for example. See https://forum.mysensors.org/post/64783 for an earlier discussion on the same subject.
Thanks @mfalkvidd, I'm using this board: https://nl.aliexpress.com/item/NodeMcu-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266-module/32448461056.html?spm=a2g0s.13010208.99999999.329.1df83c00aOlGkL
I've to use different pins for each LED right?
// Flash leds on rx/tx/err // Led pins used if blinking feature is enabled above #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 LEDAnd how can I test my inclusion button?
Is there something to see in the log output? -
Thanks @mfalkvidd, I'm using this board: https://nl.aliexpress.com/item/NodeMcu-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266-module/32448461056.html?spm=a2g0s.13010208.99999999.329.1df83c00aOlGkL
I've to use different pins for each LED right?
// Flash leds on rx/tx/err // Led pins used if blinking feature is enabled above #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 LEDAnd how can I test my inclusion button?
Is there something to see in the log output?Indication leds: the same pin can be used. Pro: only one pin is needed. Con: you won't be able to see the type of indication. An alternaive, if you can't find enough pins, is to only activate one or two.
Inclusion: hopefully someone else can assist. I have never used inclusion.
-
Indication leds: the same pin can be used. Pro: only one pin is needed. Con: you won't be able to see the type of indication. An alternaive, if you can't find enough pins, is to only activate one or two.
Inclusion: hopefully someone else can assist. I have never used inclusion.
@mfalkvidd said in 💬 Building a WiFi Gateway using ESP8266:
Indication leds: the same pin can be used. Pro: only one pin is needed. Con: you won't be able to see the type of indication. An alternaive, if you can't find enough pins, is to only activate one or two.
Inclusion: hopefully someone else can assist. I have never used inclusion.
It's working now!
I'm using the following pins for the leds:// Flash leds on rx/tx/err // Led pins used if blinking feature is enabled above #define MY_DEFAULT_ERR_LED_PIN 0 // [D3 / GPIO 0] Error led pin (Red) #define MY_DEFAULT_RX_LED_PIN 2 // [D4 / GPIO 2] Receive led pin (Green) #define MY_DEFAULT_TX_LED_PIN 16 // [D0 / GPIO 16] Send led pin (Yellow)
The leds where on all the time except when there was some activity, so I had to invent the leds:
// Inverses the behavior of leds #define MY_WITH_LEDS_BLINKING_INVERSEFor the inclusion button I've used:
// Digital pin used for inclusion mode button #define MY_INCLUSION_MODE_BUTTON_PIN 5 // [D1 / GPIO 5] Button pinI needed to use an pull up resistor (10K ohm) for more stability.

-
@joseyapor On one MySensors network there can only be one MySensors gateway. But on one IP network, there can be many MySensors gateways. Exactly how many depends on geography and chosen transports but at the very least a few hundred. Thousands if you really need and plan accordingly.
@mfalkvidd
Quotes:
"Don't define MY_RADIO_NRF24 and you're good to go. It will still be a gateway, but a gateway with local sensors and no radio."
and
"On one MySensors network there can only be one MySensors gateway. But on one IP network, there can be many MySensors gateways. Exactly how many depends on geography and chosen transports but at the very least a few hundred. Thousands if you really need and plan accordingly."Let´s say I have multiple ESPs, which should all act like a sensor node. I have a RPi w Domoticz, Mosquitto and MySensors MQTT ethernet gateway.
I add the MQTT gateway to Domotics, listening on port 1883 (Mosquitto port). Now I set up a sketch, using#define MY_IP_ADDRESS 192,168,178,151 #define MY_CONTROLLER_IP_ADDRESS 192,168,178,200 #define MY_PORT 1883which sets the gateway to client / node mode (as read on the documentation).
Setting a node Id is ignored, ID is 0 and can´t be changed, so it is recognized as a gateway at domoticz.
If I now set a second node to a different IP address and name, it overwrites the old one (as you say, there can be only one gateway).
The question now is: how can I set up another ESP? Do I need another RPi or virtual machine with different IP address to install another gateway? -
@mfalkvidd
Quotes:
"Don't define MY_RADIO_NRF24 and you're good to go. It will still be a gateway, but a gateway with local sensors and no radio."
and
"On one MySensors network there can only be one MySensors gateway. But on one IP network, there can be many MySensors gateways. Exactly how many depends on geography and chosen transports but at the very least a few hundred. Thousands if you really need and plan accordingly."Let´s say I have multiple ESPs, which should all act like a sensor node. I have a RPi w Domoticz, Mosquitto and MySensors MQTT ethernet gateway.
I add the MQTT gateway to Domotics, listening on port 1883 (Mosquitto port). Now I set up a sketch, using#define MY_IP_ADDRESS 192,168,178,151 #define MY_CONTROLLER_IP_ADDRESS 192,168,178,200 #define MY_PORT 1883which sets the gateway to client / node mode (as read on the documentation).
Setting a node Id is ignored, ID is 0 and can´t be changed, so it is recognized as a gateway at domoticz.
If I now set a second node to a different IP address and name, it overwrites the old one (as you say, there can be only one gateway).
The question now is: how can I set up another ESP? Do I need another RPi or virtual machine with different IP address to install another gateway?@inso said in 💬 Building a WiFi Gateway using ESP8266:
Setting a node Id is ignored, ID is 0 and can´t be changed, so it is recognized as a gateway at domoticz.
Imo using ESP8266-based devices all as GW's with locally attached switches (or other actively addressed children) conflicts also with other controller types (e.g. FHEM also doesn't like that on more than one GW).
If you want to use that type of hardware, better use a different firmware like ESPEasy or Tasmota. The later seems to be a good fit for any installation using a MQTT-Server. (I personally don't like that kind of setup, wifi shouldn't be used for HA purposes imo).Just my2ct.
-
@inso said in 💬 Building a WiFi Gateway using ESP8266:
Setting a node Id is ignored, ID is 0 and can´t be changed, so it is recognized as a gateway at domoticz.
Imo using ESP8266-based devices all as GW's with locally attached switches (or other actively addressed children) conflicts also with other controller types (e.g. FHEM also doesn't like that on more than one GW).
If you want to use that type of hardware, better use a different firmware like ESPEasy or Tasmota. The later seems to be a good fit for any installation using a MQTT-Server. (I personally don't like that kind of setup, wifi shouldn't be used for HA purposes imo).Just my2ct.
@rejoe2
If I only would set up 8266´s I´d give it a try - problem is, I´m in love with the ESP 32.
Bluetooth LE, multithreading, a second core only for the wifi stuff so no crashes on high wlan activity and no problems with time-critical events, lots of GPIO, awesome processor power, combined with the lower power consumption makes this the most-used chip here :)
As far as I can see, both solutions you mentioned are not made for the ESP32 :( .
So I´d like to stick to MySensors as I could use lots of the sketches almost 1:1 (can´t be that hard to get more then one MQTT-"Client" running -.-).
Only real other options I see is using MQTT-Clientsoftware from Basecamp or just set up an asynchronous http socket and code / decode the JSON-parameters send from and to Domoticz myself.. -
Sorry, I'm not familiar with the ESP32; perhaps you have a look around for other more powerful platforms on MySensors, starting here: https://forum.mysensors.org/topic/6961/nrf5-action.
The problem within MySensors afaik is a double one:
-
First you have to make sure the GW get's the message. Eg. in FHEM, this is a problem, as one node basically is only identified by it's NodeID. As already described, internally there's a distinction between the GW part and the Sensor (node-) part. And the Sensor part gets unavoidably (at least afaik) the NodeID 0 - so for the controller all the Children are located at the same Node.
As the controller notes just one IO (aka GW) per Node, Messages to the "unified" Node 0 will always be routed to the same GW. If this is different when using MQTT as transport layer and not serial or IP communication? (could be, as more clients can subscribe to a "Node 0"-topic...) -
Second thing then is to make sure to not mess up messages intented for different GW's when doing some "broadcasting" by MQTT. Means: use different ChildID's for all the GW's sensors and actuators.
Best success!
-
-
I get the following errors when trying to Verify/Compile. I am trying to use the example sketch without any edits. Any ideas on what to do to fix this problem?
Under additional Board Mangers I have the following.
https://raw.githubusercontent.com/mysensors/ArduinoBoards/master/package_mysensors.org_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json
I have MySensors version 2.3.0 installed and have trying using previous versions.Errors:
In file included from E:*\MySketchesNew\libraries\MySensors/MySensors.h:420:0,
from E:*\MySketchesNew\GatewayESP8266\GatewayESP8266.ino:118:
E:***\MySketchesNew\libraries\MySensors/hal/architecture/ESP8266/MyMainESP8266.cpp:57:53:
error: declaration of C function 'void ets_update_cpu_frequency(int)'
conflicts with extern "C" void ets_update_cpu_frequency(int freqmhz);
In file included from C:\Users*\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/pgmspace.h:10:0,
from C:\Users*\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/Arduino.h:256,
from C:\Users*\AppData\Local\Temp\arduino_build_755180\sketch\GatewayESP8266.ino.cpp:1:
C:\Users*\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include/ets_sys.h:218:6:
error: previous declaration 'void ets_update_cpu_frequency(uint32_t)' here void ets_update_cpu_frequency(uint32_t ticks_per_us);exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).Thank you for the assistance.
-
Sorry, I'm not familiar with the ESP32; perhaps you have a look around for other more powerful platforms on MySensors, starting here: https://forum.mysensors.org/topic/6961/nrf5-action.
The problem within MySensors afaik is a double one:
-
First you have to make sure the GW get's the message. Eg. in FHEM, this is a problem, as one node basically is only identified by it's NodeID. As already described, internally there's a distinction between the GW part and the Sensor (node-) part. And the Sensor part gets unavoidably (at least afaik) the NodeID 0 - so for the controller all the Children are located at the same Node.
As the controller notes just one IO (aka GW) per Node, Messages to the "unified" Node 0 will always be routed to the same GW. If this is different when using MQTT as transport layer and not serial or IP communication? (could be, as more clients can subscribe to a "Node 0"-topic...) -
Second thing then is to make sure to not mess up messages intented for different GW's when doing some "broadcasting" by MQTT. Means: use different ChildID's for all the GW's sensors and actuators.
Best success!
@rejoe2
You´re absolutely right.
After 4+ hours debugging the MQTT gateway + ~10h trying to get MySensors MQTT on ethernet working properly, I tried a different way:
installed NoteRed on the RPi and an asynchronous MQTT client on the ESP32, and within ~1 hour I had a fast and stable way to send messages from and to my nodes. Adding JSON parser on the ESP, and I can perfectly communicate with dummy Domoticz devices.
Also, except of you and one very helpful guy within a private chat, noone preplied to MQTT-questions and ESP-stuff. Seems working with ESPs is reluctantly seen here on the forum.?
So I assume a different way then using MySensors for everything except (battery-powered) Arduinos is the best I can do, to also have no problems in the future.. -
-
@rejoe2
You´re absolutely right.
After 4+ hours debugging the MQTT gateway + ~10h trying to get MySensors MQTT on ethernet working properly, I tried a different way:
installed NoteRed on the RPi and an asynchronous MQTT client on the ESP32, and within ~1 hour I had a fast and stable way to send messages from and to my nodes. Adding JSON parser on the ESP, and I can perfectly communicate with dummy Domoticz devices.
Also, except of you and one very helpful guy within a private chat, noone preplied to MQTT-questions and ESP-stuff. Seems working with ESPs is reluctantly seen here on the forum.?
So I assume a different way then using MySensors for everything except (battery-powered) Arduinos is the best I can do, to also have no problems in the future..@inso
Thanks for the feedback, sorry for your ineffective messin around with mysensors. I completely agree to your conclusion using MQTT directly on more powerfull boards able to communicate directly via WiFi.@inso said in 💬 Building a WiFi Gateway using ESP8266:
Seems working with ESPs is reluctantly seen here on the forum.?
I can only speak for myself :grin: but indeed, I absolutely dislike having (regular) WiFi devices integrated in my home automation. My personal concept is to use as much wires as possible (thus I really love the RS485 stuff here!) and use different RF technologies whereever possible - and connect the corresponding GW's using a USB plug!
So atm I exactly have 2 ESP8266-based devices integrated: One is a bridge for my MiLight stuff (avoid that type of devices, but in case if, use the sidoh-firmware!), one is a IR-Device to play around...
But everybody has to find his own way. Just my personal thoughts on that topic :smirk:
-
I built a ESP8266 (Lolin V3) gw with RFM69 868mhz according to instructions.
I flashed NodeMCU with EspTool without problems. I then uploaded my sketch. It started first OK, but after I set a fixed IP with my router, it will not connect anymore (to router??).Debug:
$l⸮⸮`,ld⸮p :Y⸮56 MCO:BGN:INIT GW,CP=RRNGE---,REL=255,VER=2.3.1 108 TSF:LRT:OK 124 TSM:INIT 137 TSF:WUR:MS=0 157 TSM:INIT:TSP OK scandone state: 0 -> 2 (b0) state: 2 -> 3 (0) state: 3 -> 5 (10) add 0 aid 7 cnt connected with Neptune, channel 11 dhcp client start... 323 TSM:INIT:GW MODE 346 TSM:READY:ID=0,PAR=0,DIS=0 378 MCO:REG:NOT NEEDED 406 TSM:READY:NWD REQ 1840 TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK: scandone 1923 GWT:TPC:CONNECTING... 2452 GWT:TPC:CONNECTING... 2980 GWT:TPC:CONNECTING... 3508 GWT:TPC:CONNECTING... 4036 GWT:TPC:CONNECTING... 4564 GWT:TPC:CONNECTING... 5092 GWT:TPC:CONNECTING... 5620 GWT:TPC:CONNECTING... 6148 GWT:TPC:CONNECTING... 6676 GWT:TPC:CONNECTING... 7204 GWT:TPC:CONNECTING... 7732 GWT:TPC:CONNECTING... 8260 GWT:TPC:CONNECTING... 8788 GWT:TPC:CONNECTING... 9316 GWT:TPC:CONNECTING... 9844 GWT:TPC:CONNECTING... pm open,type:2 0 10372 GWT:TPC:CONNECTING... 10901 GWT:TPC:CONNECTING... 11430 GWT:TPC:CONNECTING... 11959 GWT:TPC:CONNECTING... 12488 GWT:TPC:CONNECTING... 13017 GWT:TPC:CONNECTING...Sketch:
#define MY_DEBUG #define MY_BAUD_RATE 9600 #define MY_RADIO_RFM69 #define MY_RFM69_FREQUENCY RFM69_868MHZ // Set your frequency here #define MY_IS_RFM69HW // Omit if your RFM is not "H" #define MY_RFM69_IRQ_PIN D1 #define MY_RFM69_IRQ_NUM MY_RFM69_IRQ_PIN #define MY_GATEWAY_MQTT_CLIENT #define MY_GATEWAY_ESP8266 #define MY_MQTT_PUBLISH_TOPIC_PREFIX "domoticz/in/mysenRFM69" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "domoticz/out/mysenRFM69" #define MY_MQTT_CLIENT_ID "mysenRFM69" #define MY_MQTT_USER "ZZZZ" #define MY_MQTT_PASSWORD "YYYYYYYY" #define MY_WIFI_SSID "Neptune" #define MY_WIFI_PASSWORD "XXXXXXXXXXXX" #define MY_HOSTNAME "mqtt-ESP8266-gateway" #define MY_CONTROLLER_IP_ADDRESS 192, 168, 1, 51 #define MY_PORT 1883 #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Flash leds on rx/tx/err #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 <MySensors.h> void setup() { // Setup locally attached sensors } void presentation() { // Present locally attached sensors here } void loop() { // Send locally attached sensors data here }Sketch or router problem?
Powered with computer usb + 800mA 5V charger at the moment. -


Hi I just have build this GW. and it is working. But as you can see in the screenshots, I get really strange readings from my sensors. The serial connected GW is working good.
the first screenshot, strange temperature. no idea from where this is coming. second screen shot also strange temperature, and a battery reading.....
I know from which sensors this is coming since the serial GW is also logging them. and these values are simply wrong. any idea what I should change?
thanks
-
Hi there all,
I'm new here and for first think I'll like to thanks a lot for this wonderful MySensorsI just folow step-by-step the guide here: Building a WiFi Gateway using ESP8266
- use all this on a NodeMcu
- I opened the sketch from Arduino Ide from File>Examples>My Sensors> GatewayESP8266
- I edited my WiFi credentials, compiled, and write it on the NodeMcu
- I opened the serial console and watch...
This is what I see on the NodeMcu log:
2216 GWT:TIN:CONNECTING... scandone state: 0 -> 2 (b0) 3982 GWT:TIN:CONNECTING... state: 2 -> 3 (0) state: 3 -> 0 (12) reconnect 5068 GWT:TIN:CONNECTING... 6096 GWT:TIN:CONNECTING... 7124 GWT:TIN:CONNECTING... scandone state: 0 -> 2 (b0) state: 2 -> 3 (0) state: 3 -> 0 (12)This NodeMcu was always connecting on my WiFi LAN.
Someone can help me please ?Thanks in advance
Denis -
I finally understand with was the problem...
My WiFi Mesh LAN accepted only 802.11.g+n radio... now that I have set 802.11.b+g+n it's ok
Strange this think cause an all other WiFi Arduino schetch the 802.11.g+n radio was always accepted.Anyway... now it's work :-)
Denis -
Hi,
I have a small problem: I am using the Gateway Mysensor EPS8266 WIFi.
Everything is correctly working except the leds:in the code mysensor code , there is:
// Flash leds on rx / tx / err
// Led pins used if blinking feature is enabled abovedefine 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 LEDI replaced by:
// Flash leds on rx / tx / err
// Uncomment to override default HW configurations
#define MY_DEFAULT_ERR_LED_PIN 1 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 3 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 4 // the PCB, on board LEDand it does not work: the LEDs are always half-on.
can You tell me if these pins are used for other things and only PIN16 is available for the user ?
Thanks for your help
Gerard
-
Hello,
I have been using MySensors for a long time. First with serial gateway now with ESP8266 gateway. For months everything worked fine except for small dropouts. Due to dropouts I wanted to switch to current development branch, since then I can not get the gateway to work.
The ESP delivers only the following output:ets Jan 8 2013,rst cause:2, boot mode:(3,6) load 0x4010f000, len 3460, room 16 tail 4 chksum 0xcc load 0x3fff20b8, len 40, room 4 tail 4 chksum 0xc9 csum 0xc9 v00051da0 ~ldI use ESP07 with RFM69 and Standard Sketch. Compiled the code with Arduino IDE as well as with VS code, always with the same result.
I disconnected RFM69 and checked the supply voltage. Have even used other calculator.
Have also tested ESP12e.
Erase Flash I have also already done.
However, when I run other code on the ESP, it runs without problems.
Erase Flash I have also already done.
I just don't understand it.#define MY_DEBUG #define MY_BAUD_RATE 115200 #define MY_RADIO_RFM69 #define MY_IS_RFM69HW #define MY_GATEWAY_ESP8266 #define MY_WIFI_SSID "my ssid" #define MY_WIFI_PASSWORD "my pw" #define MY_HOSTNAME "MySensors-GW" #define MY_PORT 5003 #define MY_GATEWAY_MAX_CLIENTS 3 #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 #include <MySensors.h> void setup() { } void presentation() { } void loop() { }