[WIP] Powermanagement

This commit is contained in:
2022-05-03 13:13:37 +02:00
parent 56fe0e50a1
commit a3f967e747
13 changed files with 65 additions and 18 deletions

View File

@@ -3,6 +3,7 @@
#define DEVICE "ESP32"
#include <Arduino.h>
#include <WiFi.h>
#include <InfluxDbClient.h>
@@ -60,6 +61,7 @@ class Influx {
}
void record(){
if(WiFi.status() != WL_CONNECTED) return;
uint8_t i = 0;
while(owm && owm[i] != NULL){
record_weather(owm[i]);
@@ -69,6 +71,7 @@ class Influx {
}
void record(bool w, bool s){
if(WiFi.status() != WL_CONNECTED) return;
uint8_t i = 0;
while(w && owm && owm[i] != NULL){
record_weather(owm[i]);
@@ -80,6 +83,8 @@ class Influx {
void record_local(){
if(!sensor) return;
if(WiFi.status() != WL_CONNECTED) return;
dp.clearFields();
dp.clearTags();
dp.addTag("device", "WESP0");
@@ -125,6 +130,7 @@ class Influx {
void record_weather(OWM* owm){
if(!owm) return;
if(!owm->valid_weather) return;
if(WiFi.status() != WL_CONNECTED) return;
JsonObject weather_0 = owm->weather["weather"][0];
JsonObject weather_main = owm->weather["main"];

View File

@@ -226,6 +226,7 @@ strDateTime NTPtime::getNTPtime(float _timeZone, boolean _DayLightSaving) {
void NTPtime::updateNTPtime(){
if(WiFi.status() != WL_CONNECTED) return;
strDateTime ndt = getNTPtime(1.0f, true);
if(ndt.valid) dt = ndt;
};

View File

@@ -2,6 +2,7 @@
#define NTPtime_h
#include <WiFiUdp.h>
#include <WiFi.h>
struct strDateTime {
byte hour;

View File

@@ -3,6 +3,7 @@
#include <HTTPClient.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")
@@ -17,6 +18,7 @@ class OWM{
bool valid_weather = false;
bool update(){
if(WiFi.status() != WL_CONNECTED) return false;
String response = httpGETRequest(OPENWEATHER_URL(location,key).c_str());
DeserializationError error = deserializeJson(weather, response);

View File

@@ -3,6 +3,9 @@
#include <Arduino.h>
#define SENSOR_DATA_LENGTH 32
/****************************************************************/
bool PMSA003::Initialize(){
bool success(true);

View File

@@ -7,7 +7,6 @@
#define PMSA003_ADDRESS (0x12)
#define SENSOR_DATA_LENGTH 32
typedef struct PMSAQIdata {
uint16_t pm10_standard, ///< Standard PM1.0
@@ -95,7 +94,7 @@ private:
bool ReadChipID();
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 WriteRegister(uint16_t addr,uint8_t data);

View File

@@ -1,5 +1,6 @@
#include "sgp40.h"
#define SENSOR_DATA_LENGTH 3
/****************************************************************/
bool SGP40::Initialize(){

View File

@@ -8,8 +8,6 @@
#define SGP40_ADDRESS (0x59)
#define SENSOR_DATA_LENGTH 3
//////////////////////////////////////////////////////////////////
/// SGP40 - Driver class for SGP40 sensor
///
@@ -55,7 +53,7 @@ private:
bool ReadChipID();
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 WriteRegister(uint16_t addr,uint8_t data);

View File

@@ -1,6 +1,7 @@
#include "tsl25911.h"
#define SENSOR_DATA_LENGTH 4
#define ENABLE_POWEROFF (0x00) ///< Flag for ENABLE register to disable
#define ENABLE_POWERON (0x01) ///< Flag for ENABLE register to enable

View File

@@ -6,7 +6,6 @@
#define TSL25911_ADDRESS (0x29)
#define SENSOR_DATA_LENGTH 4
//////////////////////////////////////////////////////////////////
/// TSL25911 - Driver class for TSL25911 sensor
@@ -111,7 +110,7 @@ private:
bool ReadChipID();
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();
bool WriteRegister(uint8_t addr,uint8_t data);

View File

@@ -1,8 +1,5 @@
#include "gt1151.h"
#define GT1151_RESET_PIN 02
#define GT1151_INT_PIN 15
volatile uint8_t gtIRQ = 0;
void IRAM_ATTR _gt_irq_handler() {

View File

@@ -4,6 +4,12 @@
#ifndef __GT1151_H
#define __GT1151_H
#define GT1151_RESET_PIN 02
#define GT1151_INT_PIN 15 //RTC_GPIO13
#define GT1151_ADDRESS 0x14
#define GT1151_ADDRESS_28 0x14
#define GT1151_ADDRESS_BA 0x5D