title: NodeMCU ets Jan 8 2013,rst cause:4, boot mode:(3,6) wet reset issue?
body: <p>this is the code I'm using from the mathworks website; <a href="https://in.mathworks.com/help/thingspeak/MoistureMonitor.html" rel="nofollow noreferrer">https://in.mathworks.com/help/thingspeak/MoistureMonitor.html</a></p>
  
  <p>I'm using it to connect a soil sensor to my NodeMCU board and then log the data via HTTP POST to ThingSpeak IOT server. My serial reading is as follows:</p>
  
  <p>ets Jan  8 2013,rst cause:4, boot mode:(3,6)</p>
  
  <p>wdt reset</p>
  
  <p>Please check out the code and help me out. Thanks!</p>
  
  <pre><code>#include &lt;ESP8266WiFi.h&gt;
  
  // Network information.
  
  
       #define WIFI_NAME "Balasundar-EXT"
       #define PASSWORD "9900002967"
  
  // Hardware information.
  
      #define SENSOR_POWER 6                  // Connect the power for the soil sensor here.
      #define SOIL_PIN A0                     // Connect the sensor output pin here.
      #define TIMEOUT  5000                  // Timeout for server response.
      #define SLEEP_TIME_SECONDS 1800
  // ThingSpeak information.
  #define NUM_FIELDS 2                               // To update more fields, increase this number and add a field label below.
  #define SOIL_MOISTURE_FIELD 1                      // ThingSpeak field for soil moisture measurement.
  #define ELAPSED_TIME_FIELD 2                       // ThingSpeak Field for elapsed time from startup.
  #define THING_SPEAK_ADDRESS "api.thingspeak.com"
  String writeAPIKey="JBNXNMFKVWQJ1NNV";             // Change this to your channel Write API key.
  
  // Global variables. 
  int numMeasure = 5;                                // Number of measurements to average.
  int ADCValue = 0;                                  // Moisture sensor reading.
  
  WiFiClient client;
  
    // Put your setup code here, to run once:
  void setup()
  {
      Serial.begin( 115200 );   // You may need to adjust the speed depending on your hardware.
      connectWifi();
      pinMode( SENSOR_POWER , OUTPUT );
      digitalWrite( SENSOR_POWER , LOW );   // Set to LOW so no power is flowing through the sensor.
  }
  
    // Put your main code here, to run repeatedly:
  void loop()
  {
      // You can fill fieldData with up to 8 values to write to successive fields in your channel.
      String fieldData[ NUM_FIELDS ];  
  
      // You can write to multiple fields by storing data in the fieldData[] array, and changing numFields.        
      // Write the moisture data to field 1.
      fieldData[ SOIL_MOISTURE_FIELD ] = String( readSoil( numMeasure ) ); 
      Serial.print( "Soil Moisture = " );
      Serial.println( fieldData[ SOIL_MOISTURE_FIELD ] );
  
      // Write the elapsed time from startup to Field 2.
      fieldData[ ELAPSED_TIME_FIELD ] = String( millis() ); 
  
      HTTPPost( NUM_FIELDS , fieldData );
  
      delay( 1000 );
      Serial.print( "Goodnight for "+String( SLEEP_TIME_SECONDS ) + " Seconds" );
      ESP.deepSleep( SLEEP_TIME_SECONDS * 1000000 );
      // If you remove the sleep, add delay so you don't post to ThingSpeak too often.
      // delay( 20000 );
  }
  
  // This function reads the soil moisture sensor name times and returns the average.
  long readSoil(int numAve)
  {
    long ADCValue = 0;
  
    for ( int i = 0; i &lt; numAve; i++ ) {
      digitalWrite( SENSOR_POWER, HIGH );  // Turn power to device on
      delay(10);    // Wait 10 milliseconds for sensor to settle
      ADCValue += analogRead( SOIL_PIN );     // Read the value from sensor
      digitalWrite( SENSOR_POWER, LOW );   // Turn power to device off
    }
  
    ADCValue = ADCValue / numAve;
    return ADCValue;                    // Return the moisture value.
  }
  
  // Connect to the local WiFi network
  int connectWifi()
  {
  
      while (WiFi.status() != WL_CONNECTED) {
          WiFi.begin( WIFI_NAME , PASSWORD );
          Serial.println( "Connecting to WiFi" );
          delay( 2500 );
      }
      Serial.println( "Connected" );  // Inform the serial monitor.
  }
  
      // This function builds the data string for posting to ThingSpeak
      // and provides the correct format for the wifi client to communicate with ThingSpeak.
      // It will post "numFields" worth of data entries, and takes the
      // data from the fieldData parameter passed to it. 
  
  int HTTPPost( int numFields , String fieldData[] ){
  
      if (client.connect( THING_SPEAK_ADDRESS , 80 )){
  
         // Build the Posting data string.  
         // If you have multiple fields, make sure the sting does not exceed 1440 characters.
         String postData= "api_key=" + writeAPIKey ;
         for ( int fieldNumber = 1; fieldNumber &lt; numFields+1; fieldNumber++ ){
              String fieldName = "field" + String( fieldNumber );
              postData += "&amp;" + fieldName + "=" + fieldData[ fieldNumber ];
  
              }
  
          // POST data via HTTP
          Serial.println( "Connecting to ThingSpeak for update..." );
          Serial.println();
  
          client.println( "POST /update HTTP/1.1" );
          client.println( "Host: api.thingspeak.com" );
          client.println( "Connection: close" );
          client.println( "Content-Type: application/x-www-form-urlencoded" );
          client.println( "Content-Length: " + String( postData.length() ) );
          client.println();
          client.println( postData );
  
          Serial.println( postData );
  
          String answer=getResponse();
          Serial.println( answer );
      }
      else
      {
        Serial.println ( "Connection Failed" );
      }
  
  }
  
  // Wait for a response from the server to be available, 
  //and then collect the response and build it into a string.
  String getResponse(){
    String response;
    long startTime = millis();
  
    delay( 200 );
    while ( client.available() &lt; 1 &amp;&amp; (( millis() - startTime ) &lt; TIMEOUT ) ){
          delay( 5 );
    }
  
    if( client.available() &gt; 0 ){ // Get response from server
       char charIn;
       do {
           charIn = client.read(); // Read a char from the buffer.
           response += charIn;     // Append the char to the string response.
          } while ( client.available() &gt; 0 );
      }
    client.stop();
  
    return response;
  }
  </code></pre>