Tag Archives: ESP8266 and loss of WIFI

ESP8266 MQTT and LOSS OF WIFI

Update at 13:22:00 on 02/02/2015
This morning I had an email to say the WIFI loss was fixed in the MQTT code. I downloaded the latest MQTT software and put my code back into it. I turned the WIFI off for a few seconds then back on – that worked, sending out the message backlog and re-subscribing to messages. I then turned the WIFI off until the 2K queue buffer was full – that I guess is the ultimate test.  That took several minutes. I turned the WIFI back on and…no. BUT we understand what’s wrong. The queue is full – and hence there is no room to re-subscribe. This is now fixed here https://github.com/tuanpmt/esp_mqtt. Everything seems to operate perfectly. That is important for a number of reasons as it suggests that there is nothing wrong with the SDK.

Original blog:

This  is getting to a be a problem.  I don’t know if it is the MQTT software or ESPRESSIFs SDK but there is an issue if you lose WIFI connection.  I tested this on the road the week but now I’m back in the office I’m doing it a bit more scientifically.

So – I know that the WIFI here is perfect.  I also know that the SDK is case sensitive so in order to simulate loss of signal it’s simply a matter of renaming the “office” WIFI to something else or just change case (my computer is hardwired) to test.

Here’s the result of this mornings test.

So what we have is an ESP-01 – I’m using the latest SDK (0.9.5) on a PC using Eclipse and using Tuan’s MQTT software as a base (NOT the LUA version – so I’m programming in C).  The basic MQTT software has a number of subscriptions… including the time.  A separate system updates the time every minute (Linux timestamp – seconds since 1974).  The board has a temperature sensor which on a timer sends out the temperature every 5 seconds (using code that does not involve long delays).

Here is the log.. “in the beginning” the router has the WRONG name so that the board cannot see the WIFI.. It sits in a loop waiting….

 

no office found, reconnect after 1s
STATION_IDLE
STATION_IDLE
reconnect
STATION_IDLE
STATION_IDLE
STATION_IDLE
STATION_IDLE
scandone
STATION_IDLE
add 0
aid 1
pm open phy_2,type:2 0 0
cnt
STATION_IDLE

 

At this point I turn on the WIFI – and all is well, it is picked up – the board starts up and subscribes to the various topics.

After about a minute, it gets the time – and now starts transmitting the temperature (the sensor isn’t hooked up so it’s just sending dummy info)

 

connected with office, channel 13
dhcp client start...
STATION_IDLE
STATION_IDLE
ip:192.168.0.9,mask:255.255.255.0,gw:192.168.0.138
TCP: Connect to domain home.scargill.org:1884
DNS: found ip 109.170.132.114
TCP: connecting...
MQTT: Connected to broker home.scargill.org:1884
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: data received 4 bytes
MQTT: Connected to home.scargill.org:1884
MQTT: Connected
MQTT: queue subscribe, topic"output", id: 1
MQTT: queue subscribe, topic"mytime", id: 2
MQTT: queue subscribe, topic"time", id: 3
MQTT: queue subscribe, topic"dusk", id: 4
MQTT: queue subscribe, topic"dawn", id: 5
MQTT: queue subscribe, topic"peak", id: 6
MQTT: queue subscribe, topic"off_peak", id: 7
MQTT: queue subscribe, topic"frost", id: 8
MQTT: queue subscribe, topic"on_1", id: 9
MQTT: queue subscribe, topic"off_1", id: 10
MQTT: queue subscribe, topic"on_2", id: 11
MQTT: queue subscribe, topic"off_2", id: 12
MQTT: queue subscribe, topic"timestring", id: 13
MQTT: Sending, type: 8, id: 0001
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 0002
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 0003
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 0004
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 0005
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 0006
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 0007
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 0008
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 0009
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 000A
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 000B
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 000C
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 000D
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
TCP: data received 18 bytes
MQTT topic: time, data: {1422703981}
TCP: data received 62 bytes
MQTT topic: timestring, data: {11:33 Saturday 31-01-2015}
Get another published message
TCP: data received 23 bytes
MQTT topic: dawn, data: {439}
Get another published message
TCP: data received 12 bytes
MQTT topic: dusk, data: {1042}
MQTT: queuing publish, length: 17, queue size(0/2048)
MQTT: Sending, type: 3, id: 0000
TCP: Sent
MQTT: Published
MQTT: queuing publish, length: 17, queue size(0/2048)
MQTT: Sending, type: 3, id: 0000
TCP: Sent
MQTT: Published
TCP: data received 13 bytes
MQTT topic: mytime, data: {400}
MQTT: queuing publish, length: 66, queue size(0/2048)
Time: 11:33:09 31/01/2015 Dawn=439 Dusk=1042 Tick=86392MQTT: Sending, type: 3, id: 0000
TCP: Sent
MQTT: Published
MQTT: queuing publish, length: 17, queue size(0/2048)
MQTT: Sending, type: 3, id: 0000
TCP: Sent
MQTT: Published
MQTT: queuing publish, length: 17, queue size(0/2048)
MQTT: Sending, type: 3, id: 0000
TCP: Sent

 

As you can see above – the unit is sending out temperature and the outgoing queue is not building up – all is well. So now I disconnect the WIFI.

 

rm match
pm close 7 0 0/96959550
TCP: Reconnect to home.scargill.org:1884
reconnect
STATION_IDLE
scandone
no office found, reconnect after 1s
STATION_IDLE
STATION_IDLE
scandone
STATION_IDLE
STATION_IDLE
STATION_IDLE
STATION_IDLE
scandone
add 0
aid 1
pm open phy_2,type:2 0 0
cnt
STATION_IDLE

 

And that sits in the loop waiting for a reconnect.. NOW I reconnect (by renaming) the WIFI

 

connected with office, channel 13
dhcp client start...
MQTT: queuing publish, length: 17, queue size(57/2048)
STATION_IDLE
STATION_IDLE
STATION_IDLE
DNS: Found, but got no ip, try to reconnect
STATION_IDLE
STATION_IDLE
STATION_IDLE
ip:192.168.0.9,mask:255.255.255.0,gw:192.168.0.138
TCP: Connect to domain home.scargill.org:1884
DNS: found ip 109.170.132.114
TCP: connecting...
MQTT: queuing publish, length: 17, queue size(76/2048)
TCP: Reconnect to home.scargill.org:1884
TCP: Connect to domain home.scargill.org:1884
TCP:Reconect to: home.scargill.org:1884
DNS: found ip 109.170.132.114
TCP: connecting...
MQTT: queuing publish, length: 17, queue size(95/2048)
TCP: Reconnect to home.scargill.org:1884
MQTT: queuing publish, length: 17, queue size(114/2048)
TCP: Connect to domain home.scargill.org:1884
TCP:Reconect to: home.scargill.org:1884
DNS: found ip 109.170.132.114
TCP: connecting...
TCP: Reconnect to home.scargill.org:1884
MQTT: queuing publish, length: 17, queue size(133/2048)
TCP: Connect to domain home.scargill.org:1884
TCP:Reconect to: home.scargill.org:1884
DNS: found ip 109.170.132.114
TCP: connecting...
TCP: Reconnect to home.scargill.org:1884
MQTT: queuing publish, length: 17, queue size(152/2048)
TCP: Connect to domain home.scargill.org:1884
TCP:Reconect to: home.scargill.org:1884
DNS: found ip 109.170.132.114
TCP: connecting...
MQTT: queuing publish, length: 17, queue size(171/2048)
TCP: Reconnect to home.scargill.org:1884
MQTT: queuing publish, length: 17, queue size(190/2048)
TCP: Connect to domain home.scargill.org:1884
TCP:Reconect to: home.scargill.org:1884
DNS: found ip 109.170.132.114
TCP: connecting...
TCP: Reconnect to home.scargill.org:1884
MQTT: queuing publish, length: 17, queue size(209/2048)
TCP: Connect to domain home.scargill.org:1884
TCP:Reconect to: home.scargill.org:1884
DNS: found ip 109.170.132.114
TCP: connecting...
TCP: Reconnect to home.scargill.org:1884
MQTT: queuing publish, length: 17, queue size(228/2048)

 

Note the problem – it is connected – or so it says – but the queue is still building up – as if it is unable to send anything out.

And that, right now renders the code useless as there will always be problems with WIFI.   If anyone has any ideas do let me know – this has to apply to other setups to one extent or another. According to Espressif they have solved some issues with reconnects in the latest SDK – well, I’ve overwritten the old one and recompiled so unless I’m missing some trick in the compile process I’m definitely using the latest SDK.

Facebooktwittergoogle_pluspinterestlinkedin