Establish Wifi-connection

For the real IoT application, the microcontroller still needs to be able to spark into the network. For this purpose, a WIFI connection is established in the following step.

working task

Establish a connection by incorporating the code listed in the information section into the existing program with the WIFI router and adjust the source code so that the signal LEDs indicate the search as running light during connection setup.

Wifi connection

The following code enables the connection to a WIFI access point or router.

#include <ESP8266WiFi.h>
#include <DHT.h>

// WIFI Connection
const char* ssid = "Fritzbox1";
const char* password = "Fritzbox1Passwort";

WiFiClient espClient;

// local hardware
[...]

void setup() {
 [...]
 setupWifi(); 
}

void setupWifi() {
 delay(100);
 Serial.print("Connecting to ");
 Serial.print(ssid);
 Serial.print(" ");
 
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED)
 {
   delay(500);
   Serial.print(".");
 }
 Serial.println();

 randomSeed(micros());
 Serial.println("");
 Serial.print("WiFi connected - ");
 Serial.print("IP: ");
 Serial.println(WiFi.localIP());

} // setupWIFI

[...]

Leave a Reply