Problema! ets Jan 8 2013,rst cause:4, boot mode:(3,6) wdt reset

**Pessoal estou com problemas no meu codigo, aparecendo essa mnsagem de erro
" ets Jan 8 2013,rst cause:4, boot mode:(3,6)

wdt reset"**

O códgo foi desenvolvido para ESP32, montei uma placa agora para ESP12F, mas sempre da erro. Alguem pode me ajudar? O codgo fonte, vai abaixo: Obrigado Pessoal" :slight_smile:

#include <Arduino.h>
#include <WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
// Add porta usb
//sudo chmod 666 /dev/ttyUSB0
//                               Testar:
#define rele1             13     // 7
#define rele2             12     // 5
#define rele3             9      // 11
#define rele4             10     // 12
#define conexao           4      // 3
#define saida             6      // 6
#define ldr               A0     // 2

#define WLAN_SSID       "digiteSeuUsuario"             // Your SSID
#define WLAN_PASS       "***************"        // Your password

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883                   // use 8883 for SSL
#define AIO_USERNAME  "Usuario"
#define AIO_KEY       "*************"   // Replace with your Project Auth Key

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

/****************************** Feeds ***************************************/


// Setup a feed called 'onoff' for subscribing to changes.
Adafruit_MQTT_Subscribe Light1 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/rele1"); // FeedName
Adafruit_MQTT_Subscribe Light2 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/rele2");
Adafruit_MQTT_Subscribe Light3 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/rele3");
Adafruit_MQTT_Subscribe Light4 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/Rele4");



void MQTT_connect();

void setup() {
  Serial.begin(115200);

  pinMode(rele1, OUTPUT);
  pinMode(rele2, OUTPUT);
  pinMode(rele3, OUTPUT);
  pinMode(rele4, OUTPUT);
  pinMode(conexao, OUTPUT);
  pinMode(ldr, INPUT);
  digitalWrite(conexao, LOW);

  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    
  }
  Serial.println();

  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());


  // Setup MQTT subscription for onoff feed.
  mqtt.subscribe(&Light1);
  mqtt.subscribe(&Light2);
  mqtt.subscribe(&Light3);
  mqtt.subscribe(&Light4);

  digitalWrite(rele1, HIGH);
  digitalWrite(rele2, HIGH);
  digitalWrite(rele3, HIGH);
  digitalWrite(rele4, HIGH);
}

void loop() {

  MQTT_connect();


  Adafruit_MQTT_Subscribe *subscription;
  while ((subscription = mqtt.readSubscription(20000))) {
    if (subscription == &Light1) {
      Serial.print(F("Got: "));
      Serial.println((char *)Light1.lastread);
      int Light1_State = atoi((char *)Light1.lastread);
      digitalWrite(rele1, Light1_State);

    }
   if (subscription == &Light2) {
     Serial.print(F("Got: "));
     Serial.println((char *)Light2.lastread);
     int Light2_State = atoi((char *)Light2.lastread);
     digitalWrite(rele2, Light2_State);
    }
   if (subscription == &Light3) {
      Serial.print(F("Got: "));
      Serial.println((char *)Light3.lastread);
      int Light3_State = atoi((char *)Light3.lastread);
      digitalWrite(rele3, Light3_State);
    }
  if (subscription == &Light4) {
    Serial.print(F("Got: "));
    Serial.println((char *)Light4.lastread);
    int Light4_State = atoi((char *)Light4.lastread);
    digitalWrite(rele4, Light4_State);

    }
  }


}

void MQTT_connect() {
  int8_t ret;

  // Stop if already connected.
  if (mqtt.connected()) {
    return;
  }

  Serial.print("Connecting to MQTT... ");

  uint8_t retries = 3;

  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
    Serial.println(mqtt.connectErrorString(ret));
    Serial.println("Retrying MQTT connection in 5 seconds...");
    mqtt.disconnect();
    delay(5000);  // wait 5 seconds
    retries--;
    if (retries == 0) {
      // basically die and wait for WDT to reset me
      while (1);
    }
  }
  Serial.println("MQTT Connected!");
  digitalWrite(conexao, HIGH);

}

I don’t understand Portuguese so I can only guess what your question is.

The program seems to be able to connect to the WiFi but unable to connect to MQTT and after 3 retries dies at:

while (1);

Most likely some of the MQTT parameters (server name, port, username, key, http vs https) are not correct or you are in a WiFi network that restricts outgoing connections.

The question is actually the following:
The code was developed for ESP32 and works perfectly, but I built a board to be able to use the ESP12f module, but it is giving error with the message " [rst cause:4, boot mode:(3,6) wdt reset]". The mqtt issue works well with esp32.
did you understand my doubt?
Thanks!

Something in your code is causing the hardware watchdog to timeout, and thus trigger the reset.

You’ll have to look at how far into your program the lockup is occuring (i.e. does it lockup during setup(), or a particular stage of loop()). Perhaps you need to use yield() in a few strategic places of your code to ‘feed’ the watchdog, because your code is blocking too long, hence the watchdog reset. This is more likely to occur with the ESP8266 than the ESP32 due to the single-core nature of the processor.

Solved!
I was using the “WiFi.h” library, when the right thing was to use “ESP8266WiFi.h”. A very amateur mistake, but I found the solution on github. I thank everyone!

2 Likes