IoT Lab - Wi-Fi Connection
The controller board that we're currently using (ESP32) has built-in Wi-Fi adapter which able to 2.4GHz WPA Wi-Fi. Connecting Wi-Fi can extend more use cases of the board by connecting, sending and receiving data from the internet.
In this workshop, we are going to send the measured humidity and temperature sensor to Node.js server and display the information of humidity/temperature log to the webpage.
Connecting to Wi-Fi
We have provisioned Wi-Fi network for you to use with your controller board:
To connect Wi-Fi from your board, try the code example by searching:
And you will get code something like:
#include<WiFi.h>
#define WIFI_STA_NAME "CSC317"
#define WIFI_STA_PASS "csc1212312121"
#define LED_BUILTIN 2
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(WIFI_STA_NAME);
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_STA_NAME, WIFI_STA_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() { }
The code above do the following functions: