1

I'm working on a project to send ultrasonic sensor data to my webserver. For that I'm using ESP8266 WiFi module, 3.3V regulator IC by giving input volt of 5v from aduino uno.

I successfully uploaded a code but in serial monitor I got an error

ets jan 8 2013,rst cause:4,boot mode(1,6) wdt reset. 

Please, tell what does it mean?

Here is my code. Guide me if I made something wrong. Thanks in advance.

Note: Before sending sensor values I successfully send a raw data manually to webserver, i.e string data, but when I try to send sensor values, I got an error.

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "VENTURE 11";
const char* pass = "12345678";

WiFiClient clientx;
const int trigPin = 8;  //Digital port D5
const int echoPin = 9;  //Digital port D6

long duration;
float distance;
float Mdistance;
float MAX_HEIGHT = 0;


void setup() {

  Serial.begin(115200);                                  //Serial connection
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT);

  WiFi.begin("VENTURE 11", "12345678");   //WiFi connection
  Serial.println("Setup iniated");
  while (WiFi.status() != 3) {  //Wait for the WiFI connection completion
    delay(500);
    Serial.println("Waiting for connection");
    Serial.print("WIFI STATUS : ");
    Serial.println(String(WiFi.status()));
  }
  Serial.println(String(WiFi.status()));
}

void loop() {
  Serial.println(String(WiFi.status()));
  if (WiFi.status() != 3)
  {
    WiFi.begin("VENTURE", "12345678");   //WiFi connection
    while (WiFi.status() != 3)
    {
      Serial.println("Waiting for connection");
    }
  }
  else
  {
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);

    // Sets the trigPin on HIGH state for 10 micro seconds
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);

    // Reads the echoPin, returns the sound wave travel time in microseconds
    duration = pulseIn(echoPin, HIGH);

    // Calculating the distance
    distance = (duration * 0.034) / 2;


    if (MAX_HEIGHT == 0) {
      //MAX_HEIGHT = distance;
      Serial.print("Max height has been set to ");
      //Serial.print(distance);
      Serial.println(" cm");
      Serial.println("Waiting for 5 seconds...");
      delay(5000);
    } else {
      Serial.print("Distance:\n");
      Serial.print(distance);
      Serial.print("cm\n");
      Serial.print("Distance:\n");
      Serial.print(distance / 100);
      Serial.print("m\n");
      delay(1000);


    }

    HTTPClient http;
    String Data = "x=" + (String)distance + "&y=" + (String)MAX_HEIGHT + "&z=0";
    //String Data = "x=Finally&y=Did&z=it;)";
    http.begin("http://testingblahblah.000webhostapp.com/IOTCON.php");
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    int sent = http.POST(Data);
    Serial.println(sent);
    String httpPayload = http.getString();
    Serial.println(httpPayload);
    if (sent > 0)
    {
      Serial.println("Message has been sent");
    } else {
      Serial.println("unable to send data");
    }
    delay(20000);

  }
}`
  • Do you see the serial prints on your serial monitor? where do they stop? – Mero55 Dec 29 '17 at 11:08
  • also in String Data, you should type String(distance) and String(MAX_HEIGHT) (paranthesis around the argument not the func) – Mero55 Dec 29 '17 at 11:14
  • why does it reset to bootloader mode (1, 6)? – Juraj Dec 29 '17 at 11:46
  • Please check SSID name of the WiFi in the code. – AltAir Dec 29 '17 at 18:33
3

Your loop():

void loop() {
  Serial.println(String(WiFi.status()));
  if (WiFi.status() != 3)
  {
    WiFi.begin("VENTURE", "12345678");   //WiFi connection
    while (WiFi.status() != 3)
    {
      Serial.println("Waiting for connection");
    }
  }
  else 
  {
    // Other code...
  }
}

While waiting for the connection, you are creating String objects at a very high rate, since your delay(20000) is in the else clause.

This means you are possibly running out of memory, as you are creating the String objects with every iteration, which is in the Megahertz range.

You likely don't need the String(...) wrappers, as the Serial.println() function can work with C-style strings returned by the WiFi library. Then, your program won't be allocating memory to hold the result of WiFi.status() millions of times per second, which you don't use later on in your program.

2

cause 4 is reset by watchdog. the watchdog resets your esp because it comes not out of the loop. the long delay is your problem. do timing with millis() to execute actions in some interval.

  • 2
    delay() shouldn't be a problem - it calls the yield() function(s) needed to keep the watchdog alive. – Majenko Dec 29 '17 at 10:42
  • So how do i call that function and where do i place it in my coding – Touseef ahmed Dec 29 '17 at 10:48
1

Found a possible solution. I was facing with the same problem. Apparently this is a hardware stack overflow watch dog preventing malfunction. This may not apply to every possible scenario but I discovered that the allocated pin number on the board itself is incorrect. What is numbered 03 is in fact D15 for example. So assigning the pin to D15 worked but 3 created this error. I hope this helps others.

  • Had configured wrong PIN also :-) – meelow Mar 5 at 12:03

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.