Hola amigos! estoy trabajando en un proyecto para poder medir el receptaculo o tanque del aire acondicionado y necesito poder guardar en una variable un dato ingresado desde un frontend. El frontend ya lo tengo pero no puedo y no se como guardar la variable. Esta variable la quiero usar para luego informar donde esta ubicado el aire acondicionado que está reportando. Aca les dejo el codigo.
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#define BOTtoken ""
#define Chat_ID ""
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
const int sensorPin = A0;
int liquid_level;
ESP8266WebServer server(80); // Create a webserver object that listens for HTTP request on port 80
const char MAIN_page[] PROGMEM = R"=====(
Sensor Nivel Aire Acondicionado
Ingrese los siguientes datos
Ubicacion Aire Acondicionado (Habitacion, cocina, etc):
)=====";
//===============================================================
// This routine is executed when you open its IP in browser
//===============================================================
void handleRoot() {
String s = MAIN_page; //Read HTML contents
server.send(200, "text/html", s); //Send web page
}
//===============================================================
// This routine is executed when you press submit
//===============================================================
void handleForm() {
String ubicacionAire = server.arg("ubicacion");
Serial.print("Ubicacion Aire:");
Serial.println(ubicacionAire);
String s = " Gracias! Su configuracion se realizo con exito! ";
server.send(200, "text/html", s);
}
void setup() {
Serial.begin(115200);
delay(10);
Serial.println('\n');
pinMode(sensorPin, INPUT);
// WiFiManager
// Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
// Uncomment and run it once, if you want to erase all the stored information
//wifiManager.resetSettings();
// set custom ip for portal
//wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
// fetches ssid and pass from eeprom and tries to connect
// if it does not connect it starts an access point with the specified name
// here "AutoConnectAP"
// and goes into a blocking loop awaiting configuration
wifiManager.autoConnect("AutoConnectAP");
// or use this for auto generated name ESP + ChipID
// if you get here you have connected to the WiFi
Serial.println("Connected.");
liquid_level = analogRead(sensorPin);
Serial.println(liquid_level);
if (liquid_level >= 0 and liquid_level <= 89) {
Serial.println("El tanque del aire acondicionado esta ok!");
Serial.println("El tanque del aire acondicionado esta ok!");
client.setInsecure();
bot.sendMessage(Chat_ID, "El tanque del aire acondicionado esta ok!", "");
}
if (liquid_level >= 90 and liquid_level <= 512) {
Serial.println("ATENCION!!! El nivel de agua del tanque del aire acondicionado se esta llenando.");
Serial.println("ATENCION!!! El nivel de agua del tanque del aire acondicionado se esta llenando.");
client.setInsecure();
bot.sendMessage(Chat_ID, "ATENCION!!! El nivel de agua del tanque del aire acondicionado se esta llenando.", "");
}
server.on("/", handleRoot); //Which routine to handle at root location
server.on("/action_page", handleForm); //form action is handled here
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}
