Skip to content

Commit

Permalink
#17: Status sync into ha-bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
ballle98 committed May 20, 2024
1 parent 0c9c05b commit 77638e1
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 11 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ endif


# Main source files
SRCS = aqualinkd.c utils.c config.c aq_serial.c aq_panel.c aq_programmer.c net_services.c json_messages.c rs_msg_utils.c\
devices_jandy.c packetLogger.c devices_pentair.c color_lights.c serialadapter.c aq_timer.c aq_scheduler.c web_config.c\
serial_logger.c mongoose.c simulator.c timespec_subtract.c

SRCS = aqualinkd.c utils.c config.c aq_serial.c aq_panel.c aq_programmer.c \
net_services.c net_services_habridge.c json_messages.c rs_msg_utils.c \
devices_jandy.c packetLogger.c devices_pentair.c color_lights.c \
serialadapter.c aq_timer.c aq_scheduler.c web_config.c serial_logger.c \
mongoose.c simulator.c timespec_subtract.c

AQ_FLAGS =
# Add source and flags depending on protocols to support.
Expand Down
25 changes: 23 additions & 2 deletions aq_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_PUMP;
aqdata->aqbuttons[index].code = KEY_PUMP;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -273,6 +274,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_SPA;
aqdata->aqbuttons[index].code = KEY_SPA;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;
}
Expand All @@ -283,6 +285,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUX1;
aqdata->aqbuttons[index].code = KEY_AUX1;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -292,6 +295,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUX2;
aqdata->aqbuttons[index].code = KEY_AUX2;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -301,6 +305,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUX3;
aqdata->aqbuttons[index].code = KEY_AUX3;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -312,6 +317,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUX4;
aqdata->aqbuttons[index].code = KEY_AUX4;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -321,6 +327,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUX5;
aqdata->aqbuttons[index].code = KEY_AUX5;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;
}
Expand All @@ -332,6 +339,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUX6;
aqdata->aqbuttons[index].code = KEY_AUX6;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -341,6 +349,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUX7;
aqdata->aqbuttons[index].code = KEY_AUX7;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;
}
Expand All @@ -362,6 +371,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUXB1;
aqdata->aqbuttons[index].code = KEY_AUXB1;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -371,6 +381,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUXB2;
aqdata->aqbuttons[index].code = KEY_AUXB2;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -380,6 +391,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUXB3;
aqdata->aqbuttons[index].code = KEY_AUXB3;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -389,6 +401,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUXB4;
aqdata->aqbuttons[index].code = KEY_AUXB4;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;
}
Expand All @@ -400,6 +413,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUXB5;
aqdata->aqbuttons[index].code = KEY_AUXB5;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -409,6 +423,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUXB6;
aqdata->aqbuttons[index].code = KEY_AUXB6;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -418,14 +433,16 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUXB7;
aqdata->aqbuttons[index].code = KEY_AUXB7;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
index++;
aqdata->aqbuttons[index].hab_id = 0;
index++;

aqdata->aqbuttons[index].led = &aqdata->aqualinkleds[24-1]; // doesn't actually exist
aqdata->aqbuttons[index].led->state = OFF; // Since there is no LED in data, set to off and allow messages to turn it on
aqdata->aqbuttons[index].label = name2label(BTN_AUXB8);
aqdata->aqbuttons[index].name = BTN_AUXB8;
aqdata->aqbuttons[index].code = KEY_AUXB8;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;
}
Expand All @@ -440,6 +457,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_AUX6;
aqdata->aqbuttons[index].code = KEY_AUX6;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;
}
Expand All @@ -461,6 +479,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_POOL_HTR;
aqdata->aqbuttons[index].code = KEY_POOL_HTR;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -470,6 +489,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_SPA_HTR;
aqdata->aqbuttons[index].code = KEY_SPA_HTR;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand All @@ -479,6 +499,7 @@ void initPanelButtons(struct aqualinkdata *aqdata, bool rs, int size, bool combo
aqdata->aqbuttons[index].name = BTN_SOLAR_HTR;
aqdata->aqbuttons[index].code = KEY_SOLAR_HTR;
aqdata->aqbuttons[index].dz_idx = DZ_NULL_IDX;
aqdata->aqbuttons[index].hab_id = 0;
aqdata->aqbuttons[index].special_mask = 0;
index++;

Expand Down Expand Up @@ -1232,4 +1253,4 @@ void initButtons_OLD_RS16(struct aqualinkdata *aqdata)

}

#endif
#endif
1 change: 1 addition & 0 deletions aqualink.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ typedef struct aqualinkkey
//#endif
unsigned char code;
int dz_idx;
int hab_id;
uint8_t special_mask;
} aqkey;

Expand Down
18 changes: 15 additions & 3 deletions aqualinkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#ifdef AQ_MANAGER
#include "serial_logger.h"
#endif
#include "net_services_habridge.h"

/*
#if defined AQ_DEBUG || defined AQ_TM_DEBUG
Expand Down Expand Up @@ -1293,7 +1294,8 @@ int startup(char *self, char *cfgFile)
LOG(AQUA_LOG,LOG_NOTICE, "Config idx pool thermostat = %d\n", _aqconfig_.dzidx_pool_thermostat);
LOG(AQUA_LOG,LOG_NOTICE, "Config idx spa thermostat = %d\n", _aqconfig_.dzidx_spa_thermostat);
*/

LOG(AQUA_LOG,LOG_NOTICE, "Config habridge_server = %s\n", _aqconfig_.habridge_server);
LOG(AQUA_LOG,LOG_NOTICE, "Config habridge_user = %s\n", _aqconfig_.habridge_user);
LOG(AQUA_LOG,LOG_NOTICE, "Config deamonize = %s\n", bool2text(_aqconfig_.deamonize));
#ifndef AQ_MANAGER
LOG(AQUA_LOG,LOG_NOTICE, "Config log_file = %s\n", _aqconfig_.log_file);
Expand Down Expand Up @@ -1335,7 +1337,6 @@ int startup(char *self, char *cfgFile)
LOG(AQUA_LOG,LOG_NOTICE, "RS Poll Speed = %d\n", _aqconfig_.rs_poll_speed);
#endif

//for (i = 0; i < TOTAL_BUTONS; i++)
for (i = 0; i < _aqualink_data.total_buttons; i++)
{
//char ext[] = " VSP ID None | AL ID 0 ";
Expand All @@ -1351,8 +1352,13 @@ int startup(char *self, char *cfgFile)
sprintf(ext,"Light Progm | CTYPE %-1d |",_aqualink_data.lights[j].lightType);
}
}
if (_aqualink_data.aqbuttons[i].dz_idx > 0)
if (_aqualink_data.aqbuttons[i].dz_idx > 0) {
sprintf(ext+strlen(ext), "dzidx %-3d", _aqualink_data.aqbuttons[i].dz_idx);
}
if (_aqualink_data.aqbuttons[i].hab_id > 0) {
sprintf(ext+strlen(ext), "habid %-3d", _aqualink_data.aqbuttons[i].hab_id);
}

/*
#ifdef AQ_PDA
if (isPDA_PANEL) {
Expand Down Expand Up @@ -1561,6 +1567,11 @@ void main_loop()
exit(EXIT_FAILURE);
}

if (!start_habridge_updater(&_aqconfig_, &_aqualink_data)) {
LOG(AQUA_LOG,LOG_ERR, "Can not start start_habridge_updater\n");
exit(EXIT_FAILURE);
}

startPacketLogger();

int blank_read = 0;
Expand Down Expand Up @@ -1933,6 +1944,7 @@ void main_loop()
#ifdef AQ_NO_THREAD_NETSERVICE
if (_aqualink_data.updated) {
broadcast_aqualinkstate();
update_habridge_state(&_aqconfig_, &_aqualink_data);
}
#endif
}
Expand Down
18 changes: 17 additions & 1 deletion config.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ void init_parameters (struct aqconfig * parms)
parms->mqtt_server = DEFAULT_MQTT_SERVER;
parms->mqtt_user = DEFAULT_MQTT_USER;
parms->mqtt_passwd = DEFAULT_MQTT_PASSWD;

parms->habridge_server = NULL;
parms->habridge_user = NULL;
parms->dzidx_air_temp = TEMP_UNKNOWN;
parms->dzidx_pool_water_temp = TEMP_UNKNOWN;
parms->dzidx_spa_water_temp = TEMP_UNKNOWN;
Expand Down Expand Up @@ -451,6 +452,12 @@ bool setConfigValue(struct aqualinkdata *aqdata, char *param, char *value) {
} else if (strncasecmp(param, "mqtt_passwd", 11) == 0) {
_aqconfig_.mqtt_passwd = cleanalloc(value);
rtn=true;
} else if (strncasecmp(param, "habridge_server", 15) == 0) {
_aqconfig_.habridge_server = cleanalloc(value);
rtn=true;
} else if (strncasecmp(param, "habridge_user", 13) == 0) {
_aqconfig_.habridge_user = cleanalloc(value);
rtn=true;
} else if (strncasecmp(param, "air_temp_dzidx", 14) == 0) {
_aqconfig_.dzidx_air_temp = strtoul(value, NULL, 10);
rtn=true;
Expand Down Expand Up @@ -683,6 +690,9 @@ bool setConfigValue(struct aqualinkdata *aqdata, char *param, char *value) {
LOG(AQUA_LOG,LOG_ERR, "Config error, VSP Pumps limited to %d, ignoring %s'\n",MAX_PUMPS,param);
}
rtn=true;
} else if (strncasecmp(param + 9, "_habid", 6) == 0) {
aqdata->aqbuttons[num].hab_id = strtoul(value, NULL, 10);
rtn=true;
}
/*
} else if (strncasecmp(param + 9, "_pumpID", 7) == 0) {
Expand Down Expand Up @@ -900,6 +910,10 @@ bool writeCfg (struct aqualinkdata *aqdata)
writeCharValue(fp, "mqtt_user", _aqconfig_.mqtt_user);
writeCharValue(fp, "mqtt_passwd", _aqconfig_.mqtt_passwd);
fprintf(fp, "\n#** HA Bridge Configuration **\n");
writeCharValue(fp, "habridge_server", config_parameters->habridge_server);
writeCharValue(fp, "habridge_user", config_parameters->habridge_user);
fprintf(fp, "\n#** General **\n");
fprintf(fp, "convert_mqtt_temp_to_c = %s\n", bool2text(_aqconfig_.convert_mqtt_temp));
fprintf(fp, "override_freeze_protect = %s\n", bool2text(_aqconfig_.override_freeze_protect));
Expand Down Expand Up @@ -938,6 +952,8 @@ bool writeCfg (struct aqualinkdata *aqdata)
fprintf(fp, "button_%.2d_dzidx = %d\n", i+1, aqdata->aqbuttons[i].dz_idx);
if (aqdata->aqbuttons[i].pda_label != NULL)
fprintf(fp, "button_%.2d_PDA_label = %s\n", i+1, aqdata->aqbuttons[i].pda_label);
if (aqdata->aqbuttons[i].hab_id > 0)
fprintf(fp, "button_%.2d_habid = %d\n", i+1, aqdata->aqbuttons[i].hab_id);
}
fclose(fp);
remount_root_ro(fs);
Expand Down
2 changes: 2 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct aqconfig
char *mqtt_server;
char *mqtt_user;
char *mqtt_passwd;
char *habridge_server;
char *habridge_user;
char mqtt_ID[MQTT_ID_LEN+1];
int dzidx_air_temp;
int dzidx_pool_water_temp;
Expand Down
Loading

0 comments on commit 77638e1

Please sign in to comment.