Wednesday, March 30, 2016

Run diagnosis of NodeMCU/ESP8266


To run diagnosis of NodeMCU/ESP8266, we can call the function WiFi.printDiag(Serial), pass with Serial port as the parameter, it will send the diagnostic info to Serial port.

remark: this apply on NodeMCU (suppose on other standalone ESP8266 also) with ESP8266 core for Arduino.

Example:
#include <ESP8266WiFi.h>

const char* ssid = "arduino-er";
const char* password = "12345678";
byte mac[6];

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

  Serial.print("\nRun diagnostic...\n");
  WiFi.printDiag(Serial);
  Serial.println();
  
  Serial.print("\nStart...\n");
  WiFi.macAddress(mac);
  Serial.print("MAC: ");
  Serial.print(mac[0],HEX);
  Serial.print(":");
  Serial.print(mac[1],HEX);
  Serial.print(":");
  Serial.print(mac[2],HEX);
  Serial.print(":");
  Serial.print(mac[3],HEX);
  Serial.print(":");
  Serial.print(mac[4],HEX);
  Serial.print(":");
  Serial.println(mac[5],HEX);
  Serial.println();

  WiFi.begin(ssid, password);
  Serial.print("Connecting WIFI ");
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("connected");  
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  // put your main code here, to run repeatedly:

}

sample output:

No comments:

Post a Comment