[WIP] Powermanagement
This commit is contained in:
parent
56fe0e50a1
commit
a3f967e747
49
metesp.ino
49
metesp.ino
@ -27,8 +27,12 @@
|
|||||||
#define PIN_SCL 23
|
#define PIN_SCL 23
|
||||||
|
|
||||||
|
|
||||||
|
#define uS_TO_S_FACTOR 1000000 //Conversion factor for micro seconds to seconds
|
||||||
|
#define TIME_TO_SLEEP (60*5)
|
||||||
|
|
||||||
/* Global Variables -----------------------------------------------------------*/
|
/* Global Variables -----------------------------------------------------------*/
|
||||||
|
|
||||||
|
RTC_DATA_ATTR int bootCount = 0;
|
||||||
|
|
||||||
static WiFiMulti wifiMulti;
|
static WiFiMulti wifiMulti;
|
||||||
static TwoWire I2C = TwoWire(0);
|
static TwoWire I2C = TwoWire(0);
|
||||||
@ -108,9 +112,6 @@ void IRAM_ATTR onTouch(int8_t contacts, GTPoint *points) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Setup Functions -----------------------------------------------------------*/
|
/* Setup Functions -----------------------------------------------------------*/
|
||||||
void setup_EPD(){
|
|
||||||
Display::setup();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup_TOUCH() {
|
void setup_TOUCH() {
|
||||||
touch->setHandler(onTouch);
|
touch->setHandler(onTouch);
|
||||||
@ -147,23 +148,53 @@ void setup_TIMEDFUN() {
|
|||||||
REGISTER_TIMEDFUN_CALL(NTP_TF, 60);
|
REGISTER_TIMEDFUN_CALL(NTP_TF, 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setup_POWER() {
|
||||||
|
esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 1);
|
||||||
|
esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 1);
|
||||||
|
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
|
||||||
|
esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO,ESP_PD_OPTION_ON);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void print_wakeup_reason(){
|
||||||
|
esp_sleep_wakeup_cause_t wakeup_reason;
|
||||||
|
|
||||||
|
wakeup_reason = esp_sleep_get_wakeup_cause();
|
||||||
|
|
||||||
|
switch(wakeup_reason)
|
||||||
|
{
|
||||||
|
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
|
||||||
|
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Setup Functions --------------------------------------------------------------*/
|
/* Setup Functions --------------------------------------------------------------*/
|
||||||
void setup(){
|
void setup(){
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
I2C.begin(PIN_SDA, PIN_SCL);
|
||||||
I2C.begin(PIN_SDA, PIN_SCL, 100000);
|
|
||||||
I2C.setPins(PIN_SDA,PIN_SCL);
|
I2C.setPins(PIN_SDA,PIN_SCL);
|
||||||
setup_EPD();
|
|
||||||
|
++bootCount;
|
||||||
|
Serial.println("Boot number: " + String(bootCount));
|
||||||
|
print_wakeup_reason();
|
||||||
|
|
||||||
|
Display::setup();
|
||||||
setup_TOUCH();
|
setup_TOUCH();
|
||||||
setup_WIFI();
|
setup_WIFI();
|
||||||
setup_TIMER();
|
setup_TIMER();
|
||||||
setup_TIMEDFUN();
|
setup_TIMEDFUN();
|
||||||
|
|
||||||
iflx->check();
|
|
||||||
Display::setViews(views,views_size);
|
Display::setViews(views,views_size);
|
||||||
|
|
||||||
|
iflx->check();
|
||||||
tf->updateForce();
|
tf->updateForce();
|
||||||
|
shutdownc = 0;
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(
|
xTaskCreatePinnedToCore(
|
||||||
loop_MEASURE, "Task LMeasure",
|
loop_MEASURE, "Task LMeasure",
|
||||||
@ -173,6 +204,7 @@ void setup(){
|
|||||||
loop_DRAW, "Task LDraw",
|
loop_DRAW, "Task LDraw",
|
||||||
10000, NULL, 1, &task_draw, 1);
|
10000, NULL, 1, &task_draw, 1);
|
||||||
|
|
||||||
|
Serial.println("Completed Setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -185,6 +217,7 @@ void loop_DRAW(void * pvParameters ){
|
|||||||
for(;;){
|
for(;;){
|
||||||
touch->update();
|
touch->update();
|
||||||
if(shutdownc >= 10){
|
if(shutdownc >= 10){
|
||||||
|
Serial.println("Shuting down");
|
||||||
Display::refresh();
|
Display::refresh();
|
||||||
EPD_2IN13_V2_Sleep();
|
EPD_2IN13_V2_Sleep();
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#define DEVICE "ESP32"
|
#define DEVICE "ESP32"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
|
||||||
#include <InfluxDbClient.h>
|
#include <InfluxDbClient.h>
|
||||||
@ -60,6 +61,7 @@ class Influx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void record(){
|
void record(){
|
||||||
|
if(WiFi.status() != WL_CONNECTED) return;
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
while(owm && owm[i] != NULL){
|
while(owm && owm[i] != NULL){
|
||||||
record_weather(owm[i]);
|
record_weather(owm[i]);
|
||||||
@ -69,6 +71,7 @@ class Influx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void record(bool w, bool s){
|
void record(bool w, bool s){
|
||||||
|
if(WiFi.status() != WL_CONNECTED) return;
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
while(w && owm && owm[i] != NULL){
|
while(w && owm && owm[i] != NULL){
|
||||||
record_weather(owm[i]);
|
record_weather(owm[i]);
|
||||||
@ -80,6 +83,8 @@ class Influx {
|
|||||||
|
|
||||||
void record_local(){
|
void record_local(){
|
||||||
if(!sensor) return;
|
if(!sensor) return;
|
||||||
|
if(WiFi.status() != WL_CONNECTED) return;
|
||||||
|
|
||||||
dp.clearFields();
|
dp.clearFields();
|
||||||
dp.clearTags();
|
dp.clearTags();
|
||||||
dp.addTag("device", "WESP0");
|
dp.addTag("device", "WESP0");
|
||||||
@ -125,6 +130,7 @@ class Influx {
|
|||||||
void record_weather(OWM* owm){
|
void record_weather(OWM* owm){
|
||||||
if(!owm) return;
|
if(!owm) return;
|
||||||
if(!owm->valid_weather) return;
|
if(!owm->valid_weather) return;
|
||||||
|
if(WiFi.status() != WL_CONNECTED) return;
|
||||||
|
|
||||||
JsonObject weather_0 = owm->weather["weather"][0];
|
JsonObject weather_0 = owm->weather["weather"][0];
|
||||||
JsonObject weather_main = owm->weather["main"];
|
JsonObject weather_main = owm->weather["main"];
|
||||||
|
@ -226,6 +226,7 @@ strDateTime NTPtime::getNTPtime(float _timeZone, boolean _DayLightSaving) {
|
|||||||
|
|
||||||
|
|
||||||
void NTPtime::updateNTPtime(){
|
void NTPtime::updateNTPtime(){
|
||||||
|
if(WiFi.status() != WL_CONNECTED) return;
|
||||||
strDateTime ndt = getNTPtime(1.0f, true);
|
strDateTime ndt = getNTPtime(1.0f, true);
|
||||||
if(ndt.valid) dt = ndt;
|
if(ndt.valid) dt = ndt;
|
||||||
};
|
};
|
@ -2,6 +2,7 @@
|
|||||||
#define NTPtime_h
|
#define NTPtime_h
|
||||||
|
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
struct strDateTime {
|
struct strDateTime {
|
||||||
byte hour;
|
byte hour;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
|
||||||
#define OPENWEATHER_URL(loc, api) ("https://api.openweathermap.org/data/2.5/weather?q=" + loc + "&appid=" + api + "&units=metric")
|
#define OPENWEATHER_URL(loc, api) ("https://api.openweathermap.org/data/2.5/weather?q=" + loc + "&appid=" + api + "&units=metric")
|
||||||
@ -17,6 +18,7 @@ class OWM{
|
|||||||
bool valid_weather = false;
|
bool valid_weather = false;
|
||||||
|
|
||||||
bool update(){
|
bool update(){
|
||||||
|
if(WiFi.status() != WL_CONNECTED) return false;
|
||||||
String response = httpGETRequest(OPENWEATHER_URL(location,key).c_str());
|
String response = httpGETRequest(OPENWEATHER_URL(location,key).c_str());
|
||||||
DeserializationError error = deserializeJson(weather, response);
|
DeserializationError error = deserializeJson(weather, response);
|
||||||
|
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define SENSOR_DATA_LENGTH 32
|
||||||
|
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
bool PMSA003::Initialize(){
|
bool PMSA003::Initialize(){
|
||||||
bool success(true);
|
bool success(true);
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#define PMSA003_ADDRESS (0x12)
|
#define PMSA003_ADDRESS (0x12)
|
||||||
|
|
||||||
#define SENSOR_DATA_LENGTH 32
|
|
||||||
|
|
||||||
typedef struct PMSAQIdata {
|
typedef struct PMSAQIdata {
|
||||||
uint16_t pm10_standard, ///< Standard PM1.0
|
uint16_t pm10_standard, ///< Standard PM1.0
|
||||||
@ -95,7 +94,7 @@ private:
|
|||||||
bool ReadChipID();
|
bool ReadChipID();
|
||||||
|
|
||||||
bool ReadRegister(uint8_t addr,uint8_t data[],uint8_t length);
|
bool ReadRegister(uint8_t addr,uint8_t data[],uint8_t length);
|
||||||
bool ReadData(uint8_t data[SENSOR_DATA_LENGTH]);
|
bool ReadData(uint8_t* data);
|
||||||
|
|
||||||
bool WriteSettings();
|
bool WriteSettings();
|
||||||
bool WriteRegister(uint16_t addr,uint8_t data);
|
bool WriteRegister(uint16_t addr,uint8_t data);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "sgp40.h"
|
#include "sgp40.h"
|
||||||
|
|
||||||
|
#define SENSOR_DATA_LENGTH 3
|
||||||
|
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
bool SGP40::Initialize(){
|
bool SGP40::Initialize(){
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
#define SGP40_ADDRESS (0x59)
|
#define SGP40_ADDRESS (0x59)
|
||||||
|
|
||||||
#define SENSOR_DATA_LENGTH 3
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
/// SGP40 - Driver class for SGP40 sensor
|
/// SGP40 - Driver class for SGP40 sensor
|
||||||
///
|
///
|
||||||
@ -55,7 +53,7 @@ private:
|
|||||||
bool ReadChipID();
|
bool ReadChipID();
|
||||||
|
|
||||||
bool ReadRegister(uint8_t addr,uint8_t data[],uint8_t length);
|
bool ReadRegister(uint8_t addr,uint8_t data[],uint8_t length);
|
||||||
bool ReadData(uint8_t data[SENSOR_DATA_LENGTH], float RH, float T);
|
bool ReadData(uint8_t* data, float RH, float T);
|
||||||
|
|
||||||
bool WriteSettings();
|
bool WriteSettings();
|
||||||
bool WriteRegister(uint16_t addr,uint8_t data);
|
bool WriteRegister(uint16_t addr,uint8_t data);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "tsl25911.h"
|
#include "tsl25911.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define SENSOR_DATA_LENGTH 4
|
||||||
|
|
||||||
#define ENABLE_POWEROFF (0x00) ///< Flag for ENABLE register to disable
|
#define ENABLE_POWEROFF (0x00) ///< Flag for ENABLE register to disable
|
||||||
#define ENABLE_POWERON (0x01) ///< Flag for ENABLE register to enable
|
#define ENABLE_POWERON (0x01) ///< Flag for ENABLE register to enable
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#define TSL25911_ADDRESS (0x29)
|
#define TSL25911_ADDRESS (0x29)
|
||||||
|
|
||||||
#define SENSOR_DATA_LENGTH 4
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
/// TSL25911 - Driver class for TSL25911 sensor
|
/// TSL25911 - Driver class for TSL25911 sensor
|
||||||
@ -111,7 +110,7 @@ private:
|
|||||||
bool ReadChipID();
|
bool ReadChipID();
|
||||||
|
|
||||||
bool ReadRegister(uint8_t addr,uint8_t data[],uint8_t length);
|
bool ReadRegister(uint8_t addr,uint8_t data[],uint8_t length);
|
||||||
bool ReadData(uint32_t data[SENSOR_DATA_LENGTH]);
|
bool ReadData(uint32_t* data);
|
||||||
|
|
||||||
void WriteSettings();
|
void WriteSettings();
|
||||||
bool WriteRegister(uint8_t addr,uint8_t data);
|
bool WriteRegister(uint8_t addr,uint8_t data);
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
#include "gt1151.h"
|
#include "gt1151.h"
|
||||||
|
|
||||||
#define GT1151_RESET_PIN 02
|
|
||||||
#define GT1151_INT_PIN 15
|
|
||||||
|
|
||||||
|
|
||||||
volatile uint8_t gtIRQ = 0;
|
volatile uint8_t gtIRQ = 0;
|
||||||
void IRAM_ATTR _gt_irq_handler() {
|
void IRAM_ATTR _gt_irq_handler() {
|
||||||
|
@ -4,6 +4,12 @@
|
|||||||
#ifndef __GT1151_H
|
#ifndef __GT1151_H
|
||||||
#define __GT1151_H
|
#define __GT1151_H
|
||||||
|
|
||||||
|
|
||||||
|
#define GT1151_RESET_PIN 02
|
||||||
|
#define GT1151_INT_PIN 15 //RTC_GPIO13
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define GT1151_ADDRESS 0x14
|
#define GT1151_ADDRESS 0x14
|
||||||
#define GT1151_ADDRESS_28 0x14
|
#define GT1151_ADDRESS_28 0x14
|
||||||
#define GT1151_ADDRESS_BA 0x5D
|
#define GT1151_ADDRESS_BA 0x5D
|
||||||
|
Loading…
x
Reference in New Issue
Block a user