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 25, 2023
1 parent 330dfbd commit 1d1d0d0
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ MGFLAGS = -D MG_DISABLE_MD5 -D MG_DISABLE_HTTP_DIGEST_AUTH -D MG_DISABLE_MD5 -D
#SRCS = aqualinkd.c utils.c config.c aq_serial.c init_buttons.c aq_programmer.c net_services.c json_messages.c pda.c pda_menu.c \
# pda_aq_programmer.c devices_jandy.c onetouch.c onetouch_aq_programmer.c packetLogger.c devices_pentair.c color_lights.c mongoose.c

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\
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 mongoose.c


Expand Down Expand Up @@ -167,7 +167,7 @@ $(PLAY): $(PL_OBJS) $(PL_EXOBJ)
git: clean $(MAIN) $(SLOG)
./release/git_version.sh


# this is a suffix replacement rule for building .o's from .c's
# it uses automatic variables $<: the name of the prerequisite of
# the rule(a .c file) and $@: the name of the target of the rule (a .o file)
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 @@ -1231,4 +1252,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 @@ -72,6 +72,7 @@ typedef struct aqualinkkey
//#endif
unsigned char code;
int dz_idx;
int hab_id;
uint8_t special_mask;
} aqkey;

Expand Down
18 changes: 14 additions & 4 deletions aqualinkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "rs_msg_utils.h"
#include "serialadapter.h"
#include "debug_timer.h"
#include "net_services_habridge.h"

/*
#if defined AQ_DEBUG || defined AQ_TM_DEBUG
Expand Down Expand Up @@ -1228,7 +1229,7 @@ int main(int argc, char *argv[])
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 deamonize = %s\n", bool2text(_aqconfig_.deamonize));
LOG(AQUA_LOG,LOG_NOTICE, "Config log_file = %s\n", _aqconfig_.log_file);
LOG(AQUA_LOG,LOG_NOTICE, "Config enable scheduler = %s\n", bool2text(_aqconfig_.enable_scheduler));
Expand Down Expand Up @@ -1266,7 +1267,6 @@ int main(int argc, char *argv[])
_aqconfig_.readahead_b4_write = false;
}

//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 @@ -1282,8 +1282,13 @@ int main(int argc, char *argv[])
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 @@ -1543,6 +1548,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();

signal(SIGINT, intHandler);
Expand Down Expand Up @@ -1923,7 +1933,7 @@ void main_loop()

if (_aqualink_data.updated) {
broadcast_aqualinkstate(mgr.active_connections);
//_aqualink_data.updated = false;
update_habridge_state(&_aqconfig_, &_aqualink_data);
}
}

Expand Down
13 changes: 12 additions & 1 deletion config.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ 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->dzidx_air_temp = TEMP_UNKNOWN;
parms->dzidx_pool_water_temp = TEMP_UNKNOWN;
parms->dzidx_spa_water_temp = TEMP_UNKNOWN;
Expand Down Expand Up @@ -437,6 +437,9 @@ 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, "air_temp_dzidx", 14) == 0) {
_aqconfig_.dzidx_air_temp = strtoul(value, NULL, 10);
rtn=true;
Expand Down Expand Up @@ -640,6 +643,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 @@ -857,6 +863,9 @@ 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);
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 @@ -895,6 +904,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
1 change: 1 addition & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct aqconfig
char *mqtt_server;
char *mqtt_user;
char *mqtt_passwd;
char *habridge_server;
char mqtt_ID[MQTT_ID_LEN];
int dzidx_air_temp;
int dzidx_pool_water_temp;
Expand Down
Loading

0 comments on commit 1d1d0d0

Please sign in to comment.