6 - Network Operation
6 - Network Operation
Difficult Level:
Step 2: Open the arduino_secrets.h and write down your own SSID and PASS.
Like this:
Note: If you have been unable to connect to the Internet during this project, you
can power off the Arduino Uno R4 Wi-Fi for a while and then reconnect.
GND GND
GND GND
/* ------------------------------------------------- */
void setup() {
/* -------------------------------------------- */
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native
USB port only
}
pinMode(LED_PIN, OUTPUT); // set the LED pin mode
pinMode(LED2_PIN, OUTPUT); // set the LED2 pin mode
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
printWifiStatus();
/* ------------------------------------------------------ */
void loop() {
/* ------------------------------------------------- */
read_response();
// do nothing forevermore:
while (true);
}
}
/* ---------------------------------------------------- */
void printWifiStatus() {
/* ------------------------------------------------------ */
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
C. Extension
Statistical delay. When the delay is greater than 7000, the yellow light is on, the green light of
the network process is on, and the network delay is too long, the red light is on.
What you need
• 3 x LED light (one red, one yellow, and one green)
• 1 x Arduino UNO R4 Wi-Fi
• 1 x USB 2.0 cable Type C
• 6 x male to male dumper wires
GND GND
GND GND
GND GND
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
printWifiStatus();
Serial.print("Time1: ");
myTime1 = millis();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.1");
client.println("Host: www.github.com");
client.println("Connection: close");
client.println();
}
}
/* -------------------------------------------------------- */
void loop() {
/* -------------------------------------------------------- */
read_response();
// do nothing forevermore:
while (true);
}
}
/* ---------------------------------------------------- */
void printWifiStatus() {
/* ---------------------------------------------------- */
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
Congratulations!
You have already got this new skills!!! Once the Arduino with sensors is connected to the
network, its potential is unlimited, and we are about to start a smart home chapter! come on!
Keep going!