ThingPulse / esp8266-weather-station-color

ESP8266 Weather Station in Color using ILI9341 TFT 240x320 display
https://thingpulse.com/product/esp8266-wifi-color-display-kit-2-4/
MIT License
571 stars 222 forks source link

Program loss on power loss #55

Closed kolasinski closed 6 years ago

kolasinski commented 6 years ago

I'm not sure if this is an "issue" or that I do not understand something.

When uploading code via Arduino IDE, weather station Color works fine, connects to my network and pulls down data, displays great. Works great.

I am only connecting via micro USB - no battery. When I unplug, and replug, unit loses memory and requires re-uploading the program via Arduino IDE.

Do I need to always keep a li-po cell on the unit? Or is there a setting that I just do not see to keep the settings after power down?

Thanks

al-ang commented 6 years ago

Are you saying the device needs to be re-programmed (flashed) every time the device is booted? If so, then there's something very wrong. Also, if that's the case, the help on the Arduino forums might be more helpful.

G6EJD commented 6 years ago

There may be an esp.reset() in the programme leading to loss of WiFi config data that then gets cleared at restart. I haven’t checked the code.

pilnikov commented 6 years ago

Please add 2 lines to your code

So now

void connectWifi() { if (WiFi.status() == WL_CONNECTED) return;

It is necessary to add

void connectWifi() { WiFi.disconnect(); //added WiFi.mode( WIFI_STA ); //added if (WiFi.status() == WL_CONNECTED) return;

G6EJD commented 6 years ago

Agreed

al-ang commented 6 years ago

This is THAT network problem???? Oh my, it strikes again.

The answer you gave above cannot spread fast enough IMHO. I was bitten hard a few weeks ago when long used code stopped working. I thought it was odd the OP needed to re-flash after power loss. Glad you spotted the potential source of the problem.

marcelstoer commented 6 years ago

@pilnikov could you please reference a source that explains why it should be necessary to add those two statements?

Btw, I can't reproduce this problem (using the current master).

marcelstoer commented 6 years ago
WiFi.disconnect(); //added
WiFi.mode( WIFI_STA ); //added
if (WiFi.status() == WL_CONNECTED) return;

How likely is it that the conditional on line 3 ever returns true if you do a WiFi.disconnect() right before...

pilnikov commented 6 years ago

After disconnect we true connect with WiFi.status(). WiFi.disconnect() resets the settings of previous connection.

pilnikov commented 6 years ago

Check your devboard. If you have a capacitor on the ground in the reset chain (reset on power on) - then you can't reproduce this problem.

marcelstoer commented 6 years ago

Still doesn't make sense to me. I know what WiFi.disconnect does and, therefore, the described fix is illogical. After disconnect WiFi.status() will of course return 6 (WL_DISCONNECTED). Hence, the conditional will always evaluate to false.

Check your devboard.

No devboard here. I'm testing against our ThingPulse reference hardware.

@G6EJD & @al-ang you both seem to be in favor of the proposed fix. Why would you want to explicitly disconnect from the AP every time first? Known issue with the SDK I'm not aware of? Furthermore, how would that be related to the OP's issues which is described as "When I unplug, and replug, unit loses memory"?

G6EJD commented 6 years ago

Marcel, your correct. What I was responding to (I thought) was reference to a problem I’ve seen many times when the ESP8266 comes out of sleep and fails to reconnect the WiFi but adding the WiFi.disconnect and WiFi.mode(WiFi _sta) does then result in reliable reconnection. I’m using the Arduino IDE and this may well be a facet of the IDE.

I think @kolasinski may well have misconstrued a connection problem or some other problem with a credentials memory clearing event but never got round to checking for an esp.reset() in the code. Also it’s been a long time since he reported the issue.

pilnikov commented 6 years ago

I also agree with @G6EJD, @kolasinski may well have misconstrued, the ESP may "fall into a stupor" (WiFi part), return it only WiFi.disconnect().

pilnikov commented 6 years ago

https://github.com/esp8266/Arduino/issues/2174