fix failing build without climate module

This commit is contained in:
Siwat Sirichai 2023-11-16 14:51:17 +07:00
parent 2c2427ee3c
commit e124c73f67
1 changed files with 84 additions and 81 deletions

View File

@ -1,11 +1,11 @@
/**
* @file espmega_iot_core.cpp
* @brief Implementation of the ESPMega IoT Core library.
*
* This library provides the core functionality for the ESPMega IoT platform, including network connectivity,
* input/output control, and MQTT communication. It also includes support for an internal LCD display and
*
* This library provides the core functionality for the ESPMega IoT platform, including network connectivity,
* input/output control, and MQTT communication. It also includes support for an internal LCD display and
* air conditioner control.
*
*
* @author Siwat Sirichai
* @date 15 Nov 2023
*/
@ -204,7 +204,7 @@ void loop()
/**
* @brief Retrieves data from EEPROM and initializes various variables and topics.
*
*
*/
void eeprom_retrieve_init()
{
@ -296,12 +296,12 @@ void eeprom_retrieve_init()
#ifdef ENABLE_WEBUI
/**
* Initializes the OTA (Over-The-Air) update server and sets up the necessary routes for configuration and firmware updates.
*
*
* The OTA server can be accessed through the root URL ("/") and the configuration page can be accessed through "/config".
* The firmware update can be initiated through the "/update" route using HTTP POST method.
*
*
* The configuration page allows the user to set the device IP address, network mask, gateway, DNS server, hostname, BMS server IP address, BMS server port, BMS server endpoint, and BMS server authentication credentials.
*
*
* @return void
*/
void ota_begin()
@ -453,7 +453,6 @@ void ota_begin()
}
#endif
void io_begin()
{
Serial.println("Initializing I/O . . .");
@ -465,10 +464,10 @@ void io_begin()
/**
* @brief Initializes the network and sets the hostname and IP configuration.
*
* @details This function initializes the Ethernet connection and sets the hostname, IP address, gateway, subnet, and DNS server.
* It also initializes the NTP core and updates the time from the NTP server.
*
*
* @details This function initializes the Ethernet connection and sets the hostname, IP address, gateway, subnet, and DNS server.
* It also initializes the NTP core and updates the time from the NTP server.
*
* @return void
*/
void network_begin()
@ -499,13 +498,13 @@ void network_begin()
/**
* @brief Connects to the MQTT broker and subscribes to topics.
*
*
* If MQTT_USE_AUTH is true, it connects to the broker using the provided username and password.
* If the connection is successful, it subscribes to topics and publishes PWM and input states.
* If ENABLE_CLIMATE_MODULE is defined, it also publishes AC state.
*
*
* @note This function assumes that the MQTT client has been initialized and WiFi is connected.
*
*
* @return void
*/
void mqtt_connect()
@ -548,7 +547,7 @@ void mqtt_connect()
/**
* @brief Subscribes to MQTT topics for controlling PWM, climate module and requesting device state.
*
*
*/
void mqtt_subscribe()
{
@ -571,7 +570,7 @@ void mqtt_subscribe()
/**
* @brief Callback function for MQTT messages received by the device.
*
*
* @param topic The topic of the received message.
* @param payload The payload of the received message.
* @param length The length of the payload.
@ -591,19 +590,23 @@ void mqtt_callback(char *topic, byte *payload, unsigned int length)
else if ((!strncmp(topic_trim, "/pwm/", 5)) && !strncmp(topic_trim + 7, "/set/value", 10))
{
pwm_value_callback(topic_trim, topic_length, payload_nt, length);
} else if(!strcmp(topic,STATE_REQUEST_TOPIC)) {
}
else if (!strcmp(topic, STATE_REQUEST_TOPIC))
{
state_request_callback();
}
else
{
#ifdef ENABLE_CLIMATE_MODULE
ac_state_callback(topic, topic_length, payload_nt, length);
#endif
}
user_mqtt_callback(topic, topic_length, payload_nt, length);
}
/**
* @brief Initializes the threads for various tasks such as MQTT connection, environment reporting, EEPROM PWM update, and user timer tick.
*
*
*/
void thread_initialization()
{
@ -623,7 +626,7 @@ void thread_initialization()
/**
* @brief Callback function for handling PWM state changes.
*
*
* @param topic The MQTT topic on which the message was received.
* @param topic_length The length of the MQTT topic.
* @param payload The message payload.
@ -646,10 +649,10 @@ void pwm_state_callback(char *topic, uint8_t topic_length, char *payload, unsign
/**
* @brief Callback function for PWM value updates.
*
*
* This function is called whenever a message is received on the PWM value update topic.
* It extracts the PWM ID and value from the topic and payload, respectively, and sets the PWM value.
*
*
* @param topic The topic on which the message was received.
* @param topic_length The length of the topic.
* @param payload The message payload.
@ -666,10 +669,10 @@ void pwm_value_callback(char *topic, uint8_t topic_length, char *payload, unsign
/**
* @brief Callback function for virtual interrupts.
*
*
* This function publishes the input state of the virtual interrupt pin and calls the user-defined callback function.
* If ENABLE_INTERNAL_LCD is defined, it also updates the LCD display with the input state.
*
*
* @param pin The virtual interrupt pin number.
* @param state The state of the virtual interrupt pin (HIGH or LOW).
*/
@ -707,7 +710,7 @@ void virtual_interrupt_loop()
/**
* @brief Publishes the current state of all PWM channels.
*
*
*/
void publish_pwm_states()
{
@ -719,7 +722,7 @@ void publish_pwm_states()
/**
* @brief Publishes the state and value of a PWM signal to MQTT broker.
*
*
* @param id The ID of the PWM signal.
*/
void publish_pwm_state(int id)
@ -745,7 +748,7 @@ void publish_pwm_state(int id)
/**
* @brief Sets the state of a PWM pin and publishes the new state.
*
*
* @param id The ID of the PWM pin.
* @param state The new state of the PWM pin.
*/
@ -769,7 +772,7 @@ void pwm_set_state(int id, int state)
/**
* @brief Sets the PWM value for a given id.
*
*
* @param id The id of the PWM pin.
* @param value The value to set the PWM pin to.
*/
@ -790,7 +793,7 @@ void pwm_set_value(int id, int value)
/**
* @brief Toggles the state of a PWM pin.
*
*
* @param id The ID of the PWM pin to toggle.
*/
void pwm_toggle(int id)
@ -821,7 +824,7 @@ void pwm_toggle(int id1, int id2)
/**
* @brief Returns a boolean value indicating whether either of the two specified PWM states is true.
*
*
* @param id1 The first PWM state ID.
* @param id2 The second PWM state ID.
* @return true if either of the two specified PWM states is true, false otherwise.
@ -836,7 +839,7 @@ boolean pwm_group_state(int id1, int id2)
/**
* @brief Cycles the PWM value for the given id.
*
*
* @param id The id of the PWM pin.
*/
void pwm_cycle_value(int id)
@ -866,7 +869,7 @@ void pwm_cycle_value(int id)
/**
* @brief Publishes the input states for all virtual input pins.
*
*
*/
void publish_input_states()
{
@ -878,7 +881,7 @@ void publish_input_states()
/**
* @brief Publishes the input state of a specific pin.
*
*
* @param id The ID of the pin to publish the state of.
*/
void publish_input_state(int id)
@ -889,7 +892,7 @@ void publish_input_state(int id)
/**
* @brief Publishes the state of an input to the MQTT broker.
*
*
* @param id The ID of the input.
* @param state The state of the input (0 or 1).
*/
@ -902,7 +905,7 @@ void publish_input_state(int id, int state)
/**
* @brief Callback function to request the current state of the device.
*
*
* This function publishes the input and PWM states of the device. If the climate module is enabled, it also publishes the AC and environment states.
* Finally, it calls the user-defined state request callback function.
*/
@ -930,7 +933,7 @@ void ir_loop()
#ifdef ENABLE_CLIMATE_MODULE
/**
* @brief Publishes the current state of the air conditioner to MQTT topics.
*
*
*/
void publish_ac_state()
{
@ -969,10 +972,10 @@ void publish_ac_state()
/**
* @brief Callback function for handling AC state changes.
*
*
* This function is called whenever a message is received on the AC_SET_TEMPERATURE_TOPIC, AC_SET_MODE_TOPIC, or AC_SET_FAN_TOPIC.
* It parses the payload of the message and updates the AC state accordingly.
*
*
* @param topic The topic of the message.
* @param topic_length The length of the topic.
* @param payload The payload of the message.
@ -1026,7 +1029,7 @@ void ac_state_callback(char *topic, uint8_t topic_length, char *payload, unsigne
/**
* @brief Sets the state of the air conditioner.
*
*
* @param mode The mode of the air conditioner (0 = off, 1 = cool, 2 = fan).
* @param temperature The temperature to set the air conditioner to (in Celsius).
* @param fan_speed The fan speed of the air conditioner (0 = low, 1 = medium, 2 = high).
@ -1072,10 +1075,10 @@ void ac_set_state(int mode, int temperature, int fan_speed)
/**
* @brief Reads the environment sensor and publishes the temperature and humidity to MQTT topics.
*
*
* @details Reads the environment sensor and publishes the temperature and humidity to MQTT topics.
* If the internal LCD is enabled, it also updates the temperature and humidity values on the LCD screen.
*
*
* @return void
*/
void publish_env_state()
@ -1115,7 +1118,7 @@ void publish_env_state()
#ifdef ENABLE_INTERNAL_LCD
/**
* @brief Initializes the LCD display and sets up the refresh intervals for the top bar and page.
*
*
*/
void lcd_begin()
{
@ -1128,7 +1131,7 @@ void lcd_begin()
/**
* @brief Runs the LCD loop, updating the display and listening for input.
*
*
*/
void lcd_loop()
{
@ -1144,7 +1147,7 @@ void lcd_loop()
/**
* @brief Refreshes the LCD display if the current page is 1.
*
*
*/
void lcd_refresh_pd()
{
@ -1156,11 +1159,11 @@ void lcd_refresh_pd()
/**
* @brief Refreshes the LCD display based on the current page.
*
*
* @details The function writes the appropriate values to the LCD display based on the current page.
*
*
* @note This function assumes that the LCD panel has already been initialized.
*
*
*/
void lcd_refresh()
{
@ -1227,10 +1230,10 @@ void lcd_refresh()
/**
* @brief Updates the top bar of the LCD display with the current time, server status, and LAN status.
*
*
* @details This function gets the current time using ESPMega_getTime() function and formats it to display on the LCD.
* It also updates the server and LAN status icons based on the standalone and ETH.linkUp() values respectively.
*
*
* @return void
*/
void lcd_top_bar_update()
@ -1246,12 +1249,12 @@ void lcd_top_bar_update()
#ifdef ENABLE_CLIMATE_MODULE
/**
* @brief Refreshes the LCD display with the current AC mode.
*
*
* This function updates the LCD display with the current AC mode, which can be one of the following:
* - 0: Off
* - 1: Cool
* - 2: Fan
*
*
* The function uses the panel object to write the appropriate image to the display for each mode.
*/
void lcd_ac_refresh_mode()
@ -1264,10 +1267,10 @@ void lcd_ac_refresh_mode()
/**
* @brief Refreshes the fan speed icons on the LCD panel based on the current AC fan speed.
*
*
* This function updates the fan speed icons on the LCD panel based on the current AC fan speed.
* It uses the panel.writeNum() function to write the appropriate fan speed icon to the panel.
*
*
*/
void lcd_ac_refresh_fan()
{
@ -1404,7 +1407,7 @@ void trigger15()
/**
* @brief Updates the PWM states and values in EEPROM if they have changed.
*
*
* If the current PWM states or values are different from the ones stored in EEPROM,
* this function updates the EEPROM with the current values.
*/
@ -1424,7 +1427,7 @@ void eeprom_pwm_update()
/**
* @brief Sets the IP address and updates it in EEPROM.
*
*
* @param address The IP address to set.
*/
void set_ip(String address)
@ -1435,7 +1438,7 @@ void set_ip(String address)
/**
* @brief Sets the subnet mask for the device.
*
*
* @param address The subnet mask address to set.
*/
void set_netmask(String address)
@ -1456,7 +1459,7 @@ void set_dns(String address)
/**
* @brief Sets the gateway IP address and updates the EEPROM.
*
*
* @param address The gateway IP address as a String.
*/
void set_gw(String address)
@ -1467,7 +1470,7 @@ void set_gw(String address)
/**
* @brief Sets the MQTT server address and updates the EEPROM.
*
*
* @param address The MQTT server address as a String.
*/
void set_mqtt_server(String address)
@ -1478,7 +1481,7 @@ void set_mqtt_server(String address)
/**
* @brief Updates the IP address in EEPROM at the specified ROM address.
*
*
* @param rom_address The ROM address where the IP address is stored.
* @param byte1 The first byte of the IP address.
* @param byte2 The second byte of the IP address.
@ -1493,7 +1496,7 @@ void eeprom_ip_update(uint16_t rom_address, uint8_t byte1, uint8_t byte2, uint8_
/**
* @brief Retrieves an IP address from EEPROM memory.
*
*
* @param rom_address The address in EEPROM memory where the IP address is stored.
* @return The retrieved IP address.
*/
@ -1506,7 +1509,7 @@ IPAddress eeprom_ip_retrieve(uint16_t rom_address)
/**
* @brief Sets the hostname for the device and writes it to non-volatile memory.
*
*
* @param hostname The hostname to set.
*/
void set_hostname(String hostname)
@ -1517,7 +1520,7 @@ void set_hostname(String hostname)
/**
* @brief Retrieves the hostname from EEPROM and stores it in the HOSTNAME variable.
*
*
*/
void eeprom_hostname_retrieve()
{
@ -1526,7 +1529,7 @@ void eeprom_hostname_retrieve()
/**
* @brief Sets the base topic for MQTT communication and writes it to EEPROM.
*
*
* @param topic The base topic to set.
*/
void set_basetopic(String topic)
@ -1537,7 +1540,7 @@ void set_basetopic(String topic)
/**
* @brief Retrieves the MQTT base topic from EEPROM and stores it in MQTT_BASE_TOPIC array.
*
*
*/
void eeprom_basetopic_retrieve()
{
@ -1546,7 +1549,7 @@ void eeprom_basetopic_retrieve()
/**
* @brief Sets the MQTT port in the EEPROM.
*
*
* @param port The MQTT port to be set.
*/
void mqtt_port_set(uint16_t port)
@ -1557,7 +1560,7 @@ void mqtt_port_set(uint16_t port)
}
/**
* @brief Retrieves the MQTT port from EEPROM and stores it in the MQTT_PORT variable.
*
*
*/
void eeprom_mqtt_port_retrieve()
{
@ -1568,7 +1571,7 @@ void eeprom_mqtt_port_retrieve()
/**
* @brief Returns the state of the PWM with the given ID.
*
*
* @param id The ID of the PWM.
* @return true if the PWM is on, false otherwise.
*/
@ -1590,7 +1593,7 @@ uint16_t pwm_get_value(int id)
/**
* @brief Returns the state of the virtual interrupt with the given ID.
*
*
* @param id The ID of the virtual interrupt.
* @return The state of the virtual interrupt.
*/
@ -1611,7 +1614,7 @@ uint8_t ac_get_temperature()
}
/**
* @brief Get the current mode of the AC system.
*
*
* @return uint8_t The current mode of the AC system.
*/
uint8_t ac_get_mode()
@ -1620,7 +1623,7 @@ uint8_t ac_get_mode()
}
/**
* @brief Get the current fan speed.
*
*
* @return uint8_t The current fan speed.
*/
uint8_t ac_get_fan_speed()
@ -1631,7 +1634,7 @@ uint8_t ac_get_fan_speed()
/**
* @brief Retrieves the MQTT username from EEPROM and stores it in the MQTT_USERNAME global variable.
*
*
*/
void eeprom_mqtt_username_retrieve()
{
@ -1639,7 +1642,7 @@ void eeprom_mqtt_username_retrieve()
}
/**
* @brief Retrieves the MQTT password from EEPROM and stores it in the MQTT_PASSWORD global variable.
*
*
*/
void eeprom_mqtt_password_retrieve()
{
@ -1647,7 +1650,7 @@ void eeprom_mqtt_password_retrieve()
}
/**
* @brief Sets the MQTT username and writes it to the EEPROM.
*
*
* @param username The MQTT username to set.
*/
void set_mqtt_username(String username)
@ -1657,7 +1660,7 @@ void set_mqtt_username(String username)
}
/**
* @brief Sets the MQTT password and writes it to the EEPROM.
*
*
* @param password The MQTT password to set.
*/
void set_mqtt_password(String password)
@ -1672,7 +1675,7 @@ void eeprom_mqtt_useauth_retrieve()
}
/**
* @brief Sets the MQTT_USE_AUTH flag and writes it to the EEPROM.
*
*
* @param use_auth A boolean value indicating whether to use authentication for MQTT.
*/
void set_mqtt_useauth(bool use_auth)
@ -1683,10 +1686,10 @@ void set_mqtt_useauth(bool use_auth)
/**
* @brief Resets the device to factory default settings.
*
* This function resets the device to its factory default settings by formatting the FRAM,
*
* This function resets the device to its factory default settings by formatting the FRAM,
* setting default IP address, gateway, and netmask values, and restarting the device.
*
*
*/
void factory_reset()
{
@ -1727,9 +1730,9 @@ void factory_reset()
/**
* @brief Checks if the device should perform a factory reset on boot.
*
*
* This function checks if pin 2 is pulled low on boot. If it is, the device will perform a factory reset.
*
*
*/
void check_boot_reset()
{