WebServer

In this demonstrative example is shown how to realize a simple web server, using an Arduino UNO WiFi
, to read the analog sensors values.

Hardware

Connect your sensors to the Analog pins of the board and plug in your Arduino to PC. 
Now upload the code.

Code

Upload the below code and access via browser to http://<IP>/arduino/webserver/ orhttp://<hostname>.local/arduino/webserver/ to read the sensors values.

 
 
#include <Wire.h>
#include <ArduinoWiFi.h>
/*
on your borwser, you type http://<IP>/arduino/webserver/ or http://<hostname>.local/arduino/webserver/
 
http://www.arduino.org/learning/tutorials/webserver
 
*/
void setup() {
  Wifi.begin();
  Wifi.println("WebServer Server is up");
}
void loop() {
 
  while(Wifi.available()){
    process(Wifi);
  }
delay(50);
}
void process(WifiData client) {
// read the command
String command = client.readStringUntil('/');
 
if (command == "webserver") {
  WebServer(client);
}
}
void WebServer(WifiData client) {
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: text/html");
        client.println("Connection: close");
        client.println("Refresh: 20"); // refresh the page automatically every sec
        client.println();    
        client.println("<html>");
        client.println("<head> <title>UNO WIFI Example</title> </head>");
        client.print("<body>");
       
        for (int analogChannel = 0; analogChannel < 4; analogChannel++) {
          int sensorReading = analogRead(analogChannel);
          client.print("analog input ");
          client.print(analogChannel);
          client.print(" is ");
          client.print(sensorReading);
          client.print("<br/>");
        }
         
        client.print("</body>");
        client.println("</html>");
        client.print(DELIMITER); // very important to end the communication !!!        
}
 
 

OUTPUT

Web Server

  • You can look the sensors values also from the web panel, as shown in the below image:

WiFi Console
Note: 
Type the IP address or the hostname.local/ of your board on the browser so you will access to the Arduino UNO WiFi web panel.