Skip to content

Fix for ESP8266 Gateway with static IP #1101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

tobof
Copy link

@tobof tobof commented Apr 2, 2018

According to this: esp8266/Arduino#128

Wifi.config() needs to be called after Wifi.begin().
Otherwise the static IP issn't used by the ESP8266 gateway.

@mfalkvidd
Copy link
Member

Thanks for reporting this @tobof
Would you mind updating https://github.com/mysensors/MySensors/blob/development/core/MyGatewayTransportMQTTClient.cpp#L154 as well? You can just amend your current commit and force-push it.

According to this: esp8266/Arduino#128

Wifi.config() needs to be called after Wifi.begin().
Otherwise the static IP issn't used by the ESP8266 gateway.
@tobof tobof force-pushed the ESP8266_static_ip_fix branch from 6ac57ad to ab57f29 Compare April 3, 2018 06:14
@tobof
Copy link
Author

tobof commented Apr 3, 2018

Good idea @mfalkvidd !
Done!
I've tested my changes to the ESP8266 gateway. The changes to ESP8266 MQTT gateway are not tested.

@mfalkvidd
Copy link
Member

I can probably test a mqtt gateway some time this week. I am not sure the fix you did will work though, there is a begin call here: https://github.com/mysensors/MySensors/pull/1101/files#diff-d700e8d31fad8e7369cc0cdab2d76fa3R158

@tobof
Copy link
Author

tobof commented Apr 3, 2018

Yes, but the Wifi.config() is part of gatewayTransportConnect() which is called after Wifi.begin(): https://github.com/mysensors/MySensors/pull/1101/files#diff-d700e8d31fad8e7369cc0cdab2d76fa3R161

@mfalkvidd
Copy link
Member

Ah. Stupid me :) I'll set up a mqtt gw and verify.

@mfalkvidd
Copy link
Member

mfalkvidd commented Apr 4, 2018

TL;DR: this fix breaks static IP on mqtt gw.

I am not able to reproduce the problem using ESP8266 board version 2.4.0

4582 MCO:BGN:INIT GW,CP=R-NGE---,VER=2.2.1-alpha
STUB: dhcp_stop
scandone
5245 GWT:TPC:CONNECTING...
wifi evt: 2
5747 GWT:TPC:CONNECTING...
6249 GWT:TPC:CONNECTING...
6751 GWT:TPC:CONNECTING...
scandone
state: 0 -> 2 (b0)
7825 GWT:TPC:CONNECTING...
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 5
cnt 

connected with Mr-IoT.com, channel 6
ip:192.168.1.187,mask:255.255.255.0,gw:192.168.1.1
ip:192.168.1.187,mask:255.255.255.0,gw:192.168.1.1
wifi evt: 0
wifi evt: 3
8333 GWT:TPC:CONNECTING...
8335 GWT:TPC:IP=192.168.1.187
8338 MCO:BGN:STP
8339 MCO:REG:NOT NEEDED
8342 MCO:BGN:INIT OK,TSP=NA
8344 GWT:TPC:IP=192.168.1.187
8347 GWT:RMQ:MQTT RECONNECT
8364 GWT:RMQ:MQTT CONNECTED
8367 GWT:TPS:TOPIC=mygateway1-out/0/255/0/0/17,MSG SENT

(reset the device)

connected with Mr-IoT.com, channel 6
ip:192.168.1.187,mask:255.255.255.0,gw:192.168.1.1
ip:192.168.1.187,mask:255.255.255.0,gw:192.168.1.1
wifi evt: 0
wifi evt: 3
567 GWT:TPC:CONNECTING...
569 GWT:TPC:IP=192.168.1.187
572 MCO:BGN:STP
573 MCO:REG:NOT NEEDED
575 MCO:BGN:INIT OK,TSP=NA
578 GWT:TPC:IP=192.168.1.187
580 GWT:RMQ:MQTT RECONNECT
601 GWT:RMQ:MQTT CONNECTED
604 GWT:TPS:TOPIC=mygateway1-out/0/255/0/0/17,MSG SENT

(change IP address)

4569 MCO:BGN:INIT GW,CP=R-NGE---,VER=2.2.1-alpha
wifi evt: 2
STUB: dhcp_stop
scandone
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 4
cnt 

connected with Mr-IoT.com, channel 6
ip:192.168.1.188,mask:255.255.255.0,gw:192.168.1.1
ip:192.168.1.188,mask:255.255.255.0,gw:192.168.1.1
wifi evt: 0
wifi evt: 3
5078 GWT:TPC:CONNECTING...
5080 GWT:TPC:IP=192.168.1.188
5083 MCO:BGN:STP
5084 MCO:REG:NOT NEEDED
5087 MCO:BGN:INIT OK,TSP=NA
5089 GWT:TPC:IP=192.168.1.188
5092 GWT:RMQ:MQTT RECONNECT
5111 GWT:RMQ:MQTT CONNECTED
5114 GWT:TPS:TOPIC=mygateway1-out/0/255/0/0/17,MSG SENT

Updated to ESP8266 board version 2.4.1 (latest version at the moment)

SDK:2.2.1(cfd48f3)/Core:2.4.1/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1)
4583 MCO:BGN:INIT GW,CP=R-NGE---,VER=2.2.1-alpha
wifi evt: 2
STUB: dhcp_stop
scandone
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 4
cnt 

connected with Mr-IoT.com, channel 6
ip:192.168.1.189,mask:255.255.255.0,gw:192.168.1.1
ip:192.168.1.189,mask:255.255.255.0,gw:192.168.1.1
wifi evt: 0
wifi evt: 3
5099 GWT:TPC:CONNECTING...
5101 GWT:TPC:IP=192.168.1.189
5104 MCO:BGN:STP
5106 MCO:REG:NOT NEEDED
5108 MCO:BGN:INIT OK,TSP=NA
5110 GWT:TPC:IP=192.168.1.189
5113 GWT:RMQ:MQTT RECONNECT
5129 GWT:RMQ:MQTT CONNECTED
5132 GWT:TPS:TOPIC=mygateway1-out/0/255/0/0/17,MSG SENT

change IP address and upload:

SDK:2.2.1(cfd48f3)/Core:2.4.1/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1)
4597 MCO:BGN:INIT GW,CP=R-NGE---,VER=2.2.1-alpha
wifi evt: 2
STUB: dhcp_stop
scandone
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 4
cnt 

connected with Mr-IoT.com, channel 6
ip:192.168.1.190,mask:255.255.255.0,gw:192.168.1.1
ip:192.168.1.190,mask:255.255.255.0,gw:192.168.1.1
wifi evt: 0
wifi evt: 3
5113 GWT:TPC:CONNECTING...
5115 GWT:TPC:IP=192.168.1.190
5118 MCO:BGN:STP
5120 MCO:REG:NOT NEEDED
5122 MCO:BGN:INIT OK,TSP=NA
5124 GWT:TPC:IP=192.168.1.190
5127 GWT:RMQ:MQTT RECONNECT
5146 GWT:RMQ:MQTT CONNECTED
5149 GWT:TPS:TOPIC=mygateway1-out/0/255/0/0/17,MSG SENT
pm open,type:2 0

But when using tobof/ESP8266_static_ip_fix the static IP address configuration is ignored:

SDK:2.2.1(cfd48f3)/Core:2.4.1/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1)
4614 MCO:BGN:INIT GW,CP=R-NGE---,VER=2.3.0-alpha
wifi evt: 2
scandone
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 4
cnt 

connected with Mr-IoT.com, channel 6
dhcp client start...
wifi evt: 0
5130 GWT:TPC:CONNECTING...
5632 GWT:TPC:CONNECTING...
6134 GWT:TPC:CONNECTING...
6636 GWT:TPC:CONNECTING...
7138 GWT:TPC:CONNECTING...
7640 GWT:TPC:CONNECTING...
ip:192.168.1.146,mask:255.255.255.0,gw:192.168.1.1
wifi evt: 3
8142 GWT:TPC:CONNECTING...
8144 GWT:TPC:IP=192.168.1.146
8147 MCO:BGN:STP
8148 MCO:REG:NOT NEEDED
8151 MCO:BGN:INIT OK,TSP=NA
8153 GWT:TPC:IP=192.168.1.146
8156 GWT:RMQ:MQTT RECONNECT
8169 GWT:RMQ:MQTT CONNECTED
8172 GWT:TPS:TOPIC=mygateway1-out/0/255/0/0/17,MSG SENT
pm open,type:2 0

I used the GatewayESP8266MQTTClient sketch with these defines:

#define MY_IP_ADDRESS 192,168,1,191
#define MY_IP_GATEWAY_ADDRESS 192,168,1,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 1, 101

and #define MY_RADIO_NRF24 commented so no radio was active.

So this fix seems no good for MQTT :(

@tobof
Copy link
Author

tobof commented Apr 6, 2018

Thanks for testing @mfalkvidd !
There was something amiss with the defines.

After doing some testing I'm no longer able to reproduce the initial problem, so I'll close the PR for now and wait for the problem to come up again. :-)

@tobof tobof closed this Apr 6, 2018
@mfalkvidd
Copy link
Member

Strange. Thanks for checking. If the problem happens again just reopen this issue.
Have a nice weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants