fix mqtt ptr init bug
This commit is contained in:
parent
443a02c319
commit
14767df9ec
4 changed files with 93 additions and 41 deletions
|
@ -3,16 +3,17 @@
|
|||
#include <ETH.h>
|
||||
#include <ClimateCard.hpp>
|
||||
|
||||
|
||||
// #define FRAM_DEBUG
|
||||
|
||||
// Demo PLC firmware using the ESPMegaPRO OOP library
|
||||
|
||||
ESPMegaPRO espmega = ESPMegaPRO();
|
||||
const uint16_t irCode[15][4][4][1] = {0};
|
||||
const char* mode_names[] = {"Off", "Fan-only", "Cool"};
|
||||
const char* fan_speed_names[] = {"Auto", "Low", "Medium", "High"};
|
||||
const char *mode_names[] = {"Off", "Fan-only", "Cool"};
|
||||
const char *fan_speed_names[] = {"Auto", "Low", "Medium", "High"};
|
||||
|
||||
size_t getInfraredCode(uint8_t mode, uint8_t fan_speed, uint8_t temperature, const uint16_t** codePtr) {
|
||||
size_t getInfraredCode(uint8_t mode, uint8_t fan_speed, uint8_t temperature, const uint16_t **codePtr)
|
||||
{
|
||||
// Change the code pointer to point to the IR timing array
|
||||
*codePtr = &(irCode[mode][fan_speed][temperature][0]);
|
||||
return sizeof(irCode[mode][fan_speed][temperature]) / sizeof(uint16_t);
|
||||
|
@ -25,19 +26,20 @@ AirConditioner ac = {
|
|||
.mode_names = mode_names,
|
||||
.fan_speeds = 4,
|
||||
.fan_speed_names = fan_speed_names,
|
||||
.getInfraredCode = &getInfraredCode
|
||||
};
|
||||
.getInfraredCode = &getInfraredCode};
|
||||
|
||||
ClimateCard climateCard = ClimateCard(14, ac);
|
||||
|
||||
void input_change_callback(uint8_t pin, uint8_t value) {
|
||||
void input_change_callback(uint8_t pin, uint8_t value)
|
||||
{
|
||||
Serial.print("Input change callback: ");
|
||||
Serial.print(pin);
|
||||
Serial.print(" ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
void setNetworkConfig() {
|
||||
void setNetworkConfig()
|
||||
{
|
||||
NetworkConfig config = {
|
||||
.ip = {192, 168, 0, 11},
|
||||
.gateway = {192, 168, 0, 1},
|
||||
|
@ -54,53 +56,70 @@ void setNetworkConfig() {
|
|||
Serial.println("Setting network config");
|
||||
espmega.iot->setNetworkConfig(config);
|
||||
espmega.iot->saveNetworkConfig();
|
||||
|
||||
}
|
||||
|
||||
void setMqttConfig() {
|
||||
void setMqttConfig()
|
||||
{
|
||||
MqttConfig config = {
|
||||
.mqtt_port = 1883,
|
||||
.mqtt_useauth = false
|
||||
};
|
||||
.mqtt_useauth = false};
|
||||
strcpy(config.mqtt_server, "192.168.0.26");
|
||||
strcpy(config.base_topic, "/espmegaoop");
|
||||
espmega.iot->setMqttConfig(config);
|
||||
espmega.iot->saveMqttConfig();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
void setup()
|
||||
{
|
||||
ESP_LOGI("Initializer", "Starting ESPMegaPRO OOP demo");
|
||||
espmega.begin();
|
||||
ESP_LOGI("Initializer", "Enabling IOT module");
|
||||
espmega.enableIotModule();
|
||||
ESP_LOGI("Initializer", "Enabling Ethernet");
|
||||
ETH.begin();
|
||||
ESP_LOGI("Initializer", "Binding Ethernet to IOT module");
|
||||
espmega.iot->bindEthernetInterface(Ð);
|
||||
ESP_LOGI("Initializer", "Loading network config");
|
||||
espmega.iot->loadNetworkConfig();
|
||||
ESP_LOGI("Initializer", "Connecting to network");
|
||||
espmega.iot->connectNetwork();
|
||||
ESP_LOGI("Initializer", "Loading MQTT config");
|
||||
espmega.iot->loadMqttConfig();
|
||||
ESP_LOGI("Initializer", "Connecting to MQTT");
|
||||
espmega.iot->connectToMqtt();
|
||||
ESP_LOGI("Initializer", "Registering cards 0");
|
||||
espmega.iot->registerCard(0);
|
||||
ESP_LOGI("Initializer", "Registering cards 1");
|
||||
espmega.iot->registerCard(1);
|
||||
ESP_LOGI("Initializer", "Registering Input change callback");
|
||||
espmega.inputs.registerCallback(input_change_callback);
|
||||
ESP_LOGI("Initializer", "Installing climate card");
|
||||
espmega.installCard(2, &climateCard);
|
||||
ESP_LOGI("Initializer", "Binding climate card to FRAM");
|
||||
climateCard.bindFRAM(&espmega.fram, 301);
|
||||
ESP_LOGI("Initializer", "Loading climate card state from FRAM");
|
||||
climateCard.loadStateFromFRAM();
|
||||
ESP_LOGI("Initializer", "Enabling climate card FRAM autosave");
|
||||
climateCard.setFRAMAutoSave(true);
|
||||
ESP_LOGI("Initializer", "Enabling internal display");
|
||||
espmega.enableInternalDisplay(&Serial);
|
||||
ESP_LOGI("Initializer", "Binding climate card to internal display");
|
||||
espmega.display->bindClimateCard(&climateCard);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Every 20 seconds, dump FRAM 0-500 to serial
|
||||
void loop() {
|
||||
void loop()
|
||||
{
|
||||
espmega.loop();
|
||||
#ifdef FRAM_DEBUG
|
||||
#ifdef FRAM_DEBUG
|
||||
// Every 20 seconds, dump FRAM 0-500 to serial
|
||||
static uint32_t last_fram_dump = 0;
|
||||
if (millis() - last_fram_dump >= 20000) {
|
||||
if (millis() - last_fram_dump >= 20000)
|
||||
{
|
||||
last_fram_dump = millis();
|
||||
Serial.println("Dumping FRAM");
|
||||
espmega.dumpFRAMtoSerial(0, 500);
|
||||
Serial.println("Dumping FRAM ASCII");
|
||||
espmega.dumpFRAMtoSerialASCII(0, 500);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue