ThingerSmartConfig breaks deep sleep on esp8266


I think I’m getting close to making things work with SmartConfig and Thinger. For deep sleep functionality, one must connect the RST and D0 pins on the chip. However, on many dev boards they chose to wire the BUILTIN_LED to the D0 as well. Just check for yourself, the pins_arduino.h for multiple variants:

Anyway, this causes all kinds of crazy crashes because attempting to write to D0 triggers resets and zombie state on recovery.

I suggest we have a way to have a way of disabling these (there’s another few lines down). Wouldn’t want to completely remove it, as it seems to be useful outside of a deep sleep context.

Help me understand the client library approach/idioms and I’ll send the PR :slight_smile: I’d like to do better than a top-level #define

Never tested the deep sleep feature of ESP8266, but you must take into account that thinger will be sending a keep alive every 1 minute to ensure the device is connected. It is not a problem however for the client if the device is sleeping 10 minutes, and then waking up to stream a value, or call an endpoint. This should be working.

For the deep sleep feature and the smartconfig, I think it is possible to add a default parameter in the constructor after device credential initialized to true, so it can control when to use the BUILTIN_LED to notify the SmartConfig process.

Something like:

ThingerSmartConfig(const char* user, const char* device, const char* device_credential, bool use_led=true) :
        ThingerClient(client_, user, device, device_credential), led_(use_led)
        pinMode(BUILTIN_LED, OUTPUT);

It is necessary to add the led_ attribute, and take care of it in other places where the BUILTIN_LED is used. I can modify this tonight, but if you want you can try it in the meantime :slightly_smiling:

I’ll strike a deal with you :slight_smile: You update the codebase and I will add a doc section on deep sleep referencing the code. Need to take care of a number of things today before I can get back to coding.

Done! I will work on that!. I would like to see your NodeMCU setup for deep sleep (hardware connections), so I can test it also. I thought it was necessary to jump a 0R resistor in the board to get the GPIO16, but maybe I am missing something…

Zero-resistor is a direct wire connection. Those electrical engineers and their fancy terms, he he :smiley:

I’ve documented things for others here . Not my most proudest piece of c++, but hey! Check out the next iteration of the template too.

I have the SmartConfig working in that template fine on esp8266, but of course it can be packaged and refactored better (e.g. using that other WiFiConnector library).

Let me know if it works now with the new header version :slightly_smiling:

ThingerSmartConfig thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL, false);

Works with the latest code, I’ll send through a doc update PR later today, hopefully.