[LPM] ESP8266 and DS1820 DeepSleep (#1591)
Add support for the ESP8266 deep sleep and required change for DS1820 sensor used in my project. Allow defining DS1820_RESOLUTION and DS1820_INTERVAL_SEC in ENVIRON without editing config file. Allow DTimeBetweenReadingmq2 Env. MACRO change without editing source config file. Added some an example ENVIRONMENTS Add ESP8266_DEEP_SLEEP_IN_US to nodemcuv2-all-test
This commit is contained in:
1 parent
ac0215b5be
commit
4e51d9ec45
8 files changed
+113
-8
No files matched your search
@@ -294,6 +294,16 @@ static_assert(MQTT_SECURE_SELF_SIGNED_INDEX_DEFAULT < (sizeof(certs_array) / siz
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Deep-sleep for the ESP8266.
|
||||
* Set the wake pin.
|
||||
*/
|
||||
#ifdef ESP8266_DEEP_SLEEP_IN_US
|
||||
# ifndef ESP8266_DEEP_SLEEP_WAKE_PIN
|
||||
# define ESP8266_DEEP_SLEEP_WAKE_PIN D0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*------------------DEEP SLEEP parameters ------------------*/
|
||||
//DEFAULT_LOW_POWER_MODE -1 to normal mode, low power mode can't be used on this build
|
||||
//DEFAULT_LOW_POWER_MODE 0 to normal mode (no power consumption optimisations)
|
||||
|
||||
@@ -162,6 +162,9 @@ void MeasureDS1820Temp() {
|
||||
Log.trace(F("DS1820: Temperature for device %s didn't change, don't publish it." CR), (char*)ds1820_addr[i].c_str());
|
||||
}
|
||||
persisted_temp[i] = current_temp[i];
|
||||
# ifdef ESP8266_DEEP_SLEEP_IN_US
|
||||
ready_to_sleep = true;
|
||||
# endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-7
@@ -33,13 +33,17 @@ extern void pubOneWire_HADiscovery();
|
||||
|
||||
/*----------------------------USER PARAMETERS-----------------------------*/
|
||||
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
||||
#define OW_TOPIC "/OneWiretoMQTT/ds1820"
|
||||
#define OW_MAX_SENSORS 8 // query max. sensors on 1-wire bus
|
||||
#define DS1820_ALWAYS true // if false only published current temperature if has changed from previous reading
|
||||
#define DS1820_INTERVAL_SEC 60UL // time between DS1820 readings (seconds)
|
||||
#define DS1820_RESOLUTION 10 // conversion times: 9 bit (93.75 ms), 10 bit (187.5 ms), 11 bit (375 ms), 12 bit (750 ms)
|
||||
#define DS1820_DETAILS true // publish extended info for each sensor (resolution, address, type)
|
||||
#define DS1820_CONV_TIME 2000UL // trigger conversion before requesting temperature readings (ms)
|
||||
#define OW_TOPIC "/OneWiretoMQTT/ds1820"
|
||||
#define OW_MAX_SENSORS 8 // query max. sensors on 1-wire bus
|
||||
#define DS1820_ALWAYS true // if false only published current temperature if has changed from previous reading
|
||||
#ifndef DS1820_INTERVAL_SEC
|
||||
# define DS1820_INTERVAL_SEC 60UL // time between DS1820 readings (seconds)
|
||||
#endif
|
||||
#ifndef DS1820_RESOLUTION
|
||||
# define DS1820_RESOLUTION 10 // conversion times: 9 bit (93.75 ms), 10 bit (187.5 ms), 11 bit (375 ms), 12 bit (750 ms)
|
||||
#endif
|
||||
#define DS1820_DETAILS true // publish extended info for each sensor (resolution, address, type)
|
||||
#define DS1820_CONV_TIME 2000UL // trigger conversion before requesting temperature readings (ms)
|
||||
/*-------------------PIN DEFINITIONS----------------------*/
|
||||
|
||||
#ifndef DS1820_OWBUS_GPIO
|
||||
|
||||
+3
-1
@@ -55,7 +55,9 @@ extern void MQ2toMQTT();
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define TimeBetweenReadingmq2 10000
|
||||
#ifndef TimeBetweenReadingmq2
|
||||
# define TimeBetweenReadingmq2 10000
|
||||
#endif
|
||||
/*----------------------------USER PARAMETERS-----------------------------*/
|
||||
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
||||
#define subjectMQ2toMQTT "/GAStoMQTT/mq2"
|
||||
|
||||
@@ -53,6 +53,14 @@ unsigned long timer_sys_checks = 0;
|
||||
# define ARDUINOJSON_ENABLE_STD_STRING 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Deep-sleep for the ESP8266 we need some form of indicator that we have posted the measurements and am ready to deep sleep.
|
||||
* Set this to true in the sensor code after publishing the measurement.
|
||||
*/
|
||||
#ifdef ESP8266_DEEP_SLEEP_IN_US
|
||||
bool ready_to_sleep = false;
|
||||
#endif
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoLog.h>
|
||||
#include <PubSubClient.h>
|
||||
@@ -771,6 +779,11 @@ void setup() {
|
||||
Log.notice(F("OpenMQTTGateway Version: " OMG_VERSION CR));
|
||||
# endif
|
||||
|
||||
# ifdef ESP8266_DEEP_SLEEP_IN_US
|
||||
Log.notice(F("Setting wake pin for deep sleep." CR));
|
||||
pinMode(ESP8266_DEEP_SLEEP_WAKE_PIN, WAKEUP_PULLUP);
|
||||
# endif
|
||||
|
||||
/*
|
||||
The 2 modules below are not connection dependent so start them before the connectivity functions
|
||||
Note that the ONOFF module need to start after the RN8209 so that the overCurrent task is launched after the setup of the sensor
|
||||
@@ -1779,6 +1792,17 @@ void loop() {
|
||||
#if defined(ZdisplaySSD1306)
|
||||
loopSSD1306();
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Deep-sleep for the ESP8266 - e.g. ESP8266_DEEP_SLEEP_IN_US 30000000 for 30 seconds.
|
||||
* Everything is off and (almost) all execution state is lost.
|
||||
*/
|
||||
#ifdef ESP8266_DEEP_SLEEP_IN_US
|
||||
if (ready_to_sleep) {
|
||||
Log.notice(F("Entering deep sleep for : %l us." CR), ESP8266_DEEP_SLEEP_IN_US);
|
||||
ESP.deepSleep(ESP8266_DEEP_SLEEP_IN_US);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user