0

As a learning effort, I am trying some sample code on my WEMOS D1, which is basically an Arduino compatible board with a built-in ESP8266 (Wi-Fi module).

This is the output of my Serial Monitor:

1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld
Initializing Wifi...
Start printMacAddress
 ets Jan  8 2013,rst cause:4, boot mode:(1,4)

wdt reset

It stops there and I see no more messages. Below is the code I am trying (from https://www.arduino.cc/en/Guide/ArduinoWiFiShield):

#include <SPI.h>    
#include <WiFi.h>    

void setup() {    
  // initialize serial and wait for the port to open:    
  Serial.begin(115200);    
  // attempt to connect using WEP encryption:    
  while(!Serial) ;    
    Serial.println("Initializing Wifi...");    
    printMacAddress();    
    // scan for existing networks:    
    Serial.println("Scanning available networks...");    
    listNetworks();    
}    

void loop() {    
  delay(10000);    
  // scan for existing networks:    
  Serial.println("Scanning available networks...");    
  listNetworks();    
}    

void printMacAddress() {    
  Serial.print("Start printMacAddress");    
  // the MAC address of your Wifi shield    
  byte mac[6];                        
  // print your MAC address:    
  WiFi.macAddress(mac);    
  Serial.print("MAC: ");    
  Serial.print(mac[5],HEX);    
  Serial.print(":");    
  Serial.print(mac[4],HEX);    
  Serial.print(":");    
  Serial.print(mac[3],HEX);    
  Serial.print(":");    
  Serial.print(mac[2],HEX);    
  Serial.print(":");    
  Serial.print(mac[1],HEX);    
  Serial.print(":");    
  Serial.println(mac[0],HEX);    
}    

void listNetworks() {    
  // scan for nearby networks:    
  Serial.println("** Scan Networks **");    
  byte numSsid = WiFi.scanNetworks();    
  // print the list of networks seen:    
  Serial.print("number of available networks:");    
  Serial.println(numSsid);    
  // print the network number and name for each network found:    
  for (int thisNet = 0; thisNet<numSsid; thisNet++) {    
    Serial.print(thisNet);    
    Serial.print(") ");    
    Serial.print(WiFi.SSID(thisNet));    
    Serial.print("\tSignal: ");    
    Serial.print(WiFi.RSSI(thisNet));    
    Serial.print(" dBm");    
    Serial.print("\tEncryption: ");    
    Serial.println(WiFi.encryptionType(thisNet));    
  }    
}

I am not a hundred percent sure, but I think this started happening when I connected D8 (Digital Pin 8) to a relay. I later read that it has a specific use (to flash firmware I think). The error message appears to point to something called a "WatchDog Timer", but I am not even sure what to eat that with. :-)

There are no error messages in the IDE and it even uploads fine. So why is this happening and how do I fix it?

TIA!

  • Can you disable the code for setting the relay pin as an output? I once got watchdog reset for setting reserved pins as an output. Which prins are reserved, can differ per board. – Paul Dec 5 '16 at 7:11
  • 1
    There is no such code in the above. This happened in another program and I thought I may have munged the board. – Chiwda Dec 5 '16 at 15:54
  • Ah okay, I was unsure if you left out that piece of code, since it was described in the text, but not in the code. Given that it still uploads, I think it's unlikely you broke something, since, I assume, the uploading should break if you break the bootloader pins. – Paul Dec 5 '16 at 16:38
  • WEMOS D1 is not an Arduino board. It's a NodeMCU clone. – dda Feb 3 '17 at 3:59
  • @dda You're right, I meant an Arduino "compatible" WEMOS D1. Turns out it is not even a WEMOS but a clone made by Qunqi. :-) – Chiwda Feb 3 '17 at 4:46
1

If Watchdog timer is the cause of reset that means there is at least one place in your code that runs too long without allowing subsystems to do the background tasks. It might be possible the part of your code causing the problem is:

while(!Serial) ;

Instead that loop use:

while(!Serial)
  delay(100);

so the background tasks will get the chance to be exectuted during the while loop.

EDIT:
In fact you can completely remove that while loop as it is not necessary. There is a possibility !Serial is always true so the loop never ends. And I suggest you using 74880 instead of 115200 so you can see the debug messages sent automatically by ESP8266.
END OF EDIT

However, if that is not the part of the code that causes the problem (and I think it is not) then the problem might be for loop where you list networks. You can check if that is the problem by adding a small delay inside the loop as follows:

for (int thisNet = 0; thisNet<numSsid; thisNet++) {
  delay(1);    
  Serial.print(thisNet);    
  Serial.print(") ");    
  Serial.print(WiFi.SSID(thisNet));    
  Serial.print("\tSignal: ");    
  Serial.print(WiFi.RSSI(thisNet));    
  Serial.print(" dBm");    
  Serial.print("\tEncryption: ");    
  Serial.println(WiFi.encryptionType(thisNet));    
}

If the problem will still exist then you can add a few more delay(1); statements through the code.

Instead of delay you may use yield(); which is the same as delay(0);.

| improve this answer | |
  • Thanx @Chupo_cro but none of those worked. So, I started commenting out stuff and apparently the problem is at two places (the program works without these two). The first is the line: WiFi.macAddress(mac); and after that this line: byte numSsid = WiFi.scanNetworks(); Which pretty much makes this program a zero.... – Chiwda Dec 5 '16 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.