working smart variable
This commit is contained in:
parent
1b2a270d38
commit
1d977c5bdf
2 changed files with 60 additions and 7 deletions
|
@ -1,3 +1,7 @@
|
|||
/**
|
||||
* @file main.cpp
|
||||
* @brief Test firmware for the ESPMegaPRO OOP library
|
||||
*/
|
||||
#include <ESPMegaProOS.hpp>
|
||||
#include <InternalDisplay.hpp>
|
||||
#include <ETH.h>
|
||||
|
@ -125,7 +129,7 @@ void mqtt_callback(char *topic, char *payload)
|
|||
void setNetworkConfig()
|
||||
{
|
||||
NetworkConfig config = {
|
||||
.ip = {192, 168, 0, 10},
|
||||
.ip = {192, 168, 0, 249},
|
||||
.gateway = {192, 168, 0, 1},
|
||||
.subnet = {255, 255, 255, 0},
|
||||
.dns1 = {10, 192, 1, 1},
|
||||
|
@ -148,7 +152,7 @@ void setMqttConfig()
|
|||
.mqtt_port = 1883,
|
||||
.mqtt_useauth = false};
|
||||
strcpy(config.mqtt_server, "192.168.0.26");
|
||||
strcpy(config.base_topic, "/espmegaoop");
|
||||
strcpy(config.base_topic, "/espmegacud");
|
||||
espmega.iot->setMqttConfig(config);
|
||||
espmega.iot->saveMqttConfig();
|
||||
}
|
||||
|
@ -236,10 +240,15 @@ void setup()
|
|||
#ifdef SMART_VARIABLE_ENABLE
|
||||
ESP_LOGI("Initializer", "Initializing smart variable");
|
||||
smartVar.begin(16);
|
||||
ESP_LOGI("Initializer", "Binding smart variable to FRAM");
|
||||
smartVar.bindFRAM(&espmega.fram, 8000);
|
||||
ESP_LOGI("Initializer", "Enabling smart variable autosave");
|
||||
smartVar.setValueAutoSave(true);
|
||||
ESP_LOGI("Initializer", "Enabling IoT for smart variable");
|
||||
smartVar.enableIoT(espmega.iot, "/smartvar");
|
||||
ESP_LOGI("Initializer", "Enabling smart variable set value");
|
||||
smartVar.enableSetValue("/smartvar/set");
|
||||
ESP_LOGI("Initializer", "Enabling smart variable value request");
|
||||
smartVar.enableValueRequest("/smartvar/request");
|
||||
#endif
|
||||
ESP_LOGI("Initializer", "Setup complete");
|
||||
|
@ -306,5 +315,14 @@ void loop()
|
|||
Serial.print("SmartVar: ");
|
||||
Serial.println(smartVar.getValue());
|
||||
}
|
||||
|
||||
static bool last_smartvar_state = false;
|
||||
static uint32_t last_smartvar_state_change = 0;
|
||||
if (millis() - last_smartvar_state_change >= 5000)
|
||||
{
|
||||
last_smartvar_state_change = millis();
|
||||
last_smartvar_state = !last_smartvar_state;
|
||||
smartVar.setValue(last_smartvar_state ? "true" : "false");
|
||||
}
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue