Reflect

To content | To menu | To search

Programming

Entries feed - Comments feed

Saturday 21 May 2016

Watchdog Resets

There are two commands which can help prevent a watchdog reset.

  1. delay()
  2. yield()

These commands allow the ESP8266 to perform internal routines while the user commands are waiting for some action. If the internal routines are not executed on time the watchdog is triggered.

Simple Ping Example

There are instances where you want to check if the ESP8266 is connected to a Wifi AP and if the AP does have internet connectivity or not. In those situations try the code below

#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>

const char* ssid     = "ssid";
const char* password = "password";

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

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  } 
/* If you are here you successfully connected to your access point */

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

void loop() {
  delay(5000);
  Serial.print("Pinging ip ");
  Serial.println("www.google.com");

  if(Ping.ping("www.google.com")) {
    Serial.println("Success!!"); /* if the code reaches here you are good to go */
  } else {
    Serial.println("Error :(");
  }
}