Bonjour à tous,
Je reprends ce topic sur lequel j'ai pu avancer mais où je bloque toujours sur la mise en veille le soir et le réveil le matin.
Je suis passé pour le moment au Wemos D1 Pro mini à la place de l'ESP32.
Pour l'émission en journée, le wemos D1 Pro mini ( se réveille toutes les 15 mn, se connecte au serveur Pioupiou via l'API, récupère les données, lance l'émission en VHF, passe le SA828 en "sleeping mode" en mettant à LOW sa broche 23(CS) et passe en deep sleep pour 15 mn.
Première question : En mode Deep sleep de l'ESP, est ce que la pin 7 qui est mise à LOW va conserver cette valeur jusqu'au réveil?
Deuxième question : Pour passer en mode deep sleep "nuit", j'aimerais le faire en mesurant la tension du panneau solaire par l'entrée analogique A0. Si elle est à 0 alors on passe en deep sleep. Mais comment faire pour réveiller l'ESP lorsque le panneau recommence à produire une tension alors que l'ESP est "endormie"?
Troisième question : Existe t'il une autre façon de procéder ?
Merci pour votre aide.
Mon code actuel :
/*
Rui Santos
Complete project details at Complete project details at https://RandomNerdTutorials.com/esp32-http-get-open-weather-map-thingspeak-arduino/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
//ref : http://tilman.de/projekte/wifi-doorbell/
//Pour ESP8266
//Par rapport à pioupiou_test1 : utilise ArduinoJson et son assistant;
//permet de recuperer les Floats pour les directions et vitesses du vent pour arrondir les valeurs
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include "SoftwareSerial.h"
#include <ArduinoJson.h>
const char* ssid = "Lxxxxxxxxxxxxxxx";
const char* password = "xxxxxxxxxxxxxxl";
//**********DFPLAYER***********
SoftwareSerial mySoftwareSerial(D3, D2); // DFPLAYER TX, RX
#include "DFRobotDFPlayerMini.h"
#define FOLDER_title 1
#define FOLDER_directions 2
#define FOLDER_speed 3
#define FOLDER_text 4
static unsigned long timer = millis();
int dir;
const int PTT = D5;
const int PIN_CS_SA828 = D7;
float data_measurements_wind_heading;
float data_measurements_wind_speed_avg;
float data_measurements_wind_speed_max;
int windSpeedAvg;
int readIndex;
int windSpeedMax;
int windHeading;
char *sectors[ ] = {"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N"};
String compassDir = "";
int number = 0;
const byte degres[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
DFRobotDFPlayerMini dfPlayer;
void printDetail(uint8_t type, int value);
//*************************************************
// THE DEFAULT TIMER IS SET TO 10 SECONDS FOR TESTING PURPOSES
// For a final application, check the API call limits per hour/minute to avoid getting blocked/banned
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 10 seconds (10000)
unsigned long timerDelay = 10000;
String json;
DynamicJsonDocument doc(1024);
void setup() {
mySoftwareSerial.begin(9600);
Serial.begin(115200);
pinMode(PIN_CS_SA828, OUTPUT);
pinMode(PTT, OUTPUT);
Serial.println("");
Serial.println("Sketch : balisePoupiou_Andran_D1ProMini.ino");
WiFi.begin(ssid, password);
Serial.println("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
Serial.println("Timer set to 10 seconds (timerDelay variable), it will take 10 seconds before publishing the first reading.");
//************DFPLAYER*************************
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!dfPlayer.begin(mySoftwareSerial)) {
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while (true);
}
Serial.println(F("DFPlayer Mini online."));
dfPlayer.setTimeOut(500);
dfPlayer.EQ(DFPLAYER_EQ_NORMAL);
dfPlayer.outputDevice(DFPLAYER_DEVICE_SD);
// dfPlayer.volume(8); //Set volume value. From 0 to 30
//********************************************************
// Send an HTTP GET request
// Check WiFi connection status
if (WiFi.status() == WL_CONNECTED) {
//WiFiClient client;
//HTTPClient http;
//String serverPath = "http://api.pioupiou.fr/v1/live/596";//Digne
//String serverPath = "http://api.pioupiou.fr/v1/live/594";//Le TRAINON
//String serverPath = "http://api.pioupiou.fr/v1/live/595";//Aiguines
String serverPath = "http://api.pioupiou.fr/v1/live/87";//Saint-Andre_Sud
json = httpGETRequest(serverPath.c_str());
Serial.println(json);
// Deserialize the JSON document
DeserializationError error = deserializeJson(doc, json);
// Test if parsing succeeds.
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}
JsonObject data = doc["data"];
int data_id = data["id"];
const char* data_meta_name = data["meta"]["name"];
JsonObject data_measurements = data["measurements"];
data_measurements_wind_heading = data_measurements["wind_heading"];
data_measurements_wind_speed_avg = data_measurements["wind_speed_avg"];
data_measurements_wind_speed_max = data_measurements["wind_speed_max"];
Serial.print("JSON object = "); Serial.println(data);
Serial.print("Balise : "); Serial.println(data_id);
Serial.print("BaliseName : "); Serial.println(data_meta_name);
Serial.print("WindHeading : "); Serial.println(data_measurements_wind_heading);
Serial.print("Direction : "); Serial.println(compassDir);
Serial.print("WindSpeedAvg : "); Serial.println(data_measurements_wind_speed_avg);
Serial.print("WindSpeedMax : "); Serial.println(data_measurements_wind_speed_max);
windSpeedAvg = round (data_measurements_wind_speed_avg);
windSpeedMax = round (data_measurements_wind_speed_max);
windHeading = round(data_measurements_wind_heading);
Serial.print("windSpeedAvg : "); Serial.println(windSpeedAvg);
Serial.print("windSpeedMax : "); Serial.println(windSpeedMax);
getHeading(windHeading);
digitalWrite(PIN_CS_SA828, HIGH);
Serial.println("PIN_CS_SA828 HIGHT");
digitalWrite(PTT, HIGH);
Serial.println("PPT HIGHT");
dfPlayer.volume(25);
delay(1000);
voice();
delay(1000);
digitalWrite(PTT, LOW);
digitalWrite(PIN_CS_SA828, LOW);
}
else {
Serial.println("WiFi Disconnected");
}
delay(1000);
ESP.deepSleep(900e6);
}
void loop() {
}
String httpGETRequest(const char* serverName) {
WiFiClient client;
HTTPClient http;
// Your IP address with path or Domain name with URL path
http.begin(client, serverName);
// Send HTTP POST request
int httpResponseCode = http.GET();
String payload = "{}";
if (httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
return payload;
}
void voice() {
Serial.println();
switch (number) {
case 0:
Serial.println(F("NORD"));
dir = 16;
break;
case 1:
Serial.println(F("NORD-NORD-EST"));
dir = 1;
break;
case 2:
Serial.println(F("NORD-EST"));
dir = 2;
break;
case 3:
Serial.println(F("EST-NORD-EST"));
dir = 3;
break;
case 4:
Serial.println(F("EST"));
dir = 4;
break;
case 5:
Serial.println(F("EST-SUD-EST"));
dir = 5;
break;
case 6:
Serial.println(F("SUD-EST"));
dir = 6;
break;
case 7:
Serial.println(F("SUD-SUD-EST"));
dir = 7;
break;
case 8:
Serial.println(F("SUD"));
dir = 8;
break;
case 9:
Serial.println(F("SUD-SUD-OUEST"));
dir = 9;
break;
case 10:
Serial.println(F("SUD-OUEST"));
dir = 10;
break;
case 11:
Serial.println(F("OUEST-SUD-OUEST"));
dir = 11;
break;
case 12:
Serial.println(F("OUEST"));
dir = 12;
break;
case 13:
Serial.println(F("OUEST-NORD-OUEST"));
dir = 13;
break;
case 14:
Serial.println(F("NORD-OUEST"));
dir = 14;
break;
case 15:
Serial.println(F("NORD-NORD-OUEST"));
dir = 15;
break;
case 16:
Serial.println(F("NORD"));
dir = 16;
break;
default:
break;
};
delay(1000);
dfPlayer.playFolder(FOLDER_title, 3);//St Andre
delay(1500);
dfPlayer.playFolder(FOLDER_directions, dir);
delay(1500);
dfPlayer.playFolder(FOLDER_speed, windSpeedAvg);
delay(1000);
dfPlayer.playFolder(FOLDER_text, 1);
delay(1000);
dfPlayer.playFolder(FOLDER_speed, windSpeedMax);
delay(1000);
dfPlayer.playFolder(FOLDER_text, 2);
if (dfPlayer.available()) {
printDetail(dfPlayer.readType(), dfPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
}
void getHeading(int direction) {
int index = windHeading % 360;//modulo
index = round(index / 22.5);
number = (degres[index]);
Serial.print("Number : "); Serial.println(number);
compassDir = (sectors[index]);
}
void printDetail(uint8_t type, int value) {
switch (type) {
case TimeOut:
Serial.println(F("Time Out!"));
break;
case WrongStack:
Serial.println(F("Stack Wrong!"));
break;
case DFPlayerCardInserted:
Serial.println(F("Card Inserted!"));
break;
case DFPlayerCardRemoved:
Serial.println(F("Card Removed!"));
break;
case DFPlayerCardOnline:
Serial.println(F("Card Online!"));
break;
case DFPlayerPlayFinished:
Serial.print(F("Number:"));
Serial.print(value);
Serial.println(F(" Play Finished!"));
break;
case DFPlayerError:
Serial.print(F("DFPlayerError:"));
switch (value) {
case Busy:
Serial.println(F("Card not found"));
break;
case Sleeping:
Serial.println(F("Sleeping"));
break;
case SerialWrongStack:
Serial.println(F("Get Wrong Stack"));
break;
case CheckSumNotMatch:
Serial.println(F("Check Sum Not Match"));
break;
case FileIndexOut:
Serial.println(F("File Index Out of Bound"));
break;
case FileMismatch:
Serial.println(F("Cannot Find File"));
break;
case Advertise:
Serial.println(F("In Advertise"));
break;
default:
break;
}
break;
default:
break;
}
}