Milestone 1

All function implemented in OOP except WebServer Function.
Most missing documentation and comments
This commit is contained in:
Siwat Sirichai 2024-01-01 00:31:28 +07:00
parent e1f0fd5651
commit d62ffa3606
7 changed files with 10 additions and 29 deletions

View File

@ -60,6 +60,9 @@ void ClimateIoT::publishClimate() {
} }
void ClimateIoT::publishRoomTemperature() { void ClimateIoT::publishRoomTemperature() {
if (this->card->getSensorType() == AC_SENSOR_TYPE_NONE ) {
return;
}
char payload[5]; char payload[5];
itoa(this->card->getRoomTemperature(), payload, 10); itoa(this->card->getRoomTemperature(), payload, 10);
this->publishRelative(AC_ROOM_TEMPERATURE_REPORT_TOPIC, payload); this->publishRelative(AC_ROOM_TEMPERATURE_REPORT_TOPIC, payload);

View File

@ -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); components[card_id]->begin(card_id, cards[card_id], &mqtt, this->mqtt_config.base_topic);
if (mqtt_connected) if (mqtt_connected)
{ {
Serial.println("Subscribing to Input Topics");
components[card_id]->subscribe(); components[card_id]->subscribe();
mqtt.loop();
Serial.println(mqtt.connected()? "MQTT Connected" : "MQTT Not Connected");
Serial.println("Publishing Input report");
components[card_id]->publishReport(); components[card_id]->publishReport();
mqtt.loop();
Serial.println(mqtt.connected()? "MQTT Connected" : "MQTT Not Connected");
} }
break; break;
case CARD_TYPE_DIGITAL_OUTPUT: case CARD_TYPE_DIGITAL_OUTPUT:

View File

@ -2,7 +2,7 @@
// Reserve FRAM address 0 - 1000 for ESPMegaPRO Internal Use // Reserve FRAM address 0 - 1000 for ESPMegaPRO Internal Use
// (34 Bytes) Address 0-33 for Built-in Digital Output Card // (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() { ESPMegaPRO::ESPMegaPRO() {

View File

@ -82,29 +82,17 @@ void InternalDisplay::saveNetworkConfig()
// dns_set -> a text input to set the dns // dns_set -> a text input to set the dns
// host_set -> a text input to set the hostname // host_set -> a text input to set the hostname
Serial.println("Saving network config");
this->sendStopBytes();
// Save the ip address // Save the ip address
IPAddress ip; IPAddress ip;
// 000.000.000.000, 16 characters, 3 dots, 3 characters per octet, 1 null terminator // 000.000.000.000, 16 characters, 3 dots, 3 characters per octet, 1 null terminator
char ip_buffer[30]; char ip_buffer[30];
Serial.println("Getting ip_set.txt");
this->sendStopBytes();
if(!this->getStringToBuffer("ip_set.txt", ip_buffer, 30)) if(!this->getStringToBuffer("ip_set.txt", ip_buffer, 30))
{ {
Serial.println("Failed to get ip_set.txt");
this->sendStopBytes();
return; return;
} }
Serial.println("Got ip_set.txt");
this->sendStopBytes();
// Validate the ip address // Validate the ip address
if (!ip.fromString(ip_buffer)) { if (!ip.fromString(ip_buffer)) {
Serial.println("Invalid ip address");
Serial.print("The recieved IP is: ");
Serial.println(ip_buffer);
this->sendStopBytes();
return; return;
} }
@ -187,8 +175,6 @@ void InternalDisplay::saveMQTTConfig()
// Save the mqtt use auth // Save the mqtt use auth
uint8_t use_auth = this->getNumber("use_auth.val"); 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->mqttConfig->mqtt_useauth = use_auth == 1 ? true : false;
this->iot->saveMqttConfig(); this->iot->saveMqttConfig();
ESP.restart(); ESP.restart();
@ -372,7 +358,7 @@ void InternalDisplay::setInputMarker(uint8_t pin, bool state)
this->displayAdapter->print("I"); this->displayAdapter->print("I");
this->displayAdapter->print(pin); this->displayAdapter->print(pin);
this->displayAdapter->print(".val="); this->displayAdapter->print(".val=");
this->displayAdapter->print(state ? 0 : 1); this->displayAdapter->print(state ? 1 : 0);
this->sendStopBytes(); 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 // If the climate card is binded to the display and the current page is the AC page
// then update the respective AC component // then update the respective AC component
Serial.println("AC state changed");
if (this->climateCard == nullptr || this->currentPage != INTERNAL_DISPLAY_AC_PAGE) if (this->climateCard == nullptr || this->currentPage != INTERNAL_DISPLAY_AC_PAGE)
return; return;
this->sendStopBytes(); this->sendStopBytes();

View File

@ -10,7 +10,6 @@ void IoTComponent::publishRelative(const char *topic, const char *payload) {
ESP_LOGD("IoTComponent", "Publishing to %s : %s", absolute_topic, payload); ESP_LOGD("IoTComponent", "Publishing to %s : %s", absolute_topic, payload);
mqtt->publish(absolute_topic, payload); mqtt->publish(absolute_topic, payload);
mqtt->loop(); mqtt->loop();
delay(50);
} }
void IoTComponent::subscribeRelative(const char *topic) { void IoTComponent::subscribeRelative(const char *topic) {

View File

@ -31,4 +31,4 @@ lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1
https://github.com/me-no-dev/ESPAsyncWebServer.git https://github.com/me-no-dev/ESPAsyncWebServer.git
#esphome/ESPAsyncWebServer-esphome@^3.1.0 #esphome/ESPAsyncWebServer-esphome@^3.1.0
monitor_speed = 115200 monitor_speed = 115200
build_flags = -DCORE_DEBUG_LEVEL=5 build_flags = -DCORE_DEBUG_LEVEL=1

View File

@ -8,7 +8,7 @@
// #define WRITE_DEFAULT_NETCONF // #define WRITE_DEFAULT_NETCONF
#define CLIMATE_CARD_ENABLE #define CLIMATE_CARD_ENABLE
#define MQTT_CARD_REGISTER #define MQTT_CARD_REGISTER
// #define DISPLAY_ENABLE #define DISPLAY_ENABLE
// Demo PLC firmware using the ESPMegaPRO OOP library // Demo PLC firmware using the ESPMegaPRO OOP library
@ -17,8 +17,8 @@ ESPMegaPRO espmega = ESPMegaPRO();
#ifdef CLIMATE_CARD_ENABLE #ifdef CLIMATE_CARD_ENABLE
// Climate Card // Climate Card
const uint16_t irCode[15][4][4][1] = {0}; const uint16_t irCode[15][4][4][1] = {0};
const char *mode_names[] = {"Off", "Fan-only", "Cool"}; const char *mode_names[] = {"off", "fan_only", "cool"};
const char *fan_speed_names[] = {"Auto", "Low", "Medium", "High"}; 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)
{ {