|
|
|
@ -47,6 +47,7 @@ uint8_t utc_offset = 7;
|
|
|
|
|
float current_room_temp = 0;
|
|
|
|
|
float current_room_humid = 0;
|
|
|
|
|
#endif
|
|
|
|
|
bool pwm_report_enable = true;
|
|
|
|
|
|
|
|
|
|
// Inputs
|
|
|
|
|
#define VINT_COUNT 16
|
|
|
|
@ -69,6 +70,7 @@ const float pwm_linear_scaling_c[PWM_COUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
const int PWM_CYCLE_VALUES[PWM_CYCLE_VALUES_COUNT] = {50, 125, 255};
|
|
|
|
|
char PWM_SET_STATE_TOPIC[70];
|
|
|
|
|
char PWM_SET_VALUE_TOPIC[70];
|
|
|
|
|
char PWM_REPORT_ENABLE_TOPIC[70];
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
// LCD
|
|
|
|
@ -252,11 +254,13 @@ void fram_retrieve_init()
|
|
|
|
|
#ifdef ENABLE_WEBUI
|
|
|
|
|
ESPMega_FRAM.read(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
|
|
|
|
|
ESPMega_FRAM.read(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
|
|
|
|
|
if(strlen(WEBUI_USERNAME)==0) {
|
|
|
|
|
if (strlen(WEBUI_USERNAME) == 0)
|
|
|
|
|
{
|
|
|
|
|
strcpy(WEBUI_USERNAME, "admin");
|
|
|
|
|
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
|
|
|
|
|
}
|
|
|
|
|
if(strlen(WEBUI_PASSWORD)==0) {
|
|
|
|
|
if (strlen(WEBUI_PASSWORD) == 0)
|
|
|
|
|
{
|
|
|
|
|
strcpy(WEBUI_PASSWORD, "admin");
|
|
|
|
|
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
|
|
|
|
|
}
|
|
|
|
@ -320,6 +324,8 @@ void fram_retrieve_init()
|
|
|
|
|
strcat(PWM_SET_STATE_TOPIC, "/pwm/00/set/state");
|
|
|
|
|
memcpy(PWM_SET_VALUE_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
|
strcat(PWM_SET_VALUE_TOPIC, "/pwm/00/set/value");
|
|
|
|
|
memcpy(PWM_REPORT_ENABLE_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
|
strcat(PWM_REPORT_ENABLE_TOPIC, "/pwm/report_enable");
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
memcpy(AC_SET_MODE_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
|
strcat(AC_SET_MODE_TOPIC, "/ac/set/mode");
|
|
|
|
@ -665,6 +671,7 @@ void mqtt_subscribe()
|
|
|
|
|
mqtt.subscribe(PWM_SET_STATE_TOPIC);
|
|
|
|
|
mqtt.subscribe(PWM_SET_VALUE_TOPIC);
|
|
|
|
|
}
|
|
|
|
|
mqtt.subscribe(PWM_REPORT_ENABLE_TOPIC);
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
mqtt.subscribe(AC_SET_FAN_TOPIC);
|
|
|
|
|
mqtt.subscribe(AC_SET_TEMPERATURE_TOPIC);
|
|
|
|
@ -697,7 +704,7 @@ void mqtt_subscribe()
|
|
|
|
|
* @param payload The payload of the received message.
|
|
|
|
|
* @param length The length of the payload.
|
|
|
|
|
*/
|
|
|
|
|
void mqtt_callback(char *topic, byte *payload, unsigned int length)
|
|
|
|
|
IRAM_ATTR void mqtt_callback(char *topic, byte *payload, unsigned int length)
|
|
|
|
|
{
|
|
|
|
|
uint8_t topic_length = strlen(topic);
|
|
|
|
|
char topic_trim[50];
|
|
|
|
@ -713,6 +720,10 @@ void mqtt_callback(char *topic, byte *payload, unsigned int length)
|
|
|
|
|
{
|
|
|
|
|
pwm_value_callback(topic_trim, topic_length, payload_nt, length);
|
|
|
|
|
}
|
|
|
|
|
else if (!strcmp(topic_trim, "/pwm/report_enable"))
|
|
|
|
|
{
|
|
|
|
|
pwm_set_publish_callback(topic_trim, topic_length, payload_nt, length);
|
|
|
|
|
}
|
|
|
|
|
#ifdef ENABLE_ANALOG_MODULE
|
|
|
|
|
else if ((!strncmp(topic_trim, "/adc/", 5)) && !strncmp(topic_trim + 7, "/set/state", 10))
|
|
|
|
|
{
|
|
|
|
@ -732,7 +743,8 @@ void mqtt_callback(char *topic, byte *payload, unsigned int length)
|
|
|
|
|
{
|
|
|
|
|
const char *delimiter = ",";
|
|
|
|
|
char *token = strtok(const_cast<char *>(payload_nt), delimiter);
|
|
|
|
|
while (token != nullptr && ir_buffer_length < IR_RAW_BUFFER_LENGTH) {
|
|
|
|
|
while (token != nullptr && ir_buffer_length < IR_RAW_BUFFER_LENGTH)
|
|
|
|
|
{
|
|
|
|
|
ir_buffer[ir_buffer_length++] = atoi(token);
|
|
|
|
|
token = strtok(nullptr, delimiter);
|
|
|
|
|
}
|
|
|
|
@ -784,7 +796,7 @@ void thread_initialization()
|
|
|
|
|
* @param payload The message payload.
|
|
|
|
|
* @param payload_length The length of the message payload.
|
|
|
|
|
*/
|
|
|
|
|
void pwm_state_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
|
|
|
|
|
IRAM_ATTR void pwm_state_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
|
|
|
|
|
{
|
|
|
|
|
int a = topic[5] - '0';
|
|
|
|
|
int b = topic[6] - '0';
|
|
|
|
@ -810,7 +822,7 @@ void pwm_state_callback(char *topic, uint8_t topic_length, char *payload, unsign
|
|
|
|
|
* @param payload The message payload.
|
|
|
|
|
* @param payload_length The length of the message payload.
|
|
|
|
|
*/
|
|
|
|
|
void pwm_value_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
|
|
|
|
|
IRAM_ATTR void pwm_value_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
|
|
|
|
|
{
|
|
|
|
|
int a = topic[5] - '0';
|
|
|
|
|
int b = topic[6] - '0';
|
|
|
|
@ -869,6 +881,7 @@ void publish_pwm_states()
|
|
|
|
|
for (int i = 0; i < PWM_COUNT; i++)
|
|
|
|
|
{
|
|
|
|
|
publish_pwm_state(i);
|
|
|
|
|
publish_pwm_value(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -879,12 +892,11 @@ void publish_pwm_states()
|
|
|
|
|
*/
|
|
|
|
|
void publish_pwm_state(int id)
|
|
|
|
|
{
|
|
|
|
|
if (!pwm_report_enable)
|
|
|
|
|
return;
|
|
|
|
|
int state = pwm_states[id];
|
|
|
|
|
int value = pwm_values[id];
|
|
|
|
|
PWM_STATE_TOPIC[base_topic_length + 4] = ((id - id % 10) / 10) + '0';
|
|
|
|
|
PWM_STATE_TOPIC[base_topic_length + 5] = (id % 10) + '0';
|
|
|
|
|
PWM_VALUE_TOPIC[base_topic_length + 4] = ((id - id % 10) / 10) + '0';
|
|
|
|
|
PWM_VALUE_TOPIC[base_topic_length + 5] = (id % 10) + '0';
|
|
|
|
|
if (state == 1)
|
|
|
|
|
{
|
|
|
|
|
mqtt.publish(PWM_STATE_TOPIC, "on");
|
|
|
|
@ -893,6 +905,15 @@ void publish_pwm_state(int id)
|
|
|
|
|
{
|
|
|
|
|
mqtt.publish(PWM_STATE_TOPIC, "off");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void publish_pwm_value(int id)
|
|
|
|
|
{
|
|
|
|
|
if (!pwm_report_enable)
|
|
|
|
|
return;
|
|
|
|
|
int value = pwm_values[id];
|
|
|
|
|
PWM_VALUE_TOPIC[base_topic_length + 4] = ((id - id % 10) / 10) + '0';
|
|
|
|
|
PWM_VALUE_TOPIC[base_topic_length + 5] = (id % 10) + '0';
|
|
|
|
|
char temp[6];
|
|
|
|
|
itoa(value, temp, DEC);
|
|
|
|
|
mqtt.publish(PWM_VALUE_TOPIC, temp);
|
|
|
|
@ -904,7 +925,7 @@ void publish_pwm_state(int id)
|
|
|
|
|
* @param id The ID of the PWM pin.
|
|
|
|
|
* @param state The new state of the PWM pin.
|
|
|
|
|
*/
|
|
|
|
|
void pwm_set_state(int id, int state)
|
|
|
|
|
IRAM_ATTR void pwm_set_state(int id, int state)
|
|
|
|
|
{
|
|
|
|
|
if (state != pwm_states[id])
|
|
|
|
|
{
|
|
|
|
@ -928,7 +949,7 @@ void pwm_set_state(int id, int state)
|
|
|
|
|
* @param id The id of the PWM pin.
|
|
|
|
|
* @param value The value to set the PWM pin to.
|
|
|
|
|
*/
|
|
|
|
|
void pwm_set_value(int id, int value)
|
|
|
|
|
IRAM_ATTR void pwm_set_value(int id, int value)
|
|
|
|
|
{
|
|
|
|
|
pwm_values[id] = value;
|
|
|
|
|
int pwm_state = pwm_states[id];
|
|
|
|
@ -939,7 +960,7 @@ void pwm_set_value(int id, int value)
|
|
|
|
|
else if (lcd_current_page == 5 && id == lcd_pwmAdj_id)
|
|
|
|
|
panel.writeNum("pwm_value.val", pwm_values[lcd_pwmAdj_id]);
|
|
|
|
|
#endif
|
|
|
|
|
publish_pwm_state(id);
|
|
|
|
|
publish_pwm_value(id);
|
|
|
|
|
pwm_changed_user_callback(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1055,6 +1076,11 @@ void publish_input_state(int id, int state)
|
|
|
|
|
mqtt.publish(INPUTS_TOPIC, state ? "1" : "0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pwm_set_publish_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
|
|
|
|
|
{
|
|
|
|
|
pwm_report_enable = !strcmp(payload, "on");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Callback function to request the current state of the device.
|
|
|
|
|
*
|
|
|
|
@ -1065,6 +1091,7 @@ void state_request_callback()
|
|
|
|
|
{
|
|
|
|
|
publish_input_states();
|
|
|
|
|
publish_pwm_states();
|
|
|
|
|
pwm_report_enable = true;
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
publish_ac_state();
|
|
|
|
|
publish_env_state();
|
|
|
|
@ -1241,6 +1268,8 @@ void ac_set_state(int mode, int temperature, int fan_speed)
|
|
|
|
|
*/
|
|
|
|
|
void publish_env_state()
|
|
|
|
|
{
|
|
|
|
|
if(!pwm_report_enable)
|
|
|
|
|
return;
|
|
|
|
|
int errorCode = env_sensor.read();
|
|
|
|
|
yield();
|
|
|
|
|
switch (errorCode)
|
|
|
|
@ -2267,8 +2296,10 @@ bool dac_get_state(int id)
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void virtual_interrupt_preload() {
|
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
|
void virtual_interrupt_preload()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
virtual_interupt_state[i] = ESPMega_digitalRead(virtual_interrupt_pins[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|