From d62ffa36062e46c6d8e9fbf3c5e7e916a1fa341a Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Mon, 1 Jan 2024 00:31:28 +0700 Subject: [PATCH] Milestone 1 All function implemented in OOP except WebServer Function. Most missing documentation and comments --- .../lib/ESPMegaPRO/ClimateIoT.cpp | 3 +++ .../lib/ESPMegaPRO/ESPMegaIoT.cpp | 6 ------ .../lib/ESPMegaPRO/ESPMegaPRO_OOP.cpp | 2 +- .../lib/ESPMegaPRO/InternalDisplay.cpp | 19 ++----------------- .../lib/ESPMegaPRO/IoTComponent.cpp | 1 - ESPMegaPRO-firmware/platformio.ini | 2 +- ESPMegaPRO-firmware/src/main.cpp | 6 +++--- 7 files changed, 10 insertions(+), 29 deletions(-) diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateIoT.cpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateIoT.cpp index c2f4c51..d2f8813 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateIoT.cpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateIoT.cpp @@ -60,6 +60,9 @@ void ClimateIoT::publishClimate() { } void ClimateIoT::publishRoomTemperature() { + if (this->card->getSensorType() == AC_SENSOR_TYPE_NONE ) { + return; + } char payload[5]; itoa(this->card->getRoomTemperature(), payload, 10); this->publishRelative(AC_ROOM_TEMPERATURE_REPORT_TOPIC, payload); diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ESPMegaIoT.cpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ESPMegaIoT.cpp index 24a649c..eec998e 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ESPMegaIoT.cpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ESPMegaIoT.cpp @@ -100,14 +100,8 @@ void ESPMegaIoT::registerCard(uint8_t card_id) components[card_id]->begin(card_id, cards[card_id], &mqtt, this->mqtt_config.base_topic); if (mqtt_connected) { - Serial.println("Subscribing to Input Topics"); components[card_id]->subscribe(); - mqtt.loop(); - Serial.println(mqtt.connected()? "MQTT Connected" : "MQTT Not Connected"); - Serial.println("Publishing Input report"); components[card_id]->publishReport(); - mqtt.loop(); - Serial.println(mqtt.connected()? "MQTT Connected" : "MQTT Not Connected"); } break; case CARD_TYPE_DIGITAL_OUTPUT: diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ESPMegaPRO_OOP.cpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ESPMegaPRO_OOP.cpp index 187aad1..4027aea 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ESPMegaPRO_OOP.cpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ESPMegaPRO_OOP.cpp @@ -2,7 +2,7 @@ // Reserve FRAM address 0 - 1000 for ESPMegaPRO Internal Use // (34 Bytes) Address 0-33 for Built-in Digital Output Card -// () Address 34-300 for ESPMegaPRO IoT Module +// (266 Bytes) Address 34-300 for ESPMegaPRO IoT Module ESPMegaPRO::ESPMegaPRO() { diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp index 20fa3f2..1fcb998 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp @@ -82,29 +82,17 @@ void InternalDisplay::saveNetworkConfig() // dns_set -> a text input to set the dns // host_set -> a text input to set the hostname - Serial.println("Saving network config"); - this->sendStopBytes(); - // Save the ip address IPAddress ip; // 000.000.000.000, 16 characters, 3 dots, 3 characters per octet, 1 null terminator char ip_buffer[30]; - Serial.println("Getting ip_set.txt"); - this->sendStopBytes(); if(!this->getStringToBuffer("ip_set.txt", ip_buffer, 30)) { - Serial.println("Failed to get ip_set.txt"); - this->sendStopBytes(); return; } - Serial.println("Got ip_set.txt"); - this->sendStopBytes(); + // Validate the ip address if (!ip.fromString(ip_buffer)) { - Serial.println("Invalid ip address"); - Serial.print("The recieved IP is: "); - Serial.println(ip_buffer); - this->sendStopBytes(); return; } @@ -187,8 +175,6 @@ void InternalDisplay::saveMQTTConfig() // Save the mqtt use auth uint8_t use_auth = this->getNumber("use_auth.val"); - Serial.print("use_auth: "); - Serial.println(use_auth); this->mqttConfig->mqtt_useauth = use_auth == 1 ? true : false; this->iot->saveMqttConfig(); ESP.restart(); @@ -372,7 +358,7 @@ void InternalDisplay::setInputMarker(uint8_t pin, bool state) this->displayAdapter->print("I"); this->displayAdapter->print(pin); this->displayAdapter->print(".val="); - this->displayAdapter->print(state ? 0 : 1); + this->displayAdapter->print(state ? 1 : 0); this->sendStopBytes(); } @@ -709,7 +695,6 @@ void InternalDisplay::handleACStateChange(uint8_t mode, uint8_t fan_speed, uint8 { // If the climate card is binded to the display and the current page is the AC page // then update the respective AC component - Serial.println("AC state changed"); if (this->climateCard == nullptr || this->currentPage != INTERNAL_DISPLAY_AC_PAGE) return; this->sendStopBytes(); diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/IoTComponent.cpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/IoTComponent.cpp index f430b90..186657e 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/IoTComponent.cpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/IoTComponent.cpp @@ -10,7 +10,6 @@ void IoTComponent::publishRelative(const char *topic, const char *payload) { ESP_LOGD("IoTComponent", "Publishing to %s : %s", absolute_topic, payload); mqtt->publish(absolute_topic, payload); mqtt->loop(); - delay(50); } void IoTComponent::subscribeRelative(const char *topic) { diff --git a/ESPMegaPRO-firmware/platformio.ini b/ESPMegaPRO-firmware/platformio.ini index a17692c..1fe009e 100644 --- a/ESPMegaPRO-firmware/platformio.ini +++ b/ESPMegaPRO-firmware/platformio.ini @@ -31,4 +31,4 @@ lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1 https://github.com/me-no-dev/ESPAsyncWebServer.git #esphome/ESPAsyncWebServer-esphome@^3.1.0 monitor_speed = 115200 -build_flags = -DCORE_DEBUG_LEVEL=5 \ No newline at end of file +build_flags = -DCORE_DEBUG_LEVEL=1 \ No newline at end of file diff --git a/ESPMegaPRO-firmware/src/main.cpp b/ESPMegaPRO-firmware/src/main.cpp index 5fff0b7..3ca2d47 100644 --- a/ESPMegaPRO-firmware/src/main.cpp +++ b/ESPMegaPRO-firmware/src/main.cpp @@ -8,7 +8,7 @@ // #define WRITE_DEFAULT_NETCONF #define CLIMATE_CARD_ENABLE #define MQTT_CARD_REGISTER -// #define DISPLAY_ENABLE +#define DISPLAY_ENABLE // Demo PLC firmware using the ESPMegaPRO OOP library @@ -17,8 +17,8 @@ ESPMegaPRO espmega = ESPMegaPRO(); #ifdef CLIMATE_CARD_ENABLE // Climate Card 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) {