ESP8266 SmartConfig causes WDT soft resets and stacktraces

Hi,

I’m trying to bring a simple use case into the Thinger.io, but the below code crashes the esp8266 dev boards (I’ve confirmed both with NodeMCU and WeMos boards, similar crash).

There’s nothing special about the setup, the vanilla one connected to a mac’s usb. Using the latest Arduino client libs from the github.

Can’t seem to enable the Thinger.io debug output either, it simply doesn’t get to a point where it can run. Anything I’m missing?

//#include <SPI.h>
#include <ESP8266WiFi.h>
#include <Arduino.h>
#include <ESP.h>

#include <ThingerSmartConfig.h>

#define _DEBUG_

// TODO extract into an external config
#define USERNAME "andrew"
#define DEVICE_ID "some_device_id"
#define DEVICE_CREDENTIAL "xxxxx"

#define INTERVAL_MS 10000
#define SENSOR_PIN A0 // analog pin
#define VAL_LOW_LIMIT 446   // based on sensor calibration results
#define VAL_HIGH_LIMIT 830  // based on sensor calibration results

ThingerSmartConfig thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
  Serial.begin(115200);
  pinMode(SENSOR_PIN, INPUT);

  thing["soil"] >> [] (pson& out) {
    int value = analogRead(SENSOR_PIN);
    int conValue = constrain(value, VAL_LOW_LIMIT, VAL_HIGH_LIMIT);
    int mapped = map(conValue, VAL_LOW_LIMIT, VAL_HIGH_LIMIT, 100, 0);
    Serial.print("Reading raw: ");
    Serial.println(value);
    Serial.print("Reading: ");
    Serial.println(mapped);

    out = mapped;
  };
}

void loop() {
  thing.handle();
//  ESP.deepSleep(INTERVAL_MS * 1000);
}

Stacktrace:

Soft WDT reset

ctx: cont
sp: 3fff0140 end: 3fff0380 offset: 01b0

>>>stack>>>
3fff02f0:  3fff0868 40202ab4 3fff0542 402018d4
3fff0300:  3fff1490 000000cb 3fff0542 402036d2
3fff0310:  3fff14b0 0000000f 00000000 3fff1490
3fff0320:  0000000f 00000000 00000001 40203644
3fff0330:  0000001c 3fff1318 3ffef318 3ffef34c
3fff0340:  3fffdc20 00000000 3ffeec88 4020482a
3fff0350:  3fffdc20 00000000 3ffeec88 40204ad3
3fff0360:  3fffdc20 00000000 3ffef345 402018a9
3fff0370:  00000000 00000000 3ffef360 40202930
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld

Hi! Do you have the same problem with the default example? In the NodeMCU, the BUILTIN_LED should blink while waiting smart configuration.

If you want to enable DEBUG, you must define it before adding ThingerSmartConfg.h. So add the define in first line.

Let me know if you get it working!

Thanks for the tip, Alvaro! Once I moved the _DEBUG_ definition to the top, I got the output, and, surprisingly, everything went through to connect both to WiFi and the service. Go figure, but I’m glad we have a simple solution. Maybe worth mentioning it in the docs for others?

Great! It was an easy fix then! I have merged your contribution in the Arduino docs. It is worth to mention that! Thanks for the contribution! :wink:

Hmm, sorry to revive it. I took a clean board (which didn’t have old WiFi info saved). It does look like Thinger’s SmartConfig code needs to ESP.wdtFeed()

Take a look at the output below. The reset cause 2 is a watchdog timer reset. Might take a look at the Thinger library code later, but for now wanted to flag this. The reason it worked above was only due to me doing a regular wifi sketch, then SmartConfig (it reused saved WiFi credentials). Doesn’t work on a clean board.

Tip: to erase WiFi credentials take a look at how I’m doing it here: https://github.com/aperepel/iot-esp8266-starter/blob/master/src/main.ino#L194

Connect the jumper
[NETWORK] Starting connection...
[NETWORK] Starting Smart Config...
Soft WDT reset

ctx: cont
sp: 3fff0290 end: 3fff0500 offset: 01b0

>>>stack>>>
3fff0440:  3fff09e8 40202b40 3fff06c2 40201960
3fff0450:  00001462 3ffef40c 3fff06c2 40203966
3fff0460:  3fff1650 0000000f 00000000 3fff1630
3fff0470:  0000000f 00000000 3ffef40c 40222fa0
3fff0480:  3ffef40c 3ffeed78 3ffef40c 40222fc1
3fff0490:  3fff0550 3ffeed78 3ffef40c 3ffeed78
3fff04a0:  3ffef40c 3ffe84e5 3ffeed78 402049de
3fff04b0:  3fff15e0 3ffe84e5 3ffeed78 40204c8b
3fff04c0:  3ffef40c 3ffe84e5 3fff15f8 40204db4
3fff04d0:  00000000 00000000 00000000 3ffef4d0
3fff04e0:  3fffdc20 00000000 3ffef4c9 4020192a
3fff04f0:  00000000 00000000 3ffef4e0 402029bc
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld

Ok! thanks for the report. I will take a look to see what happens!

Well, I think I have some good news for this. I have been working to disable the blinking led for SmartConfig. Now you can pass another parameter to false to disable the BUILTIN_LED. Like this:

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

But you can still define the instance as always if you want to use the BUILTIN_LED:

ThingerSmartConfig thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

I have been testing also the SmartConfig method under different cases, like the device does not have a WiFi connection established yet (thanks for the Wifi.disconnect() tip!! :smiley: ), or the SmartConfig configuration is bad, and so on. Now all seems to be working like a charm!. Also I have improved the debug information for the SmartConfig.

You can try the fix replacing ThingerSmartConfig.h header, meanwhile I upload it as a new version for the Arduino Library Manager:

Will work now on the disconnect method, and will test the sleep feature to see how it affects to the client library.

Cool, I will have a chance to test an updated version tomorrow and let you know. Thanks for a quick turnaround.

Thank you for your reports! Now I am testing the deep sleep… It is working with the SmartConfig, so I will check the disconnect feature…

Hey, Alvaro, had a chance to test, works nicely with and without SmartConfig now that we can disable the LED.

Perfect! Thanks for the info! :slight_smile:

Hi, this because the power supply isn’t GOOD. Please prepare another one.
You can visit here to know instruction to make an example for ESP12E
http://engineer2you.blogspot.com/2017/05/esp12e-arduino-programming.html