arest ui library help SCHOOL PROJECT

Hi,

I need help to understand a piece of the code i'm using in my school project. Here is the code, but i need help to understand how the void loop is working, and how i can get information in my serial monitor when the switch it is on and off?

Hope someone can give me a answer :slight_smile:

// Relay control using the ESP8266 WiFi chip

// Import required libraries
#include <ESP8266WiFi.h>
#include <aREST.h>
#include <aREST_UI.h> // Biblotek som lager on/off knappene på mobilen

// Create aREST instance
aREST_UI rest = aREST_UI();

// WiFi parameters
const char* ssid = "kjetil sin iPhone";
const char* password = "12345678";

// The port to listen for incoming TCP connections
#define LISTEN_PORT 80

// Create an instance of the server
WiFiServer server(LISTEN_PORT);
void setup(void)
{
// Start Serial
Serial.begin(115200);

// Create UI
rest.title("Relay Control");
rest.button(5);

// Give name and ID to device
rest.set_id("1");
rest.set_name("esp8266");

// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.println(WiFi.localIP());

}

void loop() {

// Handle REST calls
WiFiClient client = server.available();
if (!client) {
return;
}
while (!client.available()) {
delay(1);
}
rest.handle(client);

}

but i need help to understand how the void loop is working,

There's hardly any code there, and it is commented. What don't you understand?

and how i can get information in my serial monitor when the switch it is on and off?

What switch are you talking about? If you mean router, the Arduino doesn't know if some external piece of hardware is powered on, or not. It gets input, or it doesn't. If it doesn't. it has no idea why. Maybe there are no clients because the router is powered off. Maybe there are no clients because it is the middle of the night. Maybe there are no clients because your rest service is useless.

What i was wondering about is what does the rest.handle(client) command do, and how would i go about reading the response from the server so i could use those responses in further developing something of my own

What i was wondering about is what does the rest.handle(client) command do

It brews coffee and servers tuna fish sandwiches, just like the name implies.

Isn't it abundantly clear that the function handles a client request?