Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- IPAddress ip(192, 168, 2, 2);
- IPAddress gateway(192, 168, 2, 1);
- IPAddress subnet(255, 255, 255, 0);
- IPAddress dns(192,168, 2, 209);
- const char* ssid = "Ju";
- const char* password = "Pizza123";
- WiFiServer server(80);
- const char INDEX_HTML[] =
- "<!DOCTYPE HTML>"
- "<html>"
- "<head>"
- "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
- "</head>"
- "<body>"
- "<FORM action=\"/\">"
- "Produto E Preco<br>"
- "<input type=\"text\" name=\"1\">"
- "<br>"
- "<input type=\"text\" name=\"2\">"
- "<br><br>"
- "<input type=\"submit\" value=\"Atualizar Etiqueta\">"
- "</FORM>"
- "</body>"
- "</html>";
- void setup() {
- Serial.begin(9600);
- delay(10);
- Serial.println();
- Serial.println();
- Serial.print("Conectando com ");
- Serial.println(ssid);
- WiFi.config(ip, dns, gateway, subnet);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi conectado");
- server.begin();
- Serial.print("Servidor iniciado em: ");
- Serial.println(WiFi.localIP());
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("AGUARDE");
- lcd.setCursor(0, 1);
- lcd.print("INICIANDO");
- }
- void loop() {
- WiFiClient client = server.available();
- if (!client) {
- return;
- }
- //Serial.println("Cliente encontrado");
- while(!client.available()){
- delay(1);
- }
- String request = client.readStringUntil('\r');
- //Serial.println(request);
- client.flush();
- if(request.indexOf("1=") != -1) {
- //request = request.replace("+", " ");
- String dados1 = request.substring(request.indexOf("1=") + 2, request.indexOf("2=") - 1);
- dados1.replace("+", " ");
- Serial.print("1 -");
- Serial.print(dados1);
- Serial.println("-");
- String dados2 = request.substring(request.indexOf("2=") + 2, request.indexOf("HTTP") - 1);
- dados2.replace("+", " ");
- Serial.print("2 -");
- Serial.print(dados2);
- Serial.println("-");
- lcd.setCursor(0, 0);
- lcd.print(dados1);
- lcd.setCursor(0, 1);
- lcd.print(dados2);
- }
- client.println("HTTP/1.1 200 OK");
- client.println("Connection: close");
- client.println("Content-Type: text/html");
- client.println("");
- client.println(INDEX_HTML);
- delay(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment