Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By Frogmore
#22499 First, thanks to all the people who have worked on this project. It is really amazing what has been accomplished. The ESP8266 is a very cool part at a very affordable price and being able to use much of the Arduino code makes it much easier to get stuff done.

Having said that, I have discovered there are a lot of things that can make it not work. I am currently using an ESP-12 (that I got from Seeedstudio via Amazon. It took me awhile to figure out all of the HW mods I needed to make it work (pull up and pull down resistors, as specified in making it reliable). I believe that is as it should be with:
Pull up: CH_PD, Reset, GPIO_0
Pull down: GPIO_15

That has helped tremendously. However, this morning it stopped updating the web. The serial output has stopped and I noticed that the esp8266 is now in AP mode and not station mode. AP mode is working, in that I can get an IP address and ping the esp8266, but it doesn't serve up a web page. My code doesn't set up AP mode, it does station mode:
Code: Select allvoid setup() {
    Serial.begin(115200);
    gasMeter.init();
    display.init();
    display.setCursor(0, 0);
    display.print("Connecting to");
    display.setCursor(1, 0);
    display.print(ssid);
    WiFi.begin(ssid, password);
    display.setCursor(2, 0);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        display.print(".");
    }
    display.setCursor(3, 0);
    display.print("WiFi connected:");
    display.setCursor(4, 0);
    display.print(WiFi.localIP());
    delay(5000);
}


The code that uses the WiFi client looks like this:

Code: Select all        int HttpClient::PostOrPut(WiFiClient client, const char* server, String Uri, boolean isPost, String Headers, String PostData) {
            boolean connected;
            int counter = 0;
            int retries = 0;
            int badUpdate = 0;
            do {
                connected = client.connect(server, 80);
                if (connected) { break; }
                client.stop();
                Alarm.delay(1000);
                Serial.println("retry");
                retries++;
                counter++;
            } while (!connected && counter <5);
            if (connected) {
                if (isPost){
                    Serial.println("POST");
                    Serial.print("POST " + Uri + " HTTP/1.1\n");
                    client.print("POST " + Uri + " HTTP/1.1\n");
                }
                else {
                    Serial.println("PUT");
                    Serial.print("PUT " + Uri + " HTTP/1.1\n");
                    client.print("PUT " + Uri + " HTTP/1.1\n");
                }
                client.print("Host: ");
                client.print(server);
                client.print("\n");
                client.print("Connection: close\n");
                client.print(Headers);
                client.print("Content-Length: ");
                client.print(PostData.length());
                client.print("\n\n");
                client.print(PostData);

                Serial.print("Host: ");
                Serial.print(server);
                Serial.print("\n");
                Serial.print("Connection: close\n");
                Serial.print(Headers);
                Serial.print("Content-Length: ");
                Serial.print(PostData.length());
                Serial.print("\n\n");
                Serial.print(PostData);

                int c = '\0';
                unsigned long startTime = millis();
                unsigned long httpResponseTimeOut = 10000; // 10 sec
                while (client.connected() && ((millis() - startTime) < httpResponseTimeOut)) {
                    if (client.available()) {
                        c = client.read();
                        Serial.print((char)c);
                    }
                    else {
                        Serial.print(".");
                        Alarm.delay(100);
                    }
                }

            }
            else {
                badUpdate++;
                Serial.println("bad Update");
            }
            client.stop();
            if (badUpdate > 0) {
                return -retries;
            }
            else {
                return retries;
            }
        }


Yes, it uses a lot of String manipulation. Yes, I have checked the heap usage. In fact, I graph that (along with the number of successful iterations it has made). All of this is working and it has long periods of consistent heap utilization (12 hours or more). It is interesting that there appears to be a leak, but it is not consistent and sometimes it is recovered. You can see the heap utilization here: https://smartenergygroups.com/groups/frogmore

But, I have never been able to get the esp8266 to stay working for more than a few days. It has what seems like a lot of remaining heap (28KBytes). I have not updated the esp8266 library in a few weeks, but I didn't see any changes that seemed related to this issue.

Any ideas?
User avatar
By Pigs Fly
#23355 No, they're pretty flaky. I'm running around a dozen client-mode modules deployed with various firmware, mostly Arduino and Lua and they all quit after random periods. Poke fun at it if you want, but all my new ESP-only deployments have a TLC555 doing a hard reset every 5 minutes to keep them alive. Others are running as slaves on those mini Arduino-pro modules. The Arduino uses the ESP only for WiFi comms, resetting the ESP with the Arduino module before accessing.

Without the hard resets they may go hours or weeks, but they always stop working eventually. ESP-07 and -12 from multiple vendors.

I've done all I can to read on the "zombie" mode issues but nothing I've tried fixes the problem. Rebooting in the code doesn't work, and every variation of power supply, firmware versions, pull-ups, pull-downs, etc. that you can imagine got me nowhere. Nothing but tugging on that reset line will keep them running reliably in my experience.
User avatar
By kenn
#23357 I've got some simple HTTP client implementations firing out a temperature reading every 30 sec, and with a health counter, and so far it's run for as long as 10 days without failing (and then I used it to do something else).

Idea: The deep-sleep mode with the indicated mod actually tugs on the reset line, so if you call for a deep sleep every X minutes or Y requests or whatever, it will hit reset for you.
Last edited by kenn on Wed Jul 15, 2015 3:17 pm, edited 1 time in total.
User avatar
By kolban
#23358 At the ESP8266 SDK level there is an event callback capability where one registers a callback function that gets invoked when an interesting events happens. I'd be interested to see what would happen if we registered a callback which just logged to the UART1 serial whenever an event is detected and the type and content of that event.

I'd also suggest a periodic timer (maybe as quick as every second) that logs the current heap size.

When diagnosing these kinds of problems, it is useful to gather as many clues as possible. It is not that the evidence by itself will point to the immediate answer ... but if, for example, the device issues a message that the connection to the access point was lost just before stalling or that the available free heap size was continually decreasing, then those would be good clues.