Created
July 2, 2022 21:27
-
-
Save wesleyguirra/221864a2f0152317dcf83fd2b4ee555b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <SPI.h> | |
//#####################################// | |
const char* ssid = "NOME_REDE_WIFI"; | |
const char* password = "SENHA_REDE_WIFI"; | |
String readString; | |
char c; | |
int sensor1 = 16; | |
int sensor2 = 5; | |
int sensor3 = 4; | |
WiFiServer server(80); | |
//#####################################// | |
void setup() { | |
pinMode(sensor1,INPUT); | |
pinMode(sensor2,INPUT); | |
pinMode(sensor3,INPUT); | |
Serial.begin(115200); | |
delay(10); | |
Serial.print("Conectando na rede: "); | |
Serial.println(ssid); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi Conectada"); | |
server.begin(); | |
Serial.println("Servidor iniciado!"); | |
Serial.print("Endereço IP: "); | |
Serial.println(WiFi.localIP()); | |
} | |
void loop() { | |
//####################################################################################// | |
WiFiClient client = server.available(); | |
if (client) { | |
boolean currentLineIsBlank = true; | |
while (client.connected()) { | |
if (client.available()) { | |
char c = client.read(); | |
if (readString.length() < 100) { | |
readString += c; | |
} | |
if (c == '\r') { | |
String buf = ""; | |
buf += "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n"; | |
buf += "<meta HTTP-EQUIV=\"refresh\" CONTENT=\"5\">"; | |
buf += "<html>"; | |
buf += "<head>"; | |
buf += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-2\" />"; | |
buf += "<meta name='viewport' content='width=device-width,minimum-scale=1.0,maximum-scale=1.0'>"; | |
buf += "<table align=\"center\" width=\"200\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; | |
buf += "<tr>"; | |
buf += "<td align=\"center\"><p><font face=\"Verdana\" size=\"3\">CONTROLE DE NÍVEL D'AGUA<br />"; | |
buf += "NODEMCU<br />"; | |
buf += "SENSOR BÓIA NÍVEL D'AGUA</font></p><br /><br /></td>"; | |
buf += "</tr>"; | |
buf += "</table>"; | |
buf += "<table align=\"center\" width=\"200\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" style=\"border-left:solid; border-right:solid; border-top:solid; border-bottom:solid; border-width:1px; border-color:#009;\">"; | |
buf += "<tbody>"; | |
buf += "<tr>"; | |
if(digitalRead(sensor1) == 0){ | |
buf += "<td height=\"50\"><center><font face=\"Verdana\" size=\"3\">Nivel Maximo</font></center></td>"; | |
}else{ | |
buf += "<td height=\"50\" bgcolor=\"#0067BC\"><center><font face=\"Verdana\" size=\"3\" color=\"#FFFFFF\">Nivel Maximo</font></center></td>"; | |
} | |
buf += "</tr>"; | |
buf += "<tr>"; | |
if(digitalRead(sensor2) == 0){ | |
buf += "<td height=\"50\"><center><font face=\"Verdana\" size=\"3\">Nivel Medio</font></center></td>"; | |
}else{ | |
buf += "<td height=\"50\" bgcolor=\"#0067BC\"><center><font face=\"Verdana\" size=\"3\" color=\"#FFFFFF\">Nivel Medio</font></center></td>"; | |
} | |
buf += "</tr>"; | |
buf += "<tr>"; | |
if(digitalRead(sensor3) == 0){ | |
buf += "<td height=\"50\"><center><font face=\"Verdana\" size=\"3\">Nivel Baixo</font></center></td>"; | |
}else{ | |
buf += "<td height=\"50\" bgcolor=\"#0067BC\"><center><font face=\"Verdana\" size=\"3\" color=\"#FFFFFF\">Nivel Baixo</font></center></td>"; | |
} | |
buf += "</tr>"; | |
buf += "</tbody>"; | |
buf += "</table>"; | |
buf += "</body>"; | |
buf += "</html>"; | |
client.print(buf); | |
client.flush(); | |
client.stop(); | |
readString=""; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment