Creare una Web app con ESP32

Negli ultimi anni la famiglia di chip ESP32 prodotti dalla Espressif si è affermata sul mercato per la sua caratteristica di flessibilità nelle applicazioni e per l'elevata integrazione di altri componenti in dimensioni compatte, comprese le antenne per le differenti comunicazioni wireless. Queste caratteristiche, unite al costo ridottissimo, rendono l'oggetto la scelta ideale per la realizzazione di applicazioni interconnesse come gli innumerevoli dispositivi destinati all’Internet of Things (IoT) per qualsiasi esigenza: acquisizione dati, reti neurali, elaborazioni distribuite e Web applications. In questo articolo andremo a percorrere tutti i passi per realizzare in pochissimo tempo un Web server con i moduli ESP32.

Introduzione

Il successo mondiale dei moduli ESP32 è noto ormai a chiunque abbia dimestichezza con il mondo dei makers. Velocità di calcolo, flessibilità, alta integrazione e costi ridotti rendono questi moduli più che un semplice componente, un partner ideale per i propri progetti di Internet of Things e non solo. Quando si parla di oggetti connessi esistono innumerevoli funzionalità che questi possono svolgere: dispositivi wearable per acquisizione continua, oggetti per la smart home sempre interconnessi alla rete Wi-Fi di casa, nodi di una sensor network oppure dei web server. In questo articolo andremo ad utilizzare una scheda ESP32 Devkit V1 con processore ESP-WROOM-32 per realizzare un Web server all’interno dell’IDE di Arduino.

Cos’è un Web server

Il Web server è un dispositivo interconnesso alla rete, capace di archiviare, elaborare e trasmettere informazioni ai “clienti” principalmente sotto forma di pagine web. I Web server sono praticamente le macchine dietro a qualsiasi sito o servizio internet. Si basa su un’architettura di comunicazione detta appunto client-server dove il server è il dispositivo in questione e i dispositivi "client" sono tutti gli utenti che interagiscono con il server inviando richieste attraverso il browser, proprio come avviene con le pagine di internet. Questa comunicazione client-server avviene attraverso il protocollo HTTP (HyperText Transfer Protocol) che tutti usiamo ogni giorno per navigare in internet. Dunque il server Web sarà un’applicazione software che verrà eseguita su una macchina hardware (appunto un server o nel nostro caso una scheda ESP32) connessa alla rete e che sia capace di gestire le richieste ricevute e trasmettere informazioni (pagine Web) verso un generico client.

La scheda di sviluppo ESP32 Devkit V1

Le schede ESP32 Devkit V1 sono degli oggetti estremamente economici e versatili la cui elaborazione è affidata al modulo ESP-WROOM-32 le cui caratteristiche tecniche sono le seguenti:

  • Microcontrollore: Tensilica 32-bit Single-/Dual-core CPU Xtensa LX6
  • Wi-Fi 2.4 GHz up to 150 Mbits/s
  • Bluetooth BLE (Bluetooth Low Energy)
  • Architettura a 32 bit
  • Frequenza di Clock fino a 240 MHz
  • RAM 512 KB
  • Periferiche: Capacitive touch, ADC (Analog to Digital Converter), DAC (Digital to Analog Converter), I2C (Inter-Integrated Circuit), UART (Universal Asynchronous Receiver/Transmitter), CAN 2.0 (Controller Area Network), SPI (Serial Peripheral Interface), I2S (Integrated Inter-IC Sound), RMII (Reduced Media-Independent Interface), PWM (Pulse Width Modulation) e altro.

La scheda, inoltre, è dotata di due LED: il primo, di colore rosso, ci indica la corretta alimentazione della scheda, il secondo, che è di colore blu, è un LED collegato al pin GPIO2 della scheda e dunque può essere pilotato direttamente dal software caricato sulla scheda. L'installazione di questa scheda all'interno dell'IDE di Arduino è molto semplice, in ogni caso qui di seguito è sintetizzata la procedura:

  • Dall'IDE di Arduino accedere alle Impostazioni (File -> Impostazioni)
  • Aggiungere il link "https://dl.espressif.com/dl/package_esp32_index.json" tra gli URL per il manager delle schede
  • Accedere al menu di gestione delle schede (Strumenti -> Scheda -> Gestione Schede)
  • Cercare ed installare il pacchetto relativo alle ESP32 fornito direttamente dalla Espressif Systems
  • Selezionare la scheda DOIT ESP32 Devkit V1 dal menu Strumenti -> Schede

Struttura del progetto

Lo sketch riportato di seguito è strutturato in maniera semplice:

  • la funzione setup() all'interno della quale sono riportate tutte le inizializzazioni necessarie quali:
    • la seriale per il monitor
    • la connessione Wi-Fi attraverso la funzione wifi.begin (ssid, password)
    • la funzionalità di Web server attraverso la funzione server.begin()
  • la funzione loop() all'interno della quale è riportata la logica del Web server

Come accennato nell'introduzione, un generico Web server si basa sulla comunicazione di tipo client-server. Pertanto, all'interno della logica del server implementata nella funzione loop() è stata inserita la ricerca di eventuali nuovi client da servire. Se un client è disponibile, allora viene letto il comando (ossia cosa è stato digitato all'interno della barra indirizzo). In funzione del comando viene attuata la logica corrispettiva e viene visualizzata una pagina in formato HTML. Il codice HTML è stato preparato con l'ausilio di un editor html online in modo da facilitare l'impaginazione senza dover entrare troppo nel dettaglio dei tag HTML. La visualizzazione dello stato del pulsante associato ad ogni GPIO della scheda è stata vincolata allo stato del pin stesso, in modo da poter gestire sia la visualizzazione ON/OFF del GPIO che la configurazione dell'indirizzo da raggiungere alla pressione del pulsante.

Codice dello sketch

#include <WiFi.h>

//credenziali WIFI
const char* ssid = "";/*INSERIRE SSID DELLA RETE WIFI A CUI CONNETTERSI*/
const char* password = ""; /* INSERIRE LA PASSWORD DEL WIFI */

// Set web server port number to 80
WiFiServer server(80);

String header;

bool GPIO1_state = false;
bool GPIO2_state = false;
bool GPIO3_state = false;
bool GPIO4_state = false;
bool GPIO5_state = false;
bool GPIO15_state = false;
bool GPIO16_state = false;
bool GPIO17_state = false;
bool GPIO18_state = false;
bool GPIO19_state = false;
bool GPIO12_state = false;
bool GPIO13_state = false;
bool GPIO14_state = false;
bool GPIO21_state = false;
bool GPIO22_state = false;
bool GPIO23_state = false;
bool GPIO25_state = false;
bool GPIO26_state = false;
bool GPIO27_state = false;
bool GPIO32_state = false;
bool GPIO33_state = false;
bool GPIO34_state = false;
bool GPIO35_state = false;
bool GPIO36_state = false;
bool GPIO39_state = false;

const String GPIO_string = "<a href=\"/GPIO";
const String LEDON_string = "/on\"><button class=\"button\">ON</button></a></p>";
const String LEDOFF_string = "/off\"><button class=\"button button2\">OFF</button></a></p>";
// Assign output variables to GPIO pins
#define GPIO1 1
#define GPIO2 2
#define GPIO3 3
#define GPIO4 4
#define GPIO5 5
#define GPIO12 12
#define GPIO13 13
#define GPIO14 14
#define GPIO15 15
#define GPIO16 16
#define GPIO17 17
#define GPIO18 18
#define GPIO19 19
#define GPIO21 21
#define GPIO22 22
#define GPIO23 23
#define GPIO25 25
#define GPIO26 26
#define GPIO27 27
#define GPIO32 32
#define GPIO33 33
#define GPIO34 34
#define GPIO35 35
#define GPIO36 36
#define GPIO39 39

// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0; 
const long timeoutTime = 2000;

void setup() {
Serial.begin(115200);
// Initialize the output variables as outputs
pinMode(GPIO1, OUTPUT); digitalWrite(GPIO1, LOW);
pinMode(GPIO2, OUTPUT); digitalWrite(GPIO2, LOW);
pinMode(GPIO3, OUTPUT); digitalWrite(GPIO3, LOW);
pinMode(GPIO4, OUTPUT); digitalWrite(GPIO4, LOW);
pinMode(GPIO5, OUTPUT); digitalWrite(GPIO5, LOW);
pinMode(GPIO12, OUTPUT); digitalWrite(GPIO12, LOW);
pinMode(GPIO13, OUTPUT); digitalWrite(GPIO13, LOW);
pinMode(GPIO14, OUTPUT); digitalWrite(GPIO14, LOW);
pinMode(GPIO15, OUTPUT); digitalWrite(GPIO15, LOW);
pinMode(GPIO16, OUTPUT); digitalWrite(GPIO16, LOW);
pinMode(GPIO17, OUTPUT); digitalWrite(GPIO17, LOW);
pinMode(GPIO18, OUTPUT); digitalWrite(GPIO18, LOW);
pinMode(GPIO19, OUTPUT); digitalWrite(GPIO19, LOW);
pinMode(GPIO21, OUTPUT); digitalWrite(GPIO21, LOW);
pinMode(GPIO22, OUTPUT); digitalWrite(GPIO22, LOW);
pinMode(GPIO23, OUTPUT); digitalWrite(GPIO23, LOW);
pinMode(GPIO25, OUTPUT); digitalWrite(GPIO25, LOW);
pinMode(GPIO26, OUTPUT); digitalWrite(GPIO26, LOW);
pinMode(GPIO27, OUTPUT); digitalWrite(GPIO27, LOW);
pinMode(GPIO32, OUTPUT); digitalWrite(GPIO32, LOW);
pinMode(GPIO33, OUTPUT); digitalWrite(GPIO33, LOW);
pinMode(GPIO34, OUTPUT); digitalWrite(GPIO34, LOW);
pinMode(GPIO35, OUTPUT); digitalWrite(GPIO35, LOW);
pinMode(GPIO36, OUTPUT); digitalWrite(GPIO36, LOW);
pinMode(GPIO39, OUTPUT); digitalWrite(GPIO39, LOW);

// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.print("WiFi connected. IP:");
Serial.println(WiFi.localIP());
server.begin();
}

void loop(){
WiFiClient client = server.available(); // Listen for incoming clients

if (client) { // If a new client connects,
currentTime = millis();
previousTime = currentTime;
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
currentTime = millis();
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();

//GESTIONE COMANDI DA BROWSER
if (header.indexOf("GET /GPIO1/on") >= 0) { GPIO1_state = true; digitalWrite(GPIO1, HIGH);}
else if (header.indexOf("GET /GPIO1/off") >= 0) {GPIO1_state = false; digitalWrite(GPIO1, LOW); }
else if (header.indexOf("GET /GPIO2/on") >= 0) { GPIO2_state = true; digitalWrite(GPIO2, HIGH);}
else if (header.indexOf("GET /GPIO2/off") >= 0) {GPIO2_state = false; digitalWrite(GPIO2, LOW); }
else if (header.indexOf("GET /GPIO3/on") >= 0) { GPIO3_state = true; digitalWrite(GPIO3, HIGH);}
else if (header.indexOf("GET /GPIO3/off") >= 0) {GPIO3_state = false; digitalWrite(GPIO3, LOW); }
else if (header.indexOf("GET /GPIO4/on") >= 0) { GPIO4_state = true; digitalWrite(GPIO4, HIGH);}
else if (header.indexOf("GET /GPIO4/off") >= 0) {GPIO4_state = false; digitalWrite(GPIO4, LOW); }
else if (header.indexOf("GET /GPIO5/on") >= 0) { GPIO5_state = true; digitalWrite(GPIO5, HIGH);}
else if (header.indexOf("GET /GPIO5/off") >= 0) {GPIO5_state = false; digitalWrite(GPIO5, LOW); }
else if (header.indexOf("GET /GPIO12/on") >= 0) { GPIO12_state = true; digitalWrite(GPIO12, HIGH);}
else if (header.indexOf("GET /GPIO12/off") >= 0) {GPIO12_state = false; digitalWrite(GPIO12, LOW); }
else if (header.indexOf("GET /GPIO13/on") >= 0) { GPIO13_state = true; digitalWrite(GPIO13, HIGH);}
else if (header.indexOf("GET /GPIO13/off") >= 0) {GPIO13_state = false; digitalWrite(GPIO13, LOW); }
else if (header.indexOf("GET /GPIO14/on") >= 0) { GPIO14_state = true; digitalWrite(GPIO14, HIGH);}
else if (header.indexOf("GET /GPIO14/off") >= 0) {GPIO14_state = false; digitalWrite(GPIO14, LOW); }
else if (header.indexOf("GET /GPIO15/on") >= 0) { GPIO15_state = true; digitalWrite(GPIO15, HIGH);}
else if (header.indexOf("GET /GPIO15/off") >= 0) {GPIO15_state = false; digitalWrite(GPIO15, LOW); }
else if (header.indexOf("GET /GPIO16/on") >= 0) { GPIO16_state = true; digitalWrite(GPIO16, HIGH);}
else if (header.indexOf("GET /GPIO16/off") >= 0) {GPIO16_state = false; digitalWrite(GPIO16, LOW); }
else if (header.indexOf("GET /GPIO17/on") >= 0) { GPIO17_state = true; digitalWrite(GPIO17, HIGH);}
else if (header.indexOf("GET /GPIO17/off") >= 0) {GPIO17_state = false; digitalWrite(GPIO17, LOW); }
else if (header.indexOf("GET /GPIO18/on") >= 0) { GPIO18_state = true; digitalWrite(GPIO18, HIGH);}
else if (header.indexOf("GET /GPIO18/off") >= 0) {GPIO18_state = false; digitalWrite(GPIO18, LOW); }
else if (header.indexOf("GET /GPIO19/on") >= 0) { GPIO19_state = true; digitalWrite(GPIO19, HIGH);}
else if (header.indexOf("GET /GPIO19/off") >= 0) {GPIO19_state = false; digitalWrite(GPIO19, LOW); }
else if (header.indexOf("GET /GPIO21/on") >= 0) { GPIO21_state = true; digitalWrite(GPIO21, HIGH);}
else if (header.indexOf("GET /GPIO21/off") >= 0) {GPIO21_state = false; digitalWrite(GPIO21, LOW); }
else if (header.indexOf("GET /GPIO22/on") >= 0) { GPIO22_state = true; digitalWrite(GPIO22, HIGH);}
else if (header.indexOf("GET /GPIO22/off") >= 0) {GPIO22_state = false; digitalWrite(GPIO22, LOW); }
else if (header.indexOf("GET /GPIO23/on") >= 0) { GPIO23_state = true; digitalWrite(GPIO23, HIGH);}
else if (header.indexOf("GET /GPIO23/off") >= 0) {GPIO23_state = false; digitalWrite(GPIO23, LOW); }
else if (header.indexOf("GET /GPIO25/on") >= 0) { GPIO25_state = true; digitalWrite(GPIO25, HIGH);}
else if (header.indexOf("GET /GPIO25/off") >= 0) {GPIO25_state = false; digitalWrite(GPIO25, LOW); }
else if (header.indexOf("GET /GPIO26/on") >= 0) { GPIO26_state = true; digitalWrite(GPIO26, HIGH);}
else if (header.indexOf("GET /GPIO26/off") >= 0) {GPIO26_state = false; digitalWrite(GPIO26, LOW); }
else if (header.indexOf("GET /GPIO27/on") >= 0) { GPIO27_state = true; digitalWrite(GPIO27, HIGH);}
else if (header.indexOf("GET /GPIO27/off") >= 0) {GPIO27_state = false; digitalWrite(GPIO27, LOW); }
else if (header.indexOf("GET /GPIO32/on") >= 0) { GPIO32_state = true; digitalWrite(GPIO32, HIGH);}
else if (header.indexOf("GET /GPIO32/off") >= 0) {GPIO32_state = false; digitalWrite(GPIO32, LOW); }
else if (header.indexOf("GET /GPIO33/on") >= 0) { GPIO33_state = true; digitalWrite(GPIO33, HIGH);}
else if (header.indexOf("GET /GPIO33/off") >= 0) {GPIO33_state = false; digitalWrite(GPIO33, LOW); }
else if (header.indexOf("GET /GPIO34/on") >= 0) { GPIO34_state = true; digitalWrite(GPIO34, HIGH);}
else if (header.indexOf("GET /GPIO34/off") >= 0) {GPIO34_state = false; digitalWrite(GPIO34, LOW); }
else if (header.indexOf("GET /GPIO35/on") >= 0) { GPIO35_state = true; digitalWrite(GPIO35, HIGH);}
else if (header.indexOf("GET /GPIO35/off") >= 0) {GPIO35_state = false; digitalWrite(GPIO35, LOW); }
else if (header.indexOf("GET /GPIO36/on") >= 0) { GPIO36_state = true; digitalWrite(GPIO36, HIGH);}
else if (header.indexOf("GET /GPIO36/off") >= 0) {GPIO36_state = false; digitalWrite(GPIO36, LOW); }
else if (header.indexOf("GET /GPIO39/on") >= 0) { GPIO39_state = true; digitalWrite(GPIO39, HIGH);}
else if (header.indexOf("GET /GPIO39/off") >= 0) {GPIO39_state = false; digitalWrite(GPIO39, LOW); }

// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");

client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 10px 20px;");
client.println("text-decoration: none; font-size: 15px; margin: 1px; cursor: pointer;}");
client.println(".button2 {background-color: #555555;}</style></head>");

client.println("<body><h1>ELETTRONICAOPENSOURCE EXAMPLE: ESP32 Web Server</h1>");

client.println("<div style=\"text-align: center;\"> ");
client.println("<table border=\"2\" style=\"height: 63px; width: 100%; border-collapse: collapse; float: left;\">");
client.println("<tbody><tr style=\"height: 31px;\"> ");
client.println("<td style=\"width: 160.0px; height: 31px; text-align: left;\"><p>-</p> ");
client.println("</td><td style=\"width: 160.0px; height: 31px;\" rowspan=\"13\"> ");
client.println("<p style=\"text-align: center;\"><strong>ESP32</strong></p> ");
client.println("<p style=\"text-align: center;\"><strong>DEV KIT1</strong></p> ");
client.println("</td><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO23 ");
if (GPIO23_state==false) {client.println(GPIO_string + "23" + LEDON_string);
} else { client.println(GPIO_string + "23" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 31px;\"><td style=\"width: 160.0px; height: 31px; text-align: center;\"><p>GPIO36 ");
if (GPIO36_state==false) {client.println(GPIO_string + "36" + LEDON_string);
} else { client.println(GPIO_string + "36" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO22 ");
if (GPIO22_state==false) {client.println(GPIO_string + "22" + LEDON_string);
} else { client.println(GPIO_string + "22" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 21px;\"><td style=\"width: 160.0px; height: 21px; text-align: center;\">GPIO39 ");
if (GPIO39_state==false) {client.println(GPIO_string + "39" + LEDON_string);
} else { client.println(GPIO_string + "39" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 21px; text-align: center;\">GPIO1 ");
if (GPIO1_state==false) {client.println(GPIO_string + "1" + LEDON_string);
} else { client.println(GPIO_string + "1" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 21px;\"><td style=\"width: 160.0px; height: 21px; text-align: center;\">GPIO34 ");
if (GPIO34_state==false) {client.println(GPIO_string + "34" + LEDON_string);
} else { client.println(GPIO_string + "34" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 21px; text-align: center;\">GPIO3 ");
if (GPIO3_state==false) {client.println(GPIO_string + "3" + LEDON_string);
} else { client.println(GPIO_string + "3" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 21px;\"><td style=\"width: 160.0px; height: 21px; text-align: center;\">GPIO35 ");
if (GPIO35_state==false) {client.println(GPIO_string + "35" + LEDON_string);
} else { client.println(GPIO_string + "35" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 21px; text-align: center;\">GPIO21 ");
if (GPIO21_state==false) {client.println(GPIO_string + "21" + LEDON_string);
} else { client.println(GPIO_string + "21" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 31px;\"><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO32 ");
if (GPIO32_state==false) {client.println(GPIO_string + "32" + LEDON_string);
} else { client.println(GPIO_string + "32" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 31px; text-align: centerft;\">GPIO19 ");
if (GPIO19_state==false) {client.println(GPIO_string + "19" + LEDON_string);
} else { client.println(GPIO_string + "19" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 31px;\"><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO33 ");
if (GPIO33_state==false) {client.println(GPIO_string + "33" + LEDON_string);
} else { client.println(GPIO_string + "33" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO18 ");
if (GPIO18_state==false) {client.println(GPIO_string + "18" + LEDON_string);
} else { client.println(GPIO_string + "18" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 31px;\"><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO25 ");
if (GPIO25_state==false) {client.println(GPIO_string + "25" + LEDON_string);
} else { client.println(GPIO_string + "25" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO5 ");
if (GPIO5_state==false) {client.println(GPIO_string + "5" + LEDON_string);
} else { client.println(GPIO_string + "5" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 31px;\"><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO26 ");
if (GPIO26_state==false) {client.println(GPIO_string + "26" + LEDON_string);
} else { client.println(GPIO_string + "26" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO17 ");
if (GPIO17_state==false) {client.println(GPIO_string + "17" + LEDON_string);
} else { client.println(GPIO_string + "17" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 31px;\"><td style=\"width: 160.0px; height: 31px; text-align: centereft;\">GPIO27 ");
if (GPIO27_state==false) {client.println(GPIO_string + "27" + LEDON_string);
} else { client.println(GPIO_string + "27" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO16 ");
if (GPIO16_state==false) {client.println(GPIO_string + "16" + LEDON_string);
} else { client.println(GPIO_string + "16" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 31px;\"><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO14 ");
if (GPIO14_state==false) {client.println(GPIO_string + "14" + LEDON_string);
} else { client.println(GPIO_string + "14" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 31px; text-align: lecenterft;\">GPIO4 ");
if (GPIO4_state==false) {client.println(GPIO_string + "4" + LEDON_string);
} else { client.println(GPIO_string + "4" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 31px;\"><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO12 ");
if (GPIO12_state==false) {client.println(GPIO_string + "12" + LEDON_string);
} else { client.println(GPIO_string + "12" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO2 ");
if (GPIO2_state==false) {client.println(GPIO_string + "2" + LEDON_string);
} else { client.println(GPIO_string + "2" + LEDOFF_string); }

client.println("</td></tr><tr style=\"height: 31px;\"><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO13 ");
if (GPIO13_state==false) {client.println(GPIO_string + "13" + LEDON_string);
} else { client.println(GPIO_string + "13" + LEDOFF_string); }

client.println("</td><td style=\"width: 160.0px; height: 31px; text-align: center;\">GPIO15");
if (GPIO13_state==false) {client.println(GPIO_string + "15" + LEDON_string);
} else { client.println(GPIO_string + "15" + LEDOFF_string); }

client.println("</td></tr></tbody></table></div>");
client.println("<div style=\"text-align: center;\"><p></p><p><text>Elettronica Oper Source Example</text>");
client.println("</p></div><div><p style=\"text-align: center;\">by Daniele Valanzuolo</p></div><div><p></p></div>");

client.println();
break;
} else { 
currentLine = "";
}
} else if (c != '\r') { 
currentLine += c; 
}
}
}

header = "";

client.stop();

}
}

[...]

ATTENZIONE: quello che hai appena letto è solo un estratto, l'Articolo Tecnico completo è composto da ben 4377 parole ed è riservato agli ABBONATI. Con l'Abbonamento avrai anche accesso a tutti gli altri Articoli Tecnici che potrai leggere in formato PDF per un anno. ABBONATI ORA, è semplice e sicuro.

Scarica subito una copia gratis

Scrivi un commento

Seguici anche sul tuo Social Network preferito!

Send this to a friend