ajout de la foction de réveil par l'alimentation 1er essai
This commit is contained in:
parent
bc99f15ffa
commit
adee2411eb
|
@ -14,6 +14,7 @@
|
|||
#include <PubSubClient.h>
|
||||
#include <Pangodream_18650_CL.h>
|
||||
#include <secret.h>
|
||||
#include <RTClib.h>
|
||||
|
||||
#define TOPIC "test1"
|
||||
#define MQTT_ADDRESS "185.233.103.24"
|
||||
|
|
|
@ -19,3 +19,4 @@ lib_deps =
|
|||
ottowinter/ESPAsyncWebServer-esphome@^1.2.7
|
||||
ottowinter/AsyncTCP-esphome@^1.2.1
|
||||
arduino-libraries/NTPClient@^3.1.0
|
||||
adafruit/RTClib@^2.0.2
|
||||
|
|
56
src/main.cpp
56
src/main.cpp
|
@ -5,11 +5,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
<<<<<<< HEAD
|
||||
DHT sensors[SENSORS_NUMBER] = {DHT(4, DHT22), DHT(5, DHT22), DHT(18, DHT22), DHT(19, DHT22), DHT(21, DHT22)};
|
||||
=======
|
||||
DHT sensors[SENSORS_NUMBER] = {DHT(23, DHT22), DHT(22, DHT22), DHT(21, DHT22), DHT(17, DHT22), DHT(35, DHT22)};
|
||||
>>>>>>> e1180bef4e914976c20b61b18ae28328e17ae2af
|
||||
float temp[SENSORS_NUMBER];
|
||||
float hum[SENSORS_NUMBER];
|
||||
|
||||
|
@ -19,6 +15,10 @@ WiFiUDP NtpUDP;
|
|||
NTPClient TimeClient(NtpUDP, "europe.pool.ntp.org", 0, 60000);
|
||||
Pangodream_18650_CL Battery(ADC_PIN, CONV_FACTOR, READS);
|
||||
|
||||
RTC_DS3231 rtc;
|
||||
//---------------- Réveil --------------------//
|
||||
int mesure_freq = 600; // temps entre deux réveils en secondes
|
||||
|
||||
//-------------------- FONCTIONS --------------------//
|
||||
|
||||
//-------------- Connexion MQTT --------------//
|
||||
|
@ -83,7 +83,7 @@ void readSensors(DHT sensors[], float temp[], float hum[], int number)
|
|||
}
|
||||
|
||||
//-------------------- Sleep de l'ESP --------------------//
|
||||
|
||||
/*
|
||||
void sleep()
|
||||
{
|
||||
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * US_TO_S_FACTOR);
|
||||
|
@ -102,6 +102,50 @@ std::tuple<int, int, int> getDate()
|
|||
|
||||
return std::make_tuple(year, month, day);
|
||||
}
|
||||
*/
|
||||
|
||||
//-------------------- Programmation du réveil de l'alimentation --------------------//
|
||||
|
||||
void wakeup(){
|
||||
// initializing the rtc
|
||||
if(!rtc.begin()) {
|
||||
Serial.println("Couldn't find RTC!");
|
||||
Serial.flush();
|
||||
while (1) delay(10);
|
||||
}
|
||||
|
||||
if(rtc.lostPower()) {
|
||||
// this will adjust to the date and time at compilation
|
||||
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
|
||||
}
|
||||
|
||||
//we don't need the 32K Pin, so disable it
|
||||
rtc.disable32K();
|
||||
|
||||
// set alarm 1, 2 flag to false (so alarm 1, 2 didn't happen so far)
|
||||
// if not done, this easily leads to problems, as both register aren't reset on reboot/recompile
|
||||
rtc.clearAlarm(1);
|
||||
rtc.clearAlarm(2);
|
||||
|
||||
// stop oscillating signals at SQW Pin
|
||||
// otherwise setAlarm1 will fail
|
||||
rtc.writeSqwPinMode(DS3231_OFF);
|
||||
|
||||
// turn off alarm 2 (in case it isn't off already)
|
||||
// again, this isn't done at reboot, so a previously set alarm could easily go overlooked
|
||||
rtc.disableAlarm(2);
|
||||
|
||||
// schedule an alarm 10 seconds in the future
|
||||
if(!rtc.setAlarm1(
|
||||
rtc.now() + TimeSpan(mesure_freq),
|
||||
DS3231_A1_Second // this mode triggers the alarm when the seconds match. See Doxygen for other options
|
||||
)) {
|
||||
Serial.println("Error, alarm wasn't set!");
|
||||
}else {
|
||||
Serial.println("Alarm will happen in 10 seconds!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-------------------- Création de trames --------------------//
|
||||
|
||||
|
@ -179,6 +223,6 @@ void loop()
|
|||
|
||||
delay(2000);
|
||||
Serial.println("Extinction de l'ESP ! ");
|
||||
sleep();
|
||||
wakeup();
|
||||
|
||||
}
|
Loading…
Reference in a new issue