levinoshow

lcd esp 8266

Oct 21st, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4.  
  5. LiquidCrystal_I2C lcd(0x27, 16, 2);
  6.  
  7. IPAddress ip(192, 168, 2, 2);
  8. IPAddress gateway(192, 168, 2, 1);
  9. IPAddress subnet(255, 255, 255, 0);
  10. IPAddress dns(192,168, 2, 209);
  11.  
  12. const char* ssid = "Ju";
  13. const char* password = "Pizza123";
  14.  
  15. WiFiServer server(80);
  16.  
  17. const char INDEX_HTML[] =
  18. "<!DOCTYPE HTML>"
  19. "<html>"
  20. "<head>"
  21. "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
  22. "</head>"
  23. "<body>"
  24. "<FORM action=\"/\">"
  25. "Produto E Preco<br>"
  26. "<input type=\"text\" name=\"1\">"
  27. "<br>"
  28. "<input type=\"text\" name=\"2\">"
  29. "<br><br>"
  30. "<input type=\"submit\" value=\"Atualizar Etiqueta\">"
  31. "</FORM>"
  32. "</body>"
  33. "</html>";
  34.  
  35. void setup() {
  36. Serial.begin(9600);
  37. delay(10);
  38.  
  39. Serial.println();
  40. Serial.println();
  41. Serial.print("Conectando com ");
  42. Serial.println(ssid);
  43.  
  44. WiFi.config(ip, dns, gateway, subnet);
  45. WiFi.begin(ssid, password);
  46.  
  47. while (WiFi.status() != WL_CONNECTED) {
  48. delay(500);
  49. Serial.print(".");
  50. }
  51. Serial.println("");
  52. Serial.println("WiFi conectado");
  53.  
  54. server.begin();
  55. Serial.print("Servidor iniciado em: ");
  56.  
  57. Serial.println(WiFi.localIP());
  58.  
  59. lcd.init();
  60. lcd.backlight();
  61.  
  62. lcd.setCursor(0, 0);
  63. lcd.print("AGUARDE");
  64. lcd.setCursor(0, 1);
  65. lcd.print("INICIANDO");
  66. }
  67.  
  68. void loop() {
  69.  
  70. WiFiClient client = server.available();
  71. if (!client) {
  72. return;
  73. }
  74.  
  75. //Serial.println("Cliente encontrado");
  76. while(!client.available()){
  77. delay(1);
  78. }
  79.  
  80. String request = client.readStringUntil('\r');
  81. //Serial.println(request);
  82. client.flush();
  83.  
  84. if(request.indexOf("1=") != -1) {
  85.  
  86. //request = request.replace("+", " ");
  87.  
  88. String dados1 = request.substring(request.indexOf("1=") + 2, request.indexOf("2=") - 1);
  89. dados1.replace("+", " ");
  90.  
  91. Serial.print("1 -");
  92. Serial.print(dados1);
  93. Serial.println("-");
  94.  
  95. String dados2 = request.substring(request.indexOf("2=") + 2, request.indexOf("HTTP") - 1);
  96. dados2.replace("+", " ");
  97.  
  98. Serial.print("2 -");
  99. Serial.print(dados2);
  100. Serial.println("-");
  101.  
  102. lcd.setCursor(0, 0);
  103. lcd.print(dados1);
  104. lcd.setCursor(0, 1);
  105. lcd.print(dados2);
  106. }
  107.  
  108. client.println("HTTP/1.1 200 OK");
  109. client.println("Connection: close");
  110. client.println("Content-Type: text/html");
  111. client.println("");
  112.  
  113. client.println(INDEX_HTML);
  114.  
  115. delay(1);
  116. }
Advertisement
Add Comment
Please, Sign In to add comment