Send data App to esp32
Posted: Tue Oct 23, 2018 8:23 pm
Hi everybody!
I ask your help because it's been a while since I can not find the solution.
my project is to make an aerothermal panel with autonomous management (esp32). I am at the stage where I created a wifi access point server with the Asyncwebserver method.
I can get on my smartphone information esp32 and I show them in the app.
Only the app is also used to change the thermostat setpoint via 2 buttons. This is where I can not recover this value when one of the two buttons is pressed.
In my head, I see things like this:
info_pan (esp32) -> Server -> app
For this one, in the setup () I insert the function:
And in loop(), i update info_pan when values change.
But how i must do for retrieve value of thermostat in the direction :
thermostat_update(app) -> Server -> esp32
i tried a lot of solutions but i don't find the good.
the method that I thought was good was:
in the setup():
and in loop()
thermostat_update=getrequest(/app)?
I don't arrive to formulate the request.
I need a concrete example. I found examples with html pages but I think it's different in syntax.
maybe the solution?
thank you for taking the time to read my problem
I ask your help because it's been a while since I can not find the solution.
my project is to make an aerothermal panel with autonomous management (esp32). I am at the stage where I created a wifi access point server with the Asyncwebserver method.
I can get on my smartphone information esp32 and I show them in the app.
Only the app is also used to change the thermostat setpoint via 2 buttons. This is where I can not recover this value when one of the two buttons is pressed.
In my head, I see things like this:
info_pan (esp32) -> Server -> app
For this one, in the setup () I insert the function:
Code: Select all
server.on ("/ esp32", HTTP_GET, [] (AsyncWebServerRequest * request)
{request-> send (200, "text / plain", info_pan);});
But how i must do for retrieve value of thermostat in the direction :
thermostat_update(app) -> Server -> esp32
i tried a lot of solutions but i don't find the good.
the method that I thought was good was:
in the setup():
Code: Select all
server.on ("/ app", HTTP_GET, [] (AsyncWebServerRequest * request)
{request-> send (200, "text / plain", thermostat_update);});
thermostat_update=getrequest(/app)?
I don't arrive to formulate the request.
I need a concrete example. I found examples with html pages but I think it's different in syntax.
maybe the solution?
thank you for taking the time to read my problem
Code: Select all
#include <OneWire.h> // Gestion des ds18b20 sur 1 bus
#include <DallasTemperature.h> // Récupération des infos des ds18b20
#include <CheapStepper.h> // Gestion du moteur pas à pas 28BYJ-48 5v ( p=64 et p/tr=64 )
#include <WiFi.h> // Pour l'utilisation du WiFi et la création du point d'accès
#include <ESPAsyncWebServer.h> // Pour la création du serveur HTTP
//#include <FS.h>
//#include <AsyncTCP.h>
/*** -------------------------------------------- WIFI ------------------------------------------- ***/
const char *ssid = "PAN_1"; // Déclaration du nom du réseau (SSID)
const char *password = "12345678"; // Et de son mot de passe (dans le cas où il est crypté
AsyncWebServer server(80); // Port par défaut d'un serveur HTTP
String info_pan = ""; // Récupère toutes les données à envoyer à l'application
String thermostat_update = "23.00"; // Récupère l'actualisation du thermostat par l'application
/*** -------------------------------------------- TEMP ------------------------------------------- ***/
OneWire ds(13); // Pin digital sur lequel sont connectées toutes les DS18B20
DallasTemperature sensors(&ds); // Fonction de récupération des données des DS18B20
DeviceAddress inDS = { 0x28, 0x7E, 0x1C, 0x39, 0x06, 0x00, 0x00, 0xC2 }; //Adresses uniques des ds18b20
DeviceAddress outDS = { 0x28, 0xA5, 0xE7, 0xDD, 0x06, 0x00, 0x00, 0x6F }; //récup : one_wire_address_finder
DeviceAddress panDS = { 0x28, 0xB3, 0xF8, 0x3A, 0x06, 0x00, 0x00, 0x5A };
float Tpan = 0; // Température du panneau
float Tout = 0; // Température extérieure
float Tin = 0; // Température intérieure
float TH = 23.0; // Valeur par défaut du thermostat
int HUM = 0; // Capteur Humidité
/*** -------------------------------------------- FAN -------------------------------------------- ***/
#define CHANNEL_FAN_PWM 0 // Le canal pwm. Il y a 16 canaux (0-15)
#define RES_BIT 8 // La résolution (8bits)
#define BASE_FREQ 12000 // La fréquence de base en Hz
#define PIN_FAN_PWM 16 // Port sur lequel est connecté la broche pwm du ventilateur
int PWM = 0; // Vitesse du ventilateur (0-255)
String ETAT = "Arrêt"; // Etat du ventilateur : Marche/Arrêt
/*** -------------------------------------- MOTEUR PAS A PAS ------------------------------------- ***/
CheapStepper stepper; // Variable récupérant la valeur du pas du moteur
boolean moveClockwise = true; // Variable définissant le sens de rotation du moteur
/*********************************************************************************************************/
/*** ledcAnalogWrite() ***/
/*********************************************************************************************************/
uint32_t min(uint32_t num1, uint32_t num2){ if(num1 < num2){ return num1; }else{ return num2; } }
void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255)
{
uint32_t duty = (255 / valueMax) * min(value, valueMax); // pour calculer duty, 255 = 2 ^ 8bits - 1
ledcWrite(channel, duty); // enregistre la valeur de duty
}
/*********************************************************************************************************/
/******************** SETUP() ********************/
/*********************************************************************************************************/
void setup()
{
Serial.begin(115200); // Activation de la liaison série
WiFi.softAP(ssid, password); // Appel de la fonction de création du réseau AccessPoint
Serial.println(WiFi.softAPIP()); // Affichage de l'adresse IP de l'ESP32
sensors.begin(); // Activation des sondes DS18B20
sensors.setResolution(panDS, 11); // On précise que la résolution 'r' des sondes sera de 11 bits
sensors.setResolution(outDS, 11); // 9: r=0.5°C, 10: r=0.25°C, 11: r=0.125°C, 12: r=0.0625°C
sensors.setResolution(inDS, 11); // Mais la précision sera pour tous +/- 0.5°C
pinMode(PIN_FAN_PWM, OUTPUT); // Paramétrage du sens de communication du pin du ventilateur
ledcSetup(CHANNEL_FAN_PWM, BASE_FREQ, RES_BIT); // Paramétrage PWM
ledcAttachPin(PIN_FAN_PWM, CHANNEL_FAN_PWM);
server.on("/esp32", HTTP_GET, [](AsyncWebServerRequest *request) // Serveur récupère les infos esp32
{request->send(200, "text/plain", info_pan);});
server.on("/app", HTTP_GET, [](AsyncWebServerRequest *request) // Serveur récupère thermostat_update
{request->send(200, "text/plain", thermostat_update);});
server.begin(); // Démarrage du serveur
}
/*********************************************************************************************************/
/******************** LOOP() ********************/
/*********************************************************************************************************/
void loop()
{
float tempIn; // Variables de comparaison des températures
float tempPan;
float tempOut;
sensors.requestTemperatures(); // Récupération des températures
tempPan = sensors.getTempC(panDS); // Allocation des températures aux variables
tempOut = sensors.getTempC(outDS);
tempIn = sensors.getTempC(inDS);
if(Tin!=tempIn) {Tin = tempIn;} // Actualisation si différentes après comparaison
if(Tpan!=tempPan) {Tpan = tempPan;}
if(Tout!=tempOut) {Tout = tempOut;}
Serial.println(Tout);
Serial.println(Tpan);
Serial.println(Tin);
info_pan = String(Tout)+"_"+String(Tpan)+"_"+String(Tin)+"_"+ETAT+"_"+String(HUM)+"_"+String(TH);
Serial.println(info_pan);
thermostat_update=?????????
delay(5000);
}