Behind today’s door is a 1-kohm resistor. We’re not going to do much with it today, but tomorrow it becomes important. In today’s test, we want to set up an initial connection to your home WLAN network. For this purpose, you need, as you will on many days to come, to enter your WLAN data in the programme.

Das Board pingt den Google Server an
The Board pings the Goolge server

But first you need to download today’s programme. You can download it via the right button on the from the Arduino Create Iframe.

.

The sketch: A16_P04_WiFiConnect.ino
/*
  Test for Wifi connection and ping-time
  Change SSID and PASSWORD.
*/

#include <NanoESP.h>
#include <SoftwareSerial.h>

//Change SSID and PASSWORD here:
#define SSID "YourSSID"
#define PASSWORD "YourPassword"

#define LED_WLAN 13

NanoESP nanoesp = NanoESP();

void setup() {
  Serial.begin(19200);
  nanoesp.init();

  //Station Mode, Connect to WiFi
  if (!nanoesp.configWifi(STATION, SSID, PASSWORD)) {
    Serial.println(F("Error: WLAN not Connected\n"));
  }
  else {
    Serial.println(F("WLAN Connected\n"));
    digitalWrite(LED_WLAN, HIGH);
  }

 //Print IP in Terminal
  Serial.println(nanoesp.getIp());

  //Time for Ping
  int vTime = nanoesp.ping("www.google.de");

  if (vTime > 0 ){
    Serial.println("Internet Connection OK\nPing: " + String(vTime) + "ms"); 
  }
  else {
    Serial.println(F("Error: Internet Connection"));
  }
}

void loop() {

}

(The former Arduino Create embed is no longer available; the code is taken from the download of all sketches.)

When you’ve opened the programme in the Arduino IDE, you will see at the very first two DEFINES. This is where you have to enter your WLAN name and the password. Only then can you upload the programme. You can now check the status of the WLAN connection on the serial monitor. In the ideal case, you’ll see “WLAN Connected” there. The LED D3 also lights up. If you run into problems, you’ll find help in the commentary section.

After the connection, yet more messages appear on the serial monitor. First, the IP address of the board is given once. It was assigned to the NanoESP by the router and is the board’s address in the local network. After that, the board pings a server on the Internet to test whether it is connected to the Internet. If everything functions, a suitable message appears on the serial monitor and the answer time in milliseconds that passed from the sending of the ping to reception of the answer. You may recognise this ping value from online games. The connection to the Internet now exists, and you are ready to take larger steps with the board.

Verbindung erfolgreich hergestellt
Connection successfully created