Wdt reset rst cause:4, boot mode:(3,6)

Hi Blynkers,
I have programed four ESP8266 12E, with Micropython with PyCharm CE under MacOS Mojave. On every one of them I uploaded 3 programs: boot.py, main.py and BlynkLib.py. My boot.py establishes the wifi connection and in my main.py I am controlling several sensors under blynk. All four devices are operating in the same wifi network For several days everything has been working fine. My Blynk is at my iPhone with iOS version 12.3

I made a very small change in my programing today, consisting in adding an additional wifi network (in my boot.py) and some comments and todo in my main.py. Nothing very exciting or important. I made these changes in just one of my ESP units and boot again, while the others were still connected and working all right

After uploading the new boot and main programs (blynklib was untouched) the ESP started a continuos booting cicling, with the following error message:

    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ for Python v0.2.0 (esp8266)


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

wdt reset
load 0x40100000, len 31020, room 16 
tail 12
chksum 0xd2
ho 0 tail 12 room 4
load 0x3ffe8000, len 1100, room 12 
tail 0
chksum 0x9a
load 0x3ffe8450, len 824, room 8 
tail 0
chksum 0xbd
csum 0xbd

I made several tests to pinpoint the problem:
I made a rollback to my last functional version, also uploaded wiped out the ESP and uploaded everything fresh with the prior version and no result. I thought it might be a hardware problem, so I repeated the procedure on another ESP and this new one presented the same problem.
I pinpointed the problem to the BlynkLib library uploading and running the programs in sequence.

My boot.py is:

# Archivo boot.py se ejecuta cuando el dispositivo se despierta,
# incluyendo el wake-boot despues de un deepsleep
import gc
import network
import time
from machine import Pin
gc.collect()
# redes disponibles para conectar los dispositivos
redes = (
    ("Los Leones", "hamel", "xxxxxxxxxx"),
    ("Holanda", "ARRIS-0592", "xxxxxxxxx"),
    ("Ximena", "VTR-4910546", "xxxxxxxxxx")
    # aqui se pueden colocar otras redes
)
# -------------------------------------------------------------//
# funcion para conectar el dispositivo a algunas de las redes
# definidas en la tupla
def conectar(origen, ssid, password):
    red = network.WLAN(network.STA_IF)
    ap_if = network.WLAN(network.AP_IF)
    ap_if.active(False)
    if not red.isconnected():
        print()
        print("**** intentado conexion a red de '%s'" % origen)
        red.active(True)  # activa la interfaz
        red.connect(ssid, password)  # se conecta
        for i in range(10):  # espera a que se realice la conexion
            if red.isconnected():
                print()
                print("**** IP/mascara de red/gateway/DNS: ", red.ifconfig(), "\n")
                break
            time.sleep(0.5)
            print('.', end='')
        else:
            return None

        print("**** conectado a la red de '%s'." % origen)
    else:
        print("**** ya estaba conectado a la red '%s'." % origen)

    return red

# trata de conectarse a alguna de las redes definidas en la tupla
# utilizando la funcion conectar
for red_wf in redes:
    wlan = conectar(*red_wf)
    if wlan:
        break
else:
    print("**** no he encontrado una WIFI para conectarme....")

led = Pin(16, Pin.OUT)  # selecciona el pin numero 2
total = 0
print("**** saliendo del boot....")
while total < 3:
    led.value(0)  # turn on
    time.sleep(0.1)
    led.value(1)  # turn off
    time.sleep(0.1)
    total = total + 1

My main.py is

import BlynkLib
import time
import network
from machine import Pin

# dispositivo 1
# nombre = "Unidad 1"
# token = 'xxxxxxxx'
# dispositivo 2
nombre = "Unidad 2"
token = 'xxxxxxxxx'
# dispositivo 3
# nombre = "Unidad 3"
# token = 'xxxxxxxx'
# dispositivo 4
# nombre = "Unidad 4"
# token = 'xxxxxxxxxx'
blynk = BlynkLib.Blynk(token)
pin_D0 = 16  # led azul al costado del reset. Equivale a GPIO16
pin_D4 = 2  # led azul al costado de la wifi. Equivale a GPIO4

#preparo todos los pines GPIO y los dejo todos como output y apagados
# para usarlos  para leer sensores analogos
for i in [9, 10, 12, 13, 14, 15]:
    led = Pin(i, Pin.OUT)  # selecciona el pin numero 12
    led.value(0)
# -------------------------------------------------------------//
# función para usar el led como aviso
# veces = numero de blinks totales
# tiempo = segundos que prende y apaga la luz
# ojo, los leds estan con polaridad invertida, asi es que cuando
# se "apagan" con un valor 0, se prenden.
def avisa_led(led, veces, tiempo):
    import time
    led = Pin(led, Pin.OUT)  # selecciona el pin numero 2
    total = 0
    while total < veces:
        led.value(0)  # turn on
        time.sleep(tiempo)
        led.value(1)  # turn off
        time.sleep(tiempo)
        total = total + 1

# -------------------------------------------------------------// V0
# este widget imprime el cambio de estatus en el REPL desde boton.
# Es solo para probar que esta en linea y funciona
@blynk.VIRTUAL_WRITE(0)
def nombre(value):
    print("Valor del boton V0 apretado: {}".format(value))
    avisa_led(pin_D0, 10, 0.1)
# -------------------------------------------------------------// V1
# muestra el tiempo que ha estado en linea conectado en V1
# lo tengo solo para probar, despues se borra
@blynk.VIRTUAL_READ(1)
def display():
    blynk.virtual_write(1, time.time() / 60)
# -------------------------------------------------------------// V2
# muestra la intensidad de la señal entre el dispositivo y
# el router wifi
@blynk.VIRTUAL_READ(2)
def fuerza_wifi():
    red = network.WLAN(network.STA_IF)
    fuerza = red.status("rssi")
    blynk.virtual_write(2, fuerza)
# -------------------------------------------------------------// V3
# este widget me permite controlar un led ubicado en D7 para
# hacer pruebas de multiplexacion
@blynk.VIRTUAL_WRITE(3)
def pin_d7(valor):
    print("Valor del boton V3 apretado:", valor)
    led = Pin(13, Pin.OUT)
    if valor == ["1"]:
       led.value(1)
    else:
        led.value(0)

# -------------------------------------------------------------// V6
# este widget muestra la cantidad de luz en V6
# utilizo el LDR GL-5528. segun el datasheet, la resistencia en luz intensa es 15 KΩ, en oscuridad es 1000 KΩ,
# un gamma de 0,6 y un tiempo de reaccion de 25 milisegundos
# voltaje de alimentacion: 3.3
@blynk.VIRTUAL_READ(6)
def ldr():
    import machine
    led = Pin(12, Pin.OUT)  # selecciona el pin numero 12
    led.value(1)
    adc = machine.ADC(0)
    lee_A0 = adc.read()
    print("valor del LDR: ", lee_A0)
    led.value(0)
    time.sleep(1)
    blynk.virtual_write(6, lee_A0)

# -------------------------------------------------------------//

# El programa inicia aqui.
# Hago fuegos artificales para demostrar que la cosa anda
avisa_led(pin_D0, 10, 0.1)
avisa_led(pin_D4, 10, 0.1)
print("*** estoy conectado y listo para trabajar maestro....")

while True:
    blynk.run()

Please comment on what the problem is and how can I solve it, bacause I am completely clueless.

Thanks and regards

the problem, is this error message, then resets itself, boots again, displays the message, and so on endlessly:

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

wdt reset
load 0x40100000, len 31020, room 16 
tail 12
chksum 0xd2
ho 0 tail 12 room 4
load 0x3ffe8000, len 1100, room 12 
tail 0
chksum 0x9a
load 0x3ffe8450, len 824, room 8 
tail 0
chksum 0xbd
csum 0xbd

https://arduino-esp8266.readthedocs.io/en/latest/boards.html#boot-messages-and-modes

This means the reset was caused by the watchdog timer. Perhaps something is blocking or constantly looping in your code? Perhaps even a brownout causing issues with the WiFi connection?

I am certain there was no brownout, either electrical or in my wifi connection. I experienced the same in two separate devices, fed independently in two different networks.
Yesterday mi code was working all right, with some devices working continuously for several days with no interruption or problem. Besides, the problem arises when the main.py program calls the library at booting
What can I do to pinpoint precisely the issue here? Or, if it is the watchdog as you suggest, what can I do to solve this?

Then it is your code or environmental interference in the WiFi range…

Probably more likely your code, as you said you did make some changes.

Really, there may be nothing more possible than breaking your code down into chunks, and/or adding in lots of logging/serial prints to show program status, and repeatedly testing to see what causes the issue. Basically follow the scientific method or brute force trial and error (my favorite :laughing:)

it is the same old reliable method I use myself, so, I will start dismantling and testing.
Will revert to you once I find the issue
thanks for your patience in this

1 Like

as per your suggestion, I’ve found this piece of code was generating the error:

for i in [9, 10, 12, 13, 14, 15]:
    led = Pin(i, Pin.OUT)  # selecciona el pin numero 12
    led.value(0)

In this part I am making those GPIO pins outbound and low.
Can’t understand why is colliding with the WDT, but at least the problem is bounded
Thanks a lot.
(do I have to close the ticket or anything of the sort?)

Well, on an ESP8266 pins 9 & 10 are not meant for GPIO use (and not available on some Dev boards like the Wemos D1 Mini anyhow), and 15 is in the questionable zone.

Nope… but I can mark it solved (just a visual flag).