2017-12-30 20:12:01 +00:00
/*
* Copyright ( c ) 2017 Shaun Feakes - All rights reserved
*
* You may use redistribute and / or modify this code under the terms of
* the GNU General Public License version 2 as published by the
* Free Software Foundation . For the terms of this license ,
* see < http : //www.gnu.org/licenses/>.
*
* You are free to use this software under the terms of the GNU General
* Public License , but WITHOUT ANY WARRANTY ; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
* See the GNU General Public License for more details .
*
* https : //github.com/sfeakes/aqualinkd
*/
# include <stdio.h>
# include <stdlib.h>
# include <stdarg.h>
# include <string.h>
# include <ctype.h>
2023-05-14 21:35:13 +00:00
# include <errno.h>
2017-12-30 20:12:01 +00:00
# include <libgen.h>
# include <sys/ioctl.h>
//#include <sys/socket.h>
//#include <sys/time.h>
//#include <syslog.h>
//#include <unistd.h>
# include <netdb.h>
//#include <linux/if.h>
//#include <sys/types.h>
# include <unistd.h>
# include <net/if.h>
2020-06-01 00:35:17 +00:00
# define CONFIG_C
2017-12-30 20:12:01 +00:00
# include "config.h"
# include "utils.h"
# include "aq_serial.h"
2020-07-18 16:37:19 +00:00
# include "aq_panel.h"
2020-07-19 16:20:18 +00:00
# include "aqualink.h"
2017-12-30 20:12:01 +00:00
# define MAXCFGLINE 256
2020-06-01 00:35:17 +00:00
2017-12-30 20:12:01 +00:00
char * generate_mqtt_id ( char * buf , int len ) ;
2020-06-01 00:35:17 +00:00
pump_detail * getpump ( struct aqualinkdata * aqdata , int button ) ;
2017-12-30 20:12:01 +00:00
2020-07-18 16:37:19 +00:00
struct tmpPanelInfo {
int size ;
bool rs ;
bool combo ;
bool dual ;
} ;
struct tmpPanelInfo * _tmpPanel ;
2017-12-30 20:12:01 +00:00
/*
* initialize data to default values
*/
void init_parameters ( struct aqconfig * parms )
{
2020-07-18 16:37:19 +00:00
// Set default panel if it get's missed from config
_tmpPanel = malloc ( sizeof ( struct tmpPanelInfo ) ) ;
_tmpPanel - > size = 8 ;
_tmpPanel - > rs = true ;
_tmpPanel - > combo = true ;
_tmpPanel - > dual = false ;
2023-06-20 00:15:45 +00:00
clearDebugLogMask ( ) ;
2020-06-01 00:35:17 +00:00
//int i;
2017-12-30 20:12:01 +00:00
//char *p;
2020-07-18 16:37:19 +00:00
//parms->rs_panel_size = 8;
2017-12-30 20:12:01 +00:00
parms - > serial_port = DEFAULT_SERIALPORT ;
parms - > log_level = DEFAULT_LOG_LEVEL ;
parms - > socket_port = DEFAULT_WEBPORT ;
parms - > web_directory = DEFAULT_WEBROOT ;
//parms->device_id = strtoul(DEFAULT_DEVICE_ID, &p, 16);
parms - > device_id = strtoul ( DEFAULT_DEVICE_ID , NULL , 16 ) ;
2020-08-28 19:12:38 +00:00
parms - > rssa_device_id = NUL ;
2023-05-30 23:14:04 +00:00
parms - > RSSD_LOG_filter = NUL ;
2020-07-18 16:37:19 +00:00
parms - > paneltype_mask = 0 ;
# if defined AQ_ONETOUCH || defined AQ_IAQTOUCH
parms - > extended_device_id = NUL ;
parms - > extended_device_id_programming = false ;
# endif
2017-12-30 20:12:01 +00:00
//sscanf(DEFAULT_DEVICE_ID, "0x%x", &parms->device_id);
2018-03-13 14:14:21 +00:00
parms - > override_freeze_protect = FALSE ;
2017-12-30 20:12:01 +00:00
parms - > mqtt_dz_sub_topic = DEFAULT_MQTT_DZ_OUT ;
parms - > mqtt_dz_pub_topic = DEFAULT_MQTT_DZ_IN ;
parms - > mqtt_aq_topic = DEFAULT_MQTT_AQ_TP ;
parms - > mqtt_server = DEFAULT_MQTT_SERVER ;
parms - > mqtt_user = DEFAULT_MQTT_USER ;
parms - > mqtt_passwd = DEFAULT_MQTT_PASSWD ;
parms - > dzidx_air_temp = TEMP_UNKNOWN ;
parms - > dzidx_pool_water_temp = TEMP_UNKNOWN ;
parms - > dzidx_spa_water_temp = TEMP_UNKNOWN ;
2023-05-14 21:35:13 +00:00
parms - > dzidx_swg_percent = TEMP_UNKNOWN ;
parms - > dzidx_swg_ppm = TEMP_UNKNOWN ;
2017-12-30 20:12:01 +00:00
//parms->dzidx_pool_thermostat = TEMP_UNKNOWN; // removed until domoticz has a better virtual thermostat
//parms->dzidx_spa_thermostat = TEMP_UNKNOWN; // removed until domoticz has a better virtual thermostat
parms - > light_programming_mode = 0 ;
2018-07-15 19:36:19 +00:00
parms - > light_programming_initial_on = 15 ;
parms - > light_programming_initial_off = 12 ;
2020-06-06 16:36:04 +00:00
//parms->light_programming_button_pool = TEMP_UNKNOWN;
//parms->light_programming_button_spa = TEMP_UNKNOWN;
2017-12-30 20:12:01 +00:00
parms - > deamonize = true ;
2023-07-08 16:14:44 +00:00
# ifndef AQ_MANAGER
2017-12-30 20:12:01 +00:00
parms - > log_file = ' \0 ' ;
2023-07-08 16:14:44 +00:00
# endif
2020-06-20 16:09:54 +00:00
# ifdef AQ_PDA
2019-05-25 16:52:36 +00:00
parms - > pda_sleep_mode = false ;
2020-06-20 16:09:54 +00:00
# endif
2020-07-18 16:37:19 +00:00
//parms->onetouch_mode = false;
2018-07-15 19:36:19 +00:00
parms - > convert_mqtt_temp = true ;
parms - > convert_dz_temp = true ;
2019-01-18 03:38:25 +00:00
parms - > report_zero_pool_temp = false ;
2018-07-15 19:36:19 +00:00
parms - > report_zero_spa_temp = false ;
2020-08-28 19:12:38 +00:00
//parms->read_all_devices = true;
//parms->read_pentair_packets = false;
parms - > read_RS485_devmask = 0 ;
2019-05-25 16:52:36 +00:00
parms - > use_panel_aux_labels = false ;
2023-05-14 21:35:13 +00:00
2019-05-25 16:52:36 +00:00
parms - > force_swg = false ;
2023-06-04 21:17:48 +00:00
parms - > force_ps_setpoints = false ;
2023-07-08 16:14:44 +00:00
parms - > force_frzprotect_setpoints = false ;
2019-08-17 14:04:37 +00:00
//parms->swg_pool_and_spa = false;
2020-08-28 19:12:38 +00:00
parms - > swg_zero_ignore = DEFAULT_SWG_ZERO_IGNORE_COUNT ;
2019-08-18 20:54:10 +00:00
parms - > display_warnings_web = false ;
2023-05-14 21:35:13 +00:00
parms - > log_protocol_packets = false ; // Read & Write as packets write to file
parms - > log_raw_bytes = false ; // bytes read and write to file
2020-07-18 16:37:19 +00:00
parms - > sync_panel_time = true ;
2020-08-28 19:12:38 +00:00
2023-06-04 21:17:48 +00:00
# ifdef AQ_NO_THREAD_NETSERVICE
2020-07-26 19:28:58 +00:00
parms - > rs_poll_speed = DEFAULT_POLL_SPEED ;
2020-08-28 19:12:38 +00:00
parms - > thread_netservices = true ;
2023-06-04 21:17:48 +00:00
# endif
2020-07-19 16:20:18 +00:00
2023-05-14 21:35:13 +00:00
parms - > enable_scheduler = true ;
2023-06-04 21:17:48 +00:00
parms - > ftdi_low_latency = true ;
2024-03-30 16:51:31 +00:00
parms - > frame_delay = 0 ;
2024-04-15 20:00:14 +00:00
2017-12-30 20:12:01 +00:00
generate_mqtt_id ( parms - > mqtt_ID , MQTT_ID_LEN ) ;
}
char * cleanalloc ( char * str )
{
2023-05-14 21:35:13 +00:00
if ( str = = NULL )
return str ;
2017-12-30 20:12:01 +00:00
char * result ;
str = cleanwhitespace ( str ) ;
result = ( char * ) malloc ( strlen ( str ) + 1 ) ;
strcpy ( result , str ) ;
//printf("Result=%s\n",result);
return result ;
}
2018-09-23 21:54:15 +00:00
/*
2017-12-30 20:12:01 +00:00
char * cleanallocindex ( char * str , int index )
{
char * result ;
int i ;
int found = 1 ;
int loc1 = 0 ;
int loc2 = strlen ( str ) ;
for ( i = 0 ; i < loc2 ; i + + ) {
if ( str [ i ] = = ' ; ' ) {
found + + ;
if ( found = = index )
loc1 = i ;
else if ( found = = ( index + 1 ) )
loc2 = i ;
}
}
if ( found < index )
return NULL ;
// Trim leading & trailing spaces
loc1 + + ;
while ( isspace ( str [ loc1 ] ) ) loc1 + + ;
loc2 - - ;
while ( isspace ( str [ loc2 ] ) ) loc2 - - ;
// Allocate and copy
result = ( char * ) malloc ( loc2 - loc1 + 2 * sizeof ( char ) ) ;
strncpy ( result , & str [ loc1 ] , loc2 - loc1 + 1 ) ;
result [ loc2 - loc1 + 1 ] = ' \0 ' ;
return result ;
}
2018-09-23 21:54:15 +00:00
*/
2017-12-30 20:12:01 +00:00
// Find the first network interface with valid MAC and put mac address into buffer upto length
bool mac ( char * buf , int len )
{
struct ifreq s ;
int fd = socket ( PF_INET , SOCK_DGRAM , IPPROTO_IP ) ;
struct if_nameindex * if_nidxs , * intf ;
if_nidxs = if_nameindex ( ) ;
if ( if_nidxs ! = NULL )
{
for ( intf = if_nidxs ; intf - > if_index ! = 0 | | intf - > if_name ! = NULL ; intf + + )
{
strcpy ( s . ifr_name , intf - > if_name ) ;
if ( 0 = = ioctl ( fd , SIOCGIFHWADDR , & s ) )
{
int i ;
if ( s . ifr_addr . sa_data [ 0 ] = = 0 & &
s . ifr_addr . sa_data [ 1 ] = = 0 & &
s . ifr_addr . sa_data [ 2 ] = = 0 & &
s . ifr_addr . sa_data [ 3 ] = = 0 & &
s . ifr_addr . sa_data [ 4 ] = = 0 & &
s . ifr_addr . sa_data [ 5 ] = = 0 ) {
continue ;
}
for ( i = 0 ; i < 6 & & i * 2 < len ; + + i )
{
sprintf ( & buf [ i * 2 ] , " %02x " , ( unsigned char ) s . ifr_addr . sa_data [ i ] ) ;
}
return true ;
}
}
}
return false ;
}
char * generate_mqtt_id ( char * buf , int len ) {
extern char * __progname ; // glibc populates this
int i ;
strncpy ( buf , basename ( __progname ) , len ) ;
i = strlen ( buf ) ;
if ( i < len ) {
buf [ i + + ] = ' _ ' ;
// If we can't get MAC to pad mqtt id then use PID
if ( ! mac ( & buf [ i ] , len - i ) ) {
sprintf ( & buf [ i ] , " %.*d " , ( len - i ) , getpid ( ) ) ;
}
}
2019-05-18 00:48:20 +00:00
2017-12-30 20:12:01 +00:00
buf [ len ] = ' \0 ' ;
return buf ;
}
2018-09-23 21:54:15 +00:00
/*
void readCfg_OLD ( struct aqconfig * config_parameters , struct aqualinkdata * aqdata , char * cfgFile )
2017-12-30 20:12:01 +00:00
{
FILE * fp ;
char bufr [ MAXCFGLINE ] ;
//const char delim[2] = ";";
//char *buf;
//int line = 0;
//int tokenindex = 0;
char * b_ptr ;
if ( ( fp = fopen ( cfgFile , " r " ) ) ! = NULL ) {
while ( ! feof ( fp ) ) {
if ( fgets ( bufr , MAXCFGLINE , fp ) ! = NULL )
{
b_ptr = & bufr [ 0 ] ;
char * indx ;
// Eat leading whitespace
while ( isspace ( * b_ptr ) ) b_ptr + + ;
if ( b_ptr [ 0 ] ! = ' \0 ' & & b_ptr [ 0 ] ! = ' # ' )
{
indx = strchr ( b_ptr , ' = ' ) ;
if ( indx ! = NULL )
{
if ( strncasecmp ( b_ptr , " socket_port " , 11 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
//_aqconfig_.socket_port = cleanint(indx+1);
_aqconfig_ . socket_port = cleanalloc ( indx + 1 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " serial_port " , 11 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . serial_port = cleanalloc ( indx + 1 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " log_level " , 9 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . log_level = text2elevel ( cleanalloc ( indx + 1 ) ) ;
2017-12-30 20:12:01 +00:00
// should fee mem here
} else if ( strncasecmp ( b_ptr , " device_id " , 9 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . device_id = strtoul ( cleanalloc ( indx + 1 ) , NULL , 16 ) ;
2017-12-30 20:12:01 +00:00
// should fee mem here
} else if ( strncasecmp ( b_ptr , " web_directory " , 13 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . web_directory = cleanalloc ( indx + 1 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " log_file " , 8 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . log_file = cleanalloc ( indx + 1 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " mqtt_address " , 12 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_server = cleanalloc ( indx + 1 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " mqtt_dz_sub_topic " , 17 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_dz_sub_topic = cleanalloc ( indx + 1 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " mqtt_dz_pub_topic " , 17 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_dz_pub_topic = cleanalloc ( indx + 1 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " mqtt_aq_topic " , 13 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_aq_topic = cleanalloc ( indx + 1 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " mqtt_user " , 9 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_user = cleanalloc ( indx + 1 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " mqtt_passwd " , 11 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_passwd = cleanalloc ( indx + 1 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " air_temp_dzidx " , 14 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_air_temp = strtoul ( indx + 1 , NULL , 10 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " pool_water_temp_dzidx " , 21 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_pool_water_temp = strtoul ( indx + 1 , NULL , 10 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " spa_water_temp_dzidx " , 20 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_spa_water_temp = strtoul ( indx + 1 , NULL , 10 ) ;
2017-12-30 20:12:01 +00:00
} else if ( strncasecmp ( b_ptr , " light_programming_mode " , 21 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . light_programming_mode = atof ( cleanalloc ( indx + 1 ) ) ; // should free this
2018-07-25 16:24:10 +00:00
} else if ( strncasecmp ( b_ptr , " light_programming_initial_on " , 28 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . light_programming_initial_on = strtoul ( indx + 1 , NULL , 10 ) ;
2018-07-25 16:24:10 +00:00
} else if ( strncasecmp ( b_ptr , " light_programming_initial_off " , 29 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . light_programming_initial_off = strtoul ( indx + 1 , NULL , 10 ) ;
2018-07-15 19:36:19 +00:00
} else if ( strncasecmp ( b_ptr , " light_programming_button " , 21 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . light_programming_button = strtoul ( indx + 1 , NULL , 10 ) - 1 ;
2018-03-12 23:18:09 +00:00
} else if ( strncasecmp ( b_ptr , " SWG_percent_dzidx " , 17 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_swg_percent = strtoul ( indx + 1 , NULL , 10 ) ;
2018-03-12 23:18:09 +00:00
} else if ( strncasecmp ( b_ptr , " SWG_PPM_dzidx " , 13 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_swg_ppm = strtoul ( indx + 1 , NULL , 10 ) ;
2018-06-06 00:18:44 +00:00
} else if ( strncasecmp ( b_ptr , " SWG_Status_dzidx " , 14 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_swg_status = strtoul ( indx + 1 , NULL , 10 ) ;
2018-03-13 14:14:21 +00:00
} else if ( strncasecmp ( b_ptr , " override_freeze_protect " , 23 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . override_freeze_protect = text2bool ( indx + 1 ) ;
2018-03-15 20:03:57 +00:00
} else if ( strncasecmp ( b_ptr , " pda_mode " , 8 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . pda_mode = text2bool ( indx + 1 ) ;
set_pda_mode ( _aqconfig_ . pda_mode ) ;
2018-07-15 19:36:19 +00:00
} else if ( strncasecmp ( b_ptr , " convert_mqtt_temp_to_c " , 22 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . convert_mqtt_temp = text2bool ( indx + 1 ) ;
2018-07-15 19:36:19 +00:00
} else if ( strncasecmp ( b_ptr , " convert_dz_temp_to_c " , 21 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . convert_dz_temp = text2bool ( indx + 1 ) ;
2018-07-15 19:36:19 +00:00
} else if ( strncasecmp ( b_ptr , " flash_mqtt_buttons " , 18 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . flash_mqtt_buttons = text2bool ( indx + 1 ) ;
2019-01-18 03:38:25 +00:00
} else if ( strncasecmp ( b_ptr , " report_zero_pool_temp " , 21 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . report_zero_pool_temp = text2bool ( indx + 1 ) ;
2018-07-15 19:36:19 +00:00
} else if ( strncasecmp ( b_ptr , " report_zero_spa_temp " , 20 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . report_zero_spa_temp = text2bool ( indx + 1 ) ;
2019-01-24 14:56:58 +00:00
} else if ( strncasecmp ( b_ptr , " report_zero_pool_temp " , 21 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . report_zero_pool_temp = text2bool ( indx + 1 ) ;
2018-09-23 21:54:15 +00:00
} else if ( strncasecmp ( b_ptr , " button_ " , 7 ) = = 0 ) {
2017-12-30 20:12:01 +00:00
int num = strtoul ( b_ptr + 7 , NULL , 10 ) - 1 ;
//logMessage (LOG_DEBUG, "Button %d\n", strtoul(b_ptr+7, NULL, 10));
if ( strncasecmp ( b_ptr + 9 , " _label " , 6 ) = = 0 ) {
//logMessage (LOG_DEBUG, " Label %s\n", cleanalloc(indx+1));
aqdata - > aqbuttons [ num ] . label = cleanalloc ( indx + 1 ) ;
} else if ( strncasecmp ( b_ptr + 9 , " _dzidx " , 6 ) = = 0 ) {
//logMessage (LOG_DEBUG, " dzidx %d\n", strtoul(indx+1, NULL, 10));
aqdata - > aqbuttons [ num ] . dz_idx = strtoul ( indx + 1 , NULL , 10 ) ;
2018-09-02 21:45:24 +00:00
} else if ( strncasecmp ( b_ptr + 9 , " _PDA_label " , 10 ) = = 0 ) {
//logMessage (LOG_DEBUG, " dzidx %d\n", strtoul(indx+1, NULL, 10));
aqdata - > aqbuttons [ num ] . pda_label = cleanalloc ( indx + 1 ) ;
2017-12-30 20:12:01 +00:00
}
}
}
//line++;
}
}
}
fclose ( fp ) ;
} else {
2018-09-23 21:54:15 +00:00
displayLastSystemError ( cfgFile ) ;
exit ( EXIT_FAILURE ) ;
}
}
*/
2020-06-01 00:35:17 +00:00
bool setConfigValue ( struct aqualinkdata * aqdata , char * param , char * value ) {
2018-09-23 21:54:15 +00:00
bool rtn = false ;
2020-07-18 16:37:19 +00:00
if ( strncasecmp ( param , " debug_log_mask " , 14 ) = = 0 ) {
addDebugLogMask ( strtoul ( value , NULL , 10 ) ) ;
rtn = true ;
} else if ( strncasecmp ( param , " socket_port " , 11 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . socket_port = cleanalloc ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " serial_port " , 11 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . serial_port = cleanalloc ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " log_level " , 9 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . log_level = text2elevel ( cleanalloc ( value ) ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " device_id " , 9 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . device_id = strtoul ( cleanalloc ( value ) , NULL , 16 ) ;
2020-07-18 16:37:19 +00:00
rtn = true ;
2020-08-28 19:12:38 +00:00
} else if ( strncasecmp ( param , " rssa_device_id " , 14 ) = = 0 ) {
_aqconfig_ . rssa_device_id = strtoul ( cleanalloc ( value ) , NULL , 16 ) ;
rtn = true ;
2023-05-30 23:14:04 +00:00
} else if ( strncasecmp ( param , " RSSD_LOG_filter " , 15 ) = = 0 ) {
_aqconfig_ . RSSD_LOG_filter = strtoul ( cleanalloc ( value ) , NULL , 16 ) ;
rtn = true ;
2020-07-18 16:37:19 +00:00
# if defined AQ_ONETOUCH || defined AQ_IAQTOUCH
2020-06-01 00:35:17 +00:00
} else if ( strncasecmp ( param , " extended_device_id_programming " , 30 ) = = 0 ) {
// Has to be before the below.
_aqconfig_ . extended_device_id_programming = text2bool ( value ) ;
rtn = true ;
} else if ( strncasecmp ( param , " extended_device_id " , 9 ) = = 0 ) {
2020-07-18 16:37:19 +00:00
_aqconfig_ . extended_device_id = strtoul ( cleanalloc ( value ) , NULL , 16 ) ;
2020-06-01 00:35:17 +00:00
//_config_parameters.onetouch_device_id != 0x00
2018-09-23 21:54:15 +00:00
rtn = true ;
2020-06-20 16:09:54 +00:00
# endif
2020-07-18 16:37:19 +00:00
} else if ( strncasecmp ( param , " panel_type_size " , 15 ) = = 0 ) {
_tmpPanel - > size = strtoul ( value , NULL , 10 ) ;
rtn = true ;
} else if ( strncasecmp ( param , " panel_type_combo " , 16 ) = = 0 ) {
_tmpPanel - > combo = text2bool ( value ) ;
rtn = true ;
} else if ( strncasecmp ( param , " panel_type_dual " , 15 ) = = 0 ) {
_tmpPanel - > dual = text2bool ( value ) ;
rtn = true ;
} else if ( strncasecmp ( param , " panel_type_pda " , 14 ) = = 0 ) {
_tmpPanel - > rs = ! text2bool ( value ) ;
rtn = true ;
} else if ( strncasecmp ( param , " panel_type_rs " , 13 ) = = 0 ) {
_tmpPanel - > rs = text2bool ( value ) ;
rtn = true ;
} else if ( strncasecmp ( param , " panel_type " , 10 ) = = 0 ) { // This must be last so it doesn't get picked up by other settings
setPanelByName ( aqdata , cleanwhitespace ( value ) ) ;
rtn = true ;
} else if ( strncasecmp ( param , " rs_panel_size " , 13 ) = = 0 ) {
LOG ( AQUA_LOG , LOG_WARNING , " Config error, 'rs_panel_size' no longer supported, please use 'panel_type' \n " ) ;
_tmpPanel - > size = strtoul ( value , NULL , 10 ) ;
2020-06-20 16:09:54 +00:00
rtn = true ;
2018-09-23 21:54:15 +00:00
} else if ( strncasecmp ( param , " web_directory " , 13 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . web_directory = cleanalloc ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
2023-07-08 16:14:44 +00:00
# ifndef AQ_MANAGER
2018-09-23 21:54:15 +00:00
} else if ( strncasecmp ( param , " log_file " , 8 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . log_file = cleanalloc ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
2023-07-08 16:14:44 +00:00
# endif
2018-09-23 21:54:15 +00:00
} else if ( strncasecmp ( param , " mqtt_address " , 12 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_server = cleanalloc ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " mqtt_dz_sub_topic " , 17 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_dz_sub_topic = cleanalloc ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " mqtt_dz_pub_topic " , 17 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_dz_pub_topic = cleanalloc ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " mqtt_aq_topic " , 13 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_aq_topic = cleanalloc ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " mqtt_user " , 9 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_user = cleanalloc ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " mqtt_passwd " , 11 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . mqtt_passwd = cleanalloc ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " air_temp_dzidx " , 14 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_air_temp = strtoul ( value , NULL , 10 ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " pool_water_temp_dzidx " , 21 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_pool_water_temp = strtoul ( value , NULL , 10 ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " spa_water_temp_dzidx " , 20 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_spa_water_temp = strtoul ( value , NULL , 10 ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " light_programming_mode " , 21 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . light_programming_mode = atof ( cleanalloc ( value ) ) ; // should free this
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " light_programming_initial_on " , 28 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . light_programming_initial_on = strtoul ( value , NULL , 10 ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " light_programming_initial_off " , 29 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . light_programming_initial_off = strtoul ( value , NULL , 10 ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
2019-08-18 20:54:10 +00:00
} else if ( strncasecmp ( param , " light_programming_button_spa " , 28 ) = = 0 ) {
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_ERR , " Config error, 'light_programming_button_spa' no longer supported \n " ) ;
2020-06-06 16:36:04 +00:00
//_aqconfig_.light_programming_button_spa = strtoul(value, NULL, 10) - 1;
2019-08-18 20:54:10 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " light_programming_button " , 24 ) = = 0 | |
strncasecmp ( param , " light_programming_button_pool " , 29 ) = = 0 ) {
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_ERR , " Config error, 'light_programming_button' & 'light_programming_button_pool' are no longer supported \n " ) ;
2020-06-06 16:36:04 +00:00
//_aqconfig_.light_programming_button_pool = strtoul(value, NULL, 10) - 1;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " SWG_percent_dzidx " , 17 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_swg_percent = strtoul ( value , NULL , 10 ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " SWG_PPM_dzidx " , 13 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_swg_ppm = strtoul ( value , NULL , 10 ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " SWG_Status_dzidx " , 14 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . dzidx_swg_status = strtoul ( value , NULL , 10 ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " override_freeze_protect " , 23 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . override_freeze_protect = text2bool ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
2020-06-20 16:09:54 +00:00
# ifdef AQ_PDA
2018-09-23 21:54:15 +00:00
} else if ( strncasecmp ( param , " pda_mode " , 8 ) = = 0 ) {
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_WARNING , " Config error, 'pda_mode' is no longer supported, please use rs_panel_type \n " ) ;
//_aqconfig_.pda_mode = text2bool(value);
//set_pda_mode(_aqconfig_.pda_mode);
_tmpPanel - > rs = ! text2bool ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
2019-05-25 16:52:36 +00:00
} else if ( strncasecmp ( param , " pda_sleep_mode " , 8 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . pda_sleep_mode = text2bool ( value ) ;
2019-05-25 16:52:36 +00:00
rtn = true ;
2020-06-20 16:09:54 +00:00
# endif
2018-09-23 21:54:15 +00:00
} else if ( strncasecmp ( param , " convert_mqtt_temp_to_c " , 22 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . convert_mqtt_temp = text2bool ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " convert_dz_temp_to_c " , 20 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . convert_dz_temp = text2bool ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
2019-03-01 16:05:15 +00:00
/*
2018-09-23 21:54:15 +00:00
} else if ( strncasecmp ( param , " flash_mqtt_buttons " , 18 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . flash_mqtt_buttons = text2bool ( value ) ;
2019-03-01 16:05:15 +00:00
rtn = true ; */
2018-09-23 21:54:15 +00:00
} else if ( strncasecmp ( param , " report_zero_spa_temp " , 20 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . report_zero_spa_temp = text2bool ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
2019-01-24 14:56:58 +00:00
} else if ( strncasecmp ( param , " report_zero_pool_temp " , 21 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . report_zero_pool_temp = text2bool ( value ) ;
2019-01-24 14:56:58 +00:00
rtn = true ;
2019-03-01 15:22:03 +00:00
} else if ( strncasecmp ( param , " read_all_devices " , 16 ) = = 0 ) {
2020-08-28 19:12:38 +00:00
LOG ( AQUA_LOG , LOG_WARNING , " Config error, 'read_all_devices' is no longer supported, please using one or all of 'read_RS485_swg','read_RS485_ePump','read_RS485_vsfPump' \n " ) ;
if ( text2bool ( value ) ) {
_aqconfig_ . read_RS485_devmask | = READ_RS485_SWG ;
_aqconfig_ . read_RS485_devmask | = READ_RS485_JAN_PUMP ;
} else {
_aqconfig_ . read_RS485_devmask & = ~ READ_RS485_SWG ;
_aqconfig_ . read_RS485_devmask & = ~ READ_RS485_JAN_PUMP ;
}
rtn = true ;
} else if ( strncasecmp ( param , " read_pentair_packets " , 17 ) = = 0 ) {
LOG ( AQUA_LOG , LOG_WARNING , " Config error, 'read_all_devices' is no longer supported, please using 'read_pentair_pump' \n " ) ;
if ( text2bool ( value ) )
_aqconfig_ . read_RS485_devmask | = READ_RS485_PEN_PUMP ;
else
_aqconfig_ . read_RS485_devmask & = ~ READ_RS485_PEN_PUMP ;
rtn = true ;
} else if ( strncasecmp ( param , " read_RS485_swg " , 14 ) = = 0 ) {
if ( text2bool ( value ) )
_aqconfig_ . read_RS485_devmask | = READ_RS485_SWG ;
else
_aqconfig_ . read_RS485_devmask & = ~ READ_RS485_SWG ;
rtn = true ;
} else if ( strncasecmp ( param , " read_RS485_ePump " , 16 ) = = 0 ) {
if ( text2bool ( value ) )
_aqconfig_ . read_RS485_devmask | = READ_RS485_JAN_PUMP ;
else
_aqconfig_ . read_RS485_devmask & = ~ READ_RS485_JAN_PUMP ;
rtn = true ;
} else if ( strncasecmp ( param , " read_RS485_vsfPump " , 16 ) = = 0 ) {
if ( text2bool ( value ) )
_aqconfig_ . read_RS485_devmask | = READ_RS485_PEN_PUMP ;
else
_aqconfig_ . read_RS485_devmask & = ~ READ_RS485_PEN_PUMP ;
2019-03-01 15:22:03 +00:00
rtn = true ;
2024-04-29 11:58:15 +00:00
} else if ( strncasecmp ( param , " read_RS485_JXi " , 14 ) = = 0 ) {
2023-07-08 16:14:44 +00:00
if ( text2bool ( value ) )
2024-04-29 11:58:15 +00:00
_aqconfig_ . read_RS485_devmask | = READ_RS485_JAN_JXI ;
2023-07-08 16:14:44 +00:00
else
2024-04-29 11:58:15 +00:00
_aqconfig_ . read_RS485_devmask & = ~ READ_RS485_JAN_JXI ;
rtn = true ;
} else if ( strncasecmp ( param , " read_RS485_LX " , 14 ) = = 0 ) {
if ( text2bool ( value ) )
_aqconfig_ . read_RS485_devmask | = READ_RS485_JAN_LX ;
else
_aqconfig_ . read_RS485_devmask & = ~ READ_RS485_JAN_LX ;
2023-07-08 16:14:44 +00:00
rtn = true ;
2019-05-25 16:52:36 +00:00
} else if ( strncasecmp ( param , " use_panel_aux_labels " , 20 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . use_panel_aux_labels = text2bool ( value ) ;
2019-05-25 16:52:36 +00:00
rtn = true ;
2023-06-04 21:17:48 +00:00
} else if ( strncasecmp ( param , " force_SWG " , 9 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . force_swg = text2bool ( value ) ;
2019-05-25 16:52:36 +00:00
rtn = true ;
2023-06-04 21:17:48 +00:00
} else if ( strncasecmp ( param , " force_ps_setpoints " , 18 ) = = 0 ) {
_aqconfig_ . force_ps_setpoints = text2bool ( value ) ;
rtn = true ;
2023-07-08 16:14:44 +00:00
} else if ( strncasecmp ( param , " force_frzprotect_setpoints " , 26 ) = = 0 ) {
_aqconfig_ . force_frzprotect_setpoints = text2bool ( value ) ;
rtn = true ;
2023-05-14 21:35:13 +00:00
} else if ( strncasecmp ( param , " debug_RSProtocol_bytes " , 22 ) = = 0 ) {
_aqconfig_ . log_raw_bytes = text2bool ( value ) ;
rtn = true ;
2019-05-25 16:52:36 +00:00
} else if ( strncasecmp ( param , " debug_RSProtocol_packets " , 24 ) = = 0 ) {
2023-05-14 21:35:13 +00:00
_aqconfig_ . log_protocol_packets = text2bool ( value ) ;
2019-05-25 16:52:36 +00:00
rtn = true ;
2019-08-18 20:54:10 +00:00
} else if ( strncasecmp ( param , " swg_zero_ignore_count " , 21 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . swg_zero_ignore = strtoul ( value , NULL , 10 ) ;
2019-08-18 20:54:10 +00:00
rtn = true ;
} else if ( strncasecmp ( param , " display_warnings_in_web " , 23 ) = = 0 ) {
2020-06-01 00:35:17 +00:00
_aqconfig_ . display_warnings_web = text2bool ( value ) ;
2019-08-18 20:54:10 +00:00
rtn = true ;
2020-07-18 16:37:19 +00:00
} else if ( strncasecmp ( param , " mqtt_timed_update " , 17 ) = = 0 ) {
_aqconfig_ . mqtt_timed_update = text2bool ( value ) ;
2019-06-05 16:41:38 +00:00
rtn = true ;
2020-07-18 16:37:19 +00:00
} else if ( strncasecmp ( param , " keep_paneltime_synced " , 21 ) = = 0 ) {
_aqconfig_ . sync_panel_time = text2bool ( value ) ;
rtn = true ;
2023-06-04 21:17:48 +00:00
# ifdef AQ_NO_THREAD_NETSERVICE
2020-07-19 16:20:18 +00:00
} else if ( strncasecmp ( param , " network_poll_speed " , 18 ) = = 0 ) {
2020-07-26 19:28:58 +00:00
LOG ( AQUA_LOG , LOG_WARNING , " Config error, 'network_poll_speed' is no longer supported, using value for 'rs_poll_speed' \n " ) ;
_aqconfig_ . rs_poll_speed = strtoul ( value , NULL , 10 ) ;
rtn = true ;
} else if ( strncasecmp ( param , " rs_poll_speed " , 13 ) = = 0 ) {
_aqconfig_ . rs_poll_speed = strtoul ( value , NULL , 10 ) ;
rtn = true ;
} else if ( strncasecmp ( param , " thread_netservices " , 18 ) = = 0 ) {
_aqconfig_ . thread_netservices = text2bool ( value ) ;
2020-07-19 16:20:18 +00:00
rtn = true ;
2023-06-04 21:17:48 +00:00
# endif
2023-05-14 21:35:13 +00:00
} else if ( strncasecmp ( param , " enable_scheduler " , 16 ) = = 0 ) {
_aqconfig_ . enable_scheduler = text2bool ( value ) ;
rtn = true ;
2023-06-04 21:17:48 +00:00
} else if ( strncasecmp ( param , " ftdi_low_latency " , 16 ) = = 0 ) {
_aqconfig_ . ftdi_low_latency = text2bool ( value ) ;
rtn = true ;
2024-03-30 16:51:31 +00:00
} else if ( strncasecmp ( param , " rs485_frame_delay " , 17 ) = = 0 ) {
_aqconfig_ . frame_delay = strtoul ( value , NULL , 10 ) ;
2023-06-04 21:17:48 +00:00
rtn = true ;
2024-03-30 16:51:31 +00:00
}
2018-09-23 21:54:15 +00:00
else if ( strncasecmp ( param , " button_ " , 7 ) = = 0 ) {
2020-07-18 16:37:19 +00:00
// Check we have inichalized panel information, if not use any settings we may have
if ( _aqconfig_ . paneltype_mask = = 0 )
setPanel ( aqdata , _tmpPanel - > rs , _tmpPanel - > size , _tmpPanel - > combo , _tmpPanel - > dual ) ;
2018-09-23 21:54:15 +00:00
int num = strtoul ( param + 7 , NULL , 10 ) - 1 ;
2020-07-18 16:37:19 +00:00
if ( num > TOTAL_BUTTONS ) {
LOG ( AQUA_LOG , LOG_ERR , " Config error, button_%d is out of range \n " , num + 1 ) ;
rtn = false ;
} else if ( strncasecmp ( param + 9 , " _label " , 6 ) = = 0 ) {
2018-09-23 21:54:15 +00:00
aqdata - > aqbuttons [ num ] . label = cleanalloc ( value ) ;
rtn = true ;
} else if ( strncasecmp ( param + 9 , " _dzidx " , 6 ) = = 0 ) {
aqdata - > aqbuttons [ num ] . dz_idx = strtoul ( value , NULL , 10 ) ;
rtn = true ;
2020-06-20 16:09:54 +00:00
# ifdef AQ_PDA
2018-09-23 21:54:15 +00:00
} else if ( strncasecmp ( param + 9 , " _PDA_label " , 10 ) = = 0 ) {
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_WARNING , " Config error, 'button_%d_PDA_label' is no longer supported, please use 'button_%d_label' \n " , num , num ) ;
//aqdata->aqbuttons[num].pda_label = cleanalloc(value);
aqdata - > aqbuttons [ num ] . label = cleanalloc ( value ) ;
2018-09-23 21:54:15 +00:00
rtn = true ;
2020-06-20 16:09:54 +00:00
# endif
2020-06-06 16:36:04 +00:00
} else if ( strncasecmp ( param + 9 , " _lightMode " , 10 ) = = 0 ) {
if ( aqdata - > num_lights < MAX_LIGHTS ) {
int type = strtoul ( value , NULL , 10 ) ;
2023-05-16 22:27:45 +00:00
if ( type < LC_PROGRAMABLE | | type > NUMBER_LIGHT_COLOR_TYPES ) {
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_ERR , " Config error, unknown light mode '%s' \n " , type ) ;
2020-06-06 16:36:04 +00:00
} else {
aqdata - > lights [ aqdata - > num_lights ] . button = & aqdata - > aqbuttons [ num ] ;
aqdata - > lights [ aqdata - > num_lights ] . lightType = type ;
aqdata - > num_lights + + ;
2020-08-28 19:12:38 +00:00
aqdata - > aqbuttons [ num ] . special_mask | = PROGRAM_LIGHT ;
2020-06-06 16:36:04 +00:00
}
} else {
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_ERR , " Config error, (colored|programmable) Lights limited to %d, ignoring %s' \n " , MAX_LIGHTS , param ) ;
2020-06-06 16:36:04 +00:00
}
rtn = true ;
2020-06-01 00:35:17 +00:00
} else if ( strncasecmp ( param + 9 , " _pumpID " , 7 ) = = 0 ) {
pump_detail * pump = getpump ( aqdata , num ) ;
if ( pump ! = NULL ) {
pump - > pumpID = strtoul ( cleanalloc ( value ) , NULL , 16 ) ;
2020-08-28 19:12:38 +00:00
if ( ( int ) pump - > pumpID < = PENTAIR_DEC_PUMP_MAX ) {
2020-06-06 16:36:04 +00:00
pump - > prclType = PENTAIR ;
2020-06-01 00:35:17 +00:00
} else {
2020-06-06 16:36:04 +00:00
pump - > prclType = JANDY ;
2020-06-01 00:35:17 +00:00
//pump->pumpType = EPUMP; // For testing let the interface set this
}
} else {
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_ERR , " Config error, VSP Pumps limited to %d, ignoring %s' \n " , MAX_PUMPS , param ) ;
2020-06-01 00:35:17 +00:00
}
rtn = true ;
} else if ( strncasecmp ( param + 9 , " _pumpIndex " , 10 ) = = 0 ) { //button_01_pumpIndex=1
pump_detail * pump = getpump ( aqdata , num ) ;
if ( pump ! = NULL ) {
pump - > pumpIndex = strtoul ( value , NULL , 10 ) ;
} else {
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_ERR , " Config error, VSP Pumps limited to %d, ignoring %s' \n " , MAX_PUMPS , param ) ;
2020-06-01 00:35:17 +00:00
}
rtn = true ;
2023-06-24 06:19:36 +00:00
} else if ( strncasecmp ( param + 9 , " _pumpType " , 9 ) = = 0 ) {
2023-06-24 19:15:52 +00:00
// This is not documented, as it's prefered for AqualinkD to find the pump type.
2023-06-24 06:19:36 +00:00
pump_detail * pump = getpump ( aqdata , num ) ;
if ( pump ! = NULL ) {
if ( stristr ( value , " Pentair VS " ) ! = 0 )
pump - > pumpType = VSPUMP ;
else if ( stristr ( value , " Pentair VF " ) ! = 0 )
pump - > pumpType = VFPUMP ;
else if ( stristr ( value , " Jandy ePump " ) ! = 0 )
pump - > pumpType = EPUMP ;
} else {
LOG ( AQUA_LOG , LOG_ERR , " Config error, VSP Pumps limited to %d, ignoring %s' \n " , MAX_PUMPS , param ) ;
}
rtn = true ;
2020-06-01 00:35:17 +00:00
}
/*
2019-06-07 22:54:20 +00:00
} else if ( strncasecmp ( param + 9 , " _pumpID " , 7 ) = = 0 ) {
//aqdata->aqbuttons[num].pda_label = cleanalloc(value);
2019-06-08 19:34:47 +00:00
//96 to 111 = Pentair, 120 to 123 = Jandy
if ( pi < MAX_PUMPS ) {
aqdata - > pumps [ pi ] . button = & aqdata - > aqbuttons [ num ] ;
aqdata - > pumps [ pi ] . pumpID = strtoul ( cleanalloc ( value ) , NULL , 16 ) ;
2020-06-01 00:35:17 +00:00
aqdata - > pumps [ pi ] . pumpIndex = pi + 1 ;
2019-06-08 19:34:47 +00:00
//aqdata->pumps[pi].buttonID = num;
if ( aqdata - > pumps [ pi ] . pumpID < 119 )
aqdata - > pumps [ pi ] . ptype = PENTAIR ;
else
aqdata - > pumps [ pi ] . ptype = JANDY ;
pi + + ;
2020-06-01 00:35:17 +00:00
2019-06-08 19:34:47 +00:00
} else {
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_ERR , " Config error, VSP Pumps limited to %d, ignoring %s' \n " , MAX_PUMPS , param ) ;
2019-06-08 19:34:47 +00:00
}
2019-06-07 22:54:20 +00:00
rtn = true ;
2020-06-01 00:35:17 +00:00
} else if ( strncasecmp ( param + 9 , " _pumpIndex " , 10 ) = = 0 ) { //button_01_pumpIndex=1
} */
2018-09-23 21:54:15 +00:00
}
return rtn ;
}
2020-06-06 16:36:04 +00:00
2020-06-01 00:35:17 +00:00
pump_detail * getpump ( struct aqualinkdata * aqdata , int button )
{
//static int _pumpindex = 0;
//aqdata->num_pumps
int pi ;
// Does it exist
for ( pi = 0 ; pi < aqdata - > num_pumps ; pi + + ) {
if ( aqdata - > pumps [ pi ] . button = = & aqdata - > aqbuttons [ button ] ) {
//printf ("Found pump %d\n",button);
return & aqdata - > pumps [ pi ] ;
}
}
// Create new entry
if ( aqdata - > num_pumps < MAX_PUMPS ) {
//printf ("Creating pump %d\n",button);
2020-08-28 19:12:38 +00:00
aqdata - > aqbuttons [ button ] . special_mask | = VS_PUMP ;
2020-06-01 00:35:17 +00:00
aqdata - > pumps [ aqdata - > num_pumps ] . button = & aqdata - > aqbuttons [ button ] ;
aqdata - > pumps [ aqdata - > num_pumps ] . pumpType = PT_UNKNOWN ;
aqdata - > pumps [ aqdata - > num_pumps ] . rpm = TEMP_UNKNOWN ;
aqdata - > pumps [ aqdata - > num_pumps ] . watts = TEMP_UNKNOWN ;
aqdata - > pumps [ aqdata - > num_pumps ] . gpm = TEMP_UNKNOWN ;
aqdata - > num_pumps + + ;
return & aqdata - > pumps [ aqdata - > num_pumps - 1 ] ;
}
return NULL ;
}
void init_config ( )
{
init_parameters ( & _aqconfig_ ) ;
}
2018-09-23 21:54:15 +00:00
2020-06-01 00:35:17 +00:00
//void readCfg (struct aqconfig *config_parameters, struct aqualinkdata *aqdata, char *cfgFile)
void read_config ( struct aqualinkdata * aqdata , char * cfgFile )
2018-09-23 21:54:15 +00:00
{
FILE * fp ;
char bufr [ MAXCFGLINE ] ;
//const char delim[2] = ";";
//char *buf;
//int line = 0;
//int tokenindex = 0;
char * b_ptr ;
2020-07-18 16:37:19 +00:00
2020-06-01 00:35:17 +00:00
_aqconfig_ . config_file = cleanalloc ( cfgFile ) ;
2018-09-23 21:54:15 +00:00
if ( ( fp = fopen ( cfgFile , " r " ) ) ! = NULL ) {
while ( ! feof ( fp ) ) {
if ( fgets ( bufr , MAXCFGLINE , fp ) ! = NULL )
{
b_ptr = & bufr [ 0 ] ;
char * indx ;
// Eat leading whitespace
while ( isspace ( * b_ptr ) ) b_ptr + + ;
if ( b_ptr [ 0 ] ! = ' \0 ' & & b_ptr [ 0 ] ! = ' # ' )
{
indx = strchr ( b_ptr , ' = ' ) ;
if ( indx ! = NULL )
{
2020-06-01 00:35:17 +00:00
if ( ! setConfigValue ( aqdata , b_ptr , indx + 1 ) )
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_ERR , " Unknown config parameter '%.*s' \n " , strlen ( b_ptr ) - 1 , b_ptr ) ;
2018-09-23 21:54:15 +00:00
}
}
}
}
fclose ( fp ) ;
} else {
2017-12-30 20:12:01 +00:00
/* error processing, couldn't open file */
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_ERR , " Error reading config file '%s' \n " , cfgFile ) ;
2023-05-14 21:35:13 +00:00
errno = EBADF ;
displayLastSystemError ( " Error reading config file " ) ;
2017-12-30 20:12:01 +00:00
exit ( EXIT_FAILURE ) ;
}
2020-07-18 16:37:19 +00:00
free ( _tmpPanel ) ;
2017-12-30 20:12:01 +00:00
}
2018-09-23 21:54:15 +00:00
//DEBUG_DERIAL, DEBUG, INFO, NOTICE, WARNING, ERROR
char * errorlevel2text ( int level )
{
switch ( level ) {
case LOG_DEBUG_SERIAL :
return " DEBUG_SERIAL " ;
break ;
case LOG_DEBUG :
return " DEBUG " ;
break ;
case LOG_INFO :
return " INFO " ;
break ;
case LOG_NOTICE :
return " NOTICE " ;
break ;
case LOG_WARNING :
return " WARNING " ;
break ;
case LOG_ERR :
default :
return " ERROR " ;
break ;
}
return " " ;
}
2023-05-14 21:35:13 +00:00
/*
2018-09-23 21:54:15 +00:00
bool remount_root_ro ( bool readonly ) {
// NSF Check if config is RO_ROOT set
2019-06-05 16:41:38 +00:00
if ( readonly ) { } // Dummy to stop compile warnings.
2023-05-14 21:35:13 +00:00
2018-09-23 21:54:15 +00:00
if ( readonly ) {
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_INFO , " reMounting root RO \n " ) ;
2018-09-23 21:54:15 +00:00
mount ( NULL , " / " , NULL , MS_REMOUNT | MS_RDONLY , NULL ) ;
return true ;
} else {
struct statvfs fsinfo ;
statvfs ( " / " , & fsinfo ) ;
if ( ( fsinfo . f_flag & ST_RDONLY ) = = 0 ) // We are readwrite, ignore
return false ;
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_INFO , " reMounting root RW \n " ) ;
2018-09-23 21:54:15 +00:00
mount ( NULL , " / " , NULL , MS_REMOUNT , NULL ) ;
return true ;
}
2023-05-14 21:35:13 +00:00
2018-09-23 21:54:15 +00:00
return true ;
}
2023-05-14 21:35:13 +00:00
*/
2018-09-23 21:54:15 +00:00
void writeCharValue ( FILE * fp , char * msg , char * value )
{
if ( value = = NULL )
fprintf ( fp , " #%s = \n " , msg ) ;
else
fprintf ( fp , " %s = %s \n " , msg , value ) ;
}
void writeIntValue ( FILE * fp , char * msg , int value )
{
if ( value < = 0 )
fprintf ( fp , " #%s = \n " , msg ) ;
else
fprintf ( fp , " %s = %d \n " , msg , value ) ;
}
2017-12-30 20:12:01 +00:00
2020-06-06 16:36:04 +00:00
2020-06-01 00:35:17 +00:00
bool writeCfg ( struct aqualinkdata * aqdata )
2020-06-06 16:36:04 +00:00
{
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_ERR , " writeCfg() not implimented \n " ) ;
2020-06-06 16:36:04 +00:00
/*
2018-09-23 21:54:15 +00:00
FILE * fp ;
int i ;
bool fs = remount_root_ro ( false ) ;
2020-06-01 00:35:17 +00:00
fp = fopen ( _aqconfig_ . config_file , " w " ) ;
2018-09-23 21:54:15 +00:00
if ( fp = = NULL ) {
2020-07-18 16:37:19 +00:00
LOG ( AQUA_LOG , LOG_ERR , " Open config file failed '%s' \n " , _aqconfig_ . config_file ) ;
2018-09-23 21:54:15 +00:00
remount_root_ro ( true ) ;
//fprintf(stdout, "Open file failed 'sprinkler.cron'\n");
return false ;
}
fprintf ( fp , " #***** AqualinkD configuration ***** \n " ) ;
2020-06-01 00:35:17 +00:00
fprintf ( fp , " socket_port = %s \n " , _aqconfig_ . socket_port ) ;
fprintf ( fp , " serial_port = %s \n " , _aqconfig_ . serial_port ) ;
fprintf ( fp , " device_id = 0x%02hhx \n " , _aqconfig_ . device_id ) ;
fprintf ( fp , " read_all_devices = %s " , bool2text ( _aqconfig_ . read_all_devices ) ) ;
writeCharValue ( fp , " log_level " , errorlevel2text ( _aqconfig_ . log_level ) ) ;
writeCharValue ( fp , " web_directory " , _aqconfig_ . web_directory ) ;
writeCharValue ( fp , " log_file " , _aqconfig_ . log_file ) ;
fprintf ( fp , " pda_mode = %s \n " , bool2text ( _aqconfig_ . pda_mode ) ) ;
2018-09-23 21:54:15 +00:00
fprintf ( fp , " \n #** MQTT Configuration ** \n " ) ;
2020-06-01 00:35:17 +00:00
writeCharValue ( fp , " mqtt_address " , _aqconfig_ . mqtt_server ) ;
writeCharValue ( fp , " mqtt_dz_sub_topic " , _aqconfig_ . mqtt_dz_sub_topic ) ;
writeCharValue ( fp , " mqtt_dz_pub_topic " , _aqconfig_ . mqtt_dz_pub_topic ) ;
writeCharValue ( fp , " mqtt_aq_topic " , _aqconfig_ . mqtt_aq_topic ) ;
writeCharValue ( fp , " mqtt_user " , _aqconfig_ . mqtt_user ) ;
writeCharValue ( fp , " mqtt_passwd " , _aqconfig_ . mqtt_passwd ) ;
2018-09-23 21:54:15 +00:00
fprintf ( fp , " \n #** General ** \n " ) ;
2020-06-01 00:35:17 +00:00
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 ) ) ;
//fprintf(fp, "flash_mqtt_buttons = %s\n", bool2text(_aqconfig_.flash_mqtt_buttons));
fprintf ( fp , " report_zero_spa_temp = %s \n " , bool2text ( _aqconfig_ . report_zero_spa_temp ) ) ;
fprintf ( fp , " report_zero_pool_temp = %s \n " , bool2text ( _aqconfig_ . report_zero_pool_temp ) ) ;
2018-09-23 21:54:15 +00:00
fprintf ( fp , " \n #** Programmable light ** \n " ) ;
2020-06-01 00:35:17 +00:00
//if (_aqconfig_.light_programming_button_pool <= 0) {
// fprintf(fp, "#light_programming_button_pool = %d\n", _aqconfig_.light_programming_button_pool);
// fprintf(fp, "#light_programming_mode = %f\n", _aqconfig_.light_programming_mode);
// fprintf(fp, "#light_programming_initial_on = %d\n", _aqconfig_.light_programming_initial_on);
// fprintf(fp, "#light_programming_initial_off = %d\n", _aqconfig_.light_programming_initial_off);
2019-08-18 20:54:10 +00:00
//} else {
2020-06-01 00:35:17 +00:00
fprintf ( fp , " light_programming_button_pool = %d \n " , _aqconfig_ . light_programming_button_pool ) ;
fprintf ( fp , " light_programming_button_spa = %d \n " , _aqconfig_ . light_programming_button_spa ) ;
fprintf ( fp , " light_programming_mode = %f \n " , _aqconfig_ . light_programming_mode ) ;
fprintf ( fp , " light_programming_initial_on = %d \n " , _aqconfig_ . light_programming_initial_on ) ;
fprintf ( fp , " light_programming_initial_off = %d \n " , _aqconfig_ . light_programming_initial_off ) ;
2019-08-18 20:54:10 +00:00
//}
2017-12-30 20:12:01 +00:00
2018-09-23 21:54:15 +00:00
fprintf ( fp , " \n #** Domoticz ** \n " ) ;
2020-06-01 00:35:17 +00:00
fprintf ( fp , " convert_dz_temp_to_c = %s \n " , bool2text ( _aqconfig_ . convert_dz_temp ) ) ;
writeIntValue ( fp , " air_temp_dzidx " , _aqconfig_ . dzidx_air_temp ) ;
writeIntValue ( fp , " pool_water_temp_dzidx " , _aqconfig_ . dzidx_pool_water_temp ) ;
writeIntValue ( fp , " spa_water_temp_dzidx " , _aqconfig_ . dzidx_spa_water_temp ) ;
writeIntValue ( fp , " SWG_percent_dzidx " , _aqconfig_ . dzidx_swg_percent ) ;
writeIntValue ( fp , " SWG_PPM_dzidx " , _aqconfig_ . dzidx_swg_ppm ) ;
writeIntValue ( fp , " SWG_Status_dzidx " , _aqconfig_ . dzidx_swg_status ) ;
2018-09-23 21:54:15 +00:00
fprintf ( fp , " \n #** Buttons ** \n " ) ;
for ( i = 0 ; i < TOTAL_BUTTONS ; i + + )
{
fprintf ( fp , " button_%.2d_label = %s \n " , i + 1 , aqdata - > aqbuttons [ i ] . label ) ;
if ( aqdata - > aqbuttons [ i ] . dz_idx > 0 )
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 ) ;
}
fclose ( fp ) ;
remount_root_ro ( fs ) ;
2020-06-06 16:36:04 +00:00
*/
2018-09-23 21:54:15 +00:00
return true ;
}
2020-06-06 16:36:04 +00:00