Guest User

AP

a guest
Jun 8th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <AsyncTCP.h>
  3. #include <ESPAsyncWebServer.h>
  4. #include <LiquidCrystal_I2C.h> // LCD header file
  5. #include <WiFi.h>
  6. #include <WiFiClient.h>
  7.  
  8. int lcdColumns = 20;
  9. int lcdRows = 2;
  10.  
  11. LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
  12. AsyncWebServer server(80);
  13.  
  14. // Enter your netwrok credentials
  15. const char* ssid = "Cenovka Krabec";
  16. const char* password = "kovomat";
  17. const char* PARAM_INPUT_1 = "data_field1";
  18. const char* PARAM_INPUT_2 = "data_field2";
  19.  
  20. // HTML web page to handle data input fields
  21.  
  22. const char index_html[] PROGMEM = R"rawliteral(<!DOCTYPE HTML> <html> <head><title> Cenovka </title><meta name = "viewport" content="width=device-width, initial-scale=1" "utf-8">
  23. <style>html{font-family: Calibri; display: inline-block; text-align: justify; Content-Type: text/html;charset=UTF-8}</style></head> <body><h2>Cenovka</h2><form action="/get">
  24. 1. radek <input type="text" name="data_field1" ><input type="submit" value="Poslat"></form> <br><form action="/get">2. radek <input type="text" name="data_field2"><input type="submit" value="Poslat">
  25. </form><br><br>Vsechen text musi byt <b>bez</b> diakritiky!</body></html>)rawliteral";
  26.  
  27. void notFound(AsyncWebServerRequest* request) {
  28. request->send(404, "text/plain", "Not found");
  29. }
  30.  
  31. void printOnLine(int line, String message) {
  32. lcd.setCursor(0, line);
  33. // % : print a variable
  34. // - : left justify
  35. // * : use lcdColumns as minimum width (pad with spaces)
  36. // s : it's a string type
  37. lcd.printf("%-*s", lcdColumns, message.c_str());
  38. Serial.printf("line %d : %-*s\n", line, lcdColumns, message.c_str()); // < prints to serial also
  39. }
  40.  
  41. void setup() {
  42. // put your setup code here, to run once:
  43. Serial.begin(115200);
  44. WiFi.mode(WIFI_AP);
  45. WiFi.softAP(ssid, password);
  46. }
  47. IPAddress IP = WiFi.softAPIP();
  48. Serial.println();
  49. Serial.print("IP Address: ");
  50. Serial.println(IP);
  51.  
  52. //===set LCD
  53. lcd.init();
  54. server.begin();
  55.  
  56. server.onNotFound(notFound);
  57. // Send web page with input fields to client
  58. server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
  59. request->send(200, "text/html", index_html);
  60. });
  61. // respond to GET
  62. server.on("/get", HTTP_GET, [](AsyncWebServerRequest* request) {
  63. String inputMessage;
  64. String inputParam;
  65. if (request->hasParam(PARAM_INPUT_1)) {
  66. printOnLine(0, request->getParam(PARAM_INPUT_1)->value());
  67. } else if (request->hasParam(PARAM_INPUT_2)) {
  68. printOnLine(1, request->getParam(PARAM_INPUT_2)->value());
  69. } else {
  70. // no message sent
  71. }
  72. request->send(200, "text/html", " HTTP GET request sent to ESP32(" + inputParam + "): " + inputMessage + "<br><a href=\"/\"> Back to Home Page </a>");
  73. });
  74. }
  75.  
  76. void loop() {
  77. // put your main code here, to run repeatedly:
  78. }
Advertisement
Add Comment
Please, Sign In to add comment