smart variable implementation

This commit is contained in:
Siwat Sirichai 2024-03-23 10:25:16 +07:00
parent aa28ec88fb
commit 7f55e3544d
3 changed files with 183 additions and 8 deletions

View file

@ -6,17 +6,19 @@
#include <RemoteVariable.hpp>
#include <CurrentTransformerCard.hpp>
#include <AnalogCard.hpp>
#include <SmartVariable.hpp>
// #define FRAM_DEBUG
// #define MQTT_DEBUG
// #define WRITE_DEFAULT_NETCONF
//#define CLIMATE_CARD_ENABLE
//#define MQTT_CARD_REGISTER
#define DISPLAY_ENABLE
#define WEB_SERVER_ENABLE
#define LCD_OTA_ENABLE
#define REMOTE_VARIABLE_ENABLE
#define CT_ENABLE
//#define DISPLAY_ENABLE
//#define WEB_SERVER_ENABLE
//#define LCD_OTA_ENABLE
//#define REMOTE_VARIABLE_ENABLE
//#define CT_ENABLE
#define SMART_VARIABLE_ENABLE
// Demo PLC firmware using the ESPMegaPRO OOP library
@ -41,6 +43,10 @@ float voltage = 220.0;
CurrentTransformerCard ct = CurrentTransformerCard(&analogCard, 0, &voltage, adc2current, 1000);
#endif
#ifdef SMART_VARIABLE_ENABLE
SmartVariable smartVar = SmartVariable();
#endif
#ifdef CLIMATE_CARD_ENABLE
// Climate Card
const char *mode_names[] = {"off", "fan_only", "cool"};
@ -226,6 +232,15 @@ void setup()
ct.bindFRAM(&espmega.fram, 7000);
ct.loadEnergy();
ct.setEnergyAutoSave(true);
#endif
#ifdef SMART_VARIABLE_ENABLE
ESP_LOGI("Initializer", "Initializing smart variable");
smartVar.begin(16);
smartVar.bindFRAM(&espmega.fram, 8000);
smartVar.setValueAutoSave(true);
smartVar.enableIoT(espmega.iot, "/smartvar");
smartVar.enableSetValue("/smartvar/set");
smartVar.enableValueRequest("/smartvar/request");
#endif
ESP_LOGI("Initializer", "Setup complete");
}
@ -283,4 +298,13 @@ void loop()
Serial.println(ct.getCurrent());
}
#endif
#ifdef SMART_VARIABLE_ENABLE
static uint32_t last_smartvar_print = 0;
if (millis() - last_smartvar_print >= 1000)
{
last_smartvar_print = millis();
Serial.print("SmartVar: ");
Serial.println(smartVar.getValue());
}
#endif
}