diff --git a/Makefile b/Makefile index ce8ae42..3001063 100755 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ LIBS := -lm #DBG = -g -O0 -fsanitize=address -static-libasan #DBG = -g #DBG = -D TESTING -DBG = +#DBG = # define any compile-time flags #CFLAGS = -Wall -g -lpthread -lwiringPi -lm -I. @@ -32,7 +32,7 @@ INCLUDES = -I./ #SL_SRC = serial_logger.c aq_serial.c utils.c #AL_SRC = aquapure_logger.c aq_serial.c utils.c -SRCS = aquapure.c ap_net_services.c ap_config.c aq_serial.c utils.c mongoose.c json_messages.c config.c +SRCS = aquapure.c ap_net_services.c SWG_device.c aq_serial.c utils.c mongoose.c json_messages.c config.c #SRCS = aq_serial.c utils.c mongoose.c json_messages.c config.c aquapured/ap_net_services.c aquapured/ap_config.c aquapured/aquapure.c OBJS = $(SRCS:.c=.o) diff --git a/ap_config.c b/SWG_device.c similarity index 97% rename from ap_config.c rename to SWG_device.c index 5e15efd..9842908 100644 --- a/ap_config.c +++ b/SWG_device.c @@ -1,9 +1,10 @@ #include #include -#include "ap_config.h" +#include "SWG_device.h" #include "utils.h" + void write_cache(struct apdata *ar_prms) { FILE *fp; diff --git a/SWG_device.h b/SWG_device.h new file mode 100644 index 0000000..e01474d --- /dev/null +++ b/SWG_device.h @@ -0,0 +1,33 @@ +#ifndef AR_CONFIG_H_ +#define AR_CONFIG_H_ + +#include + + +// connected, receiving ACK +// status, status from RS485 (on & generating are same status) +// Percent > 0 & status = 0 to generating. +// Percent = 0 & status = 0x00 change status to 0xFF (off) + +struct apdata +{ + int PPM; + int Percent; + int last_generating_percent; + int default_percent; + //bool generating; + bool boost; + unsigned char status; + //unsigned char last_status_published; + bool connected; + char *cache_file; + bool changed; +}; + + +bool set_SWG_percent(int percent); + +void write_cache(struct apdata *ar_prms); +void read_cache(struct apdata *ar_prms); + +#endif diff --git a/ap_config.h b/ap_config.h deleted file mode 100644 index 3092812..0000000 --- a/ap_config.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef AR_CONFIG_H_ -#define AR_CONFIG_H_ - -#include -/* -struct arconfig -{ - int PPM; - int Percent; - bool generating; - unsigned char status; - unsigned char last_status_published; - bool ar_connected; - char *cache_file; -}; -*/ -struct apdata -{ - int PPM; - int Percent; - bool generating; - unsigned char status; - unsigned char last_status_published; - bool ar_connected; - char *cache_file; - bool changed; -}; - - - -void write_cache(struct apdata *ar_prms); -void read_cache(struct apdata *ar_prms); - -#endif diff --git a/ap_net_services.c b/ap_net_services.c index d1a90b9..2552582 100644 --- a/ap_net_services.c +++ b/ap_net_services.c @@ -25,7 +25,7 @@ #include "mongoose.h" #include "aquapured.h" -#include "ap_config.h" +#include "SWG_device.h" #include "config.h" //#include "aq_programmer.h" @@ -70,11 +70,11 @@ static void ws_send(struct mg_connection *nc, char *msg) { int size = strlen(msg); - logMessage (LOG_DEBUG, "WS: Sent %d characters '%s'\n",size, msg); + //logMessage (LOG_DEBUG, "WS: Sent %d characters '%s'\n",size, msg); mg_send_websocket_frame(nc, WEBSOCKET_OP_TEXT, msg, size); - logMessage (LOG_DEBUG, "WS: Sent %d characters '%s'\n",size, msg); + //logMessage (LOG_DEBUG, "WS: Sent %d characters '%s'\n",size, msg); } static void signal_handler(int sig_num) { @@ -173,7 +173,7 @@ void ws_broadcast_aquapurestate(struct mg_connection *nc) { char data[JSON_STATUS_SIZE]; //int size = build_aquapure_status_JSON(_ar_prms, data, JSON_STATUS_SIZE); - int size = build_device_JSON(_ar_prms, data, JSON_STATUS_SIZE, false); + build_device_JSON(_ar_prms, data, JSON_STATUS_SIZE, false); ws_send(nc, data); } @@ -190,16 +190,17 @@ void mqtt_broadcast_aquapurestate(struct mg_connection *nc) { send_mqtt_float_msg(nc, SWG_PPM_F_TOPIC, roundf(degFtoC(_ar_prms->PPM))); } - send_mqtt_int_msg(nc, SWG_TOPIC, _ar_prms->generating); - + send_mqtt_int_msg(nc, SWG_TOPIC, ((_ar_prms->connected && (_ar_prms->Percent > 0))?2:0) ); + send_mqtt_int_msg(nc, SWG_ENABELED_TOPIC, (_ar_prms->connected?2:0)); send_mqtt_int_msg(nc, SWG_EXTENDED_TOPIC, (int)_ar_prms->status); - + send_mqtt_int_msg(nc, SWG_BOOST_TOPIC, _ar_prms->boost); +/* if (_ar_prms->status != _ar_prms->last_status_published) { } else { _ar_prms->last_status_published = _ar_prms->status; } - +*/ } @@ -210,6 +211,16 @@ void set_swg_percent(char *sval, bool f2c) { value = degCtoF(value); } + if (_ar_prms->connected != true) { + logMessage(LOG_ERR, "Can't set Percent %d, SWG not connected\n",value); + _ar_prms->changed = true; + return; + } else if (_ar_prms->boost == true) { + logMessage(LOG_ERR, "Can't set Percent %d, SWG Boost is active\n",value); + _ar_prms->changed = true; + return; + } + int ival = round(value); //if (0 != ( ival % 5) ) @@ -221,6 +232,9 @@ void set_swg_percent(char *sval, bool f2c) { ival = 0; _ar_prms->Percent = ival; + + if (ival > 0 && ival < 101) + _ar_prms->last_generating_percent = ival; //_ar_prms->Percent = round(degCtoF(value)); logMessage(LOG_INFO, "Setting SWG percent to %d", _ar_prms->Percent); //broadcast_aquapurestate(nc); @@ -228,6 +242,59 @@ void set_swg_percent(char *sval, bool f2c) { _ar_prms->changed = true; } +void set_swg_boost(bool val) { + if (_ar_prms->connected != true) { + logMessage(LOG_ERR, "Can't boost, SWG not connected\n"); + _ar_prms->changed = true; + return; + } + + if (_ar_prms->boost != val) { + _ar_prms->boost = val; + if (val == true) { // turning boost on + if (_ar_prms->Percent > 0) + _ar_prms->last_generating_percent = _ar_prms->Percent; + + _ar_prms->Percent = 101; + } else { // Turning boost off + if (_ar_prms->last_generating_percent > 0) + _ar_prms->Percent = _ar_prms->last_generating_percent; + else + set_swg_percent("0", false); + } + } + + _ar_prms->changed = true; +} + +void set_swg_on(bool val) { + if (_ar_prms->connected != true) { + logMessage(LOG_ERR, "Can't turn SWG %s, SWG not connected\n",(val==true?"on":"off")); + _ar_prms->changed = true; + return; + } + + if (val==true) { + if (_ar_prms->Percent > 0) { + logMessage(LOG_NOTICE, "Can't turn SWG %s, SWG is already %s\n",(val==true?"on":"off"),(_ar_prms->Percent>0?"on":"off")); + return; + } + if (_ar_prms->last_generating_percent > 0 && _ar_prms->last_generating_percent < 101) + _ar_prms->Percent = _ar_prms->last_generating_percent; + else + _ar_prms->Percent = _ar_prms->default_percent; + } + + if (val==false) { + if (_ar_prms->Percent == 0) { + logMessage(LOG_NOTICE, "Can't turn SWG %s, SWG is already %s\n",(val==true?"on":"off"),(_ar_prms->Percent>0?"on":"off")); + return; + } + set_swg_percent("0", false); + } + + _ar_prms->changed = true; +} void action_mqtt_message(struct mg_connection *nc, struct mg_mqtt_message *msg) { // int i; @@ -251,21 +318,20 @@ void action_mqtt_message(struct mg_connection *nc, struct mg_mqtt_message *msg) int pt = strlen( _apconfig_.mqtt_aq_topic) + 1; if (strncmp(&msg->topic.p[pt], "SWG/Percent/set", 15) == 0) { - //_ar_prms->Percent = round(value); - //printf("SET PERCENT TO %d", _ar_prms->Percent); - //broadcast_aquapurestate(nc); - //write_cache(_ar_prms); - //_ar_prms->changed = true; set_swg_percent(tmp, false); } else if (strncmp(&msg->topic.p[pt], "SWG/Percent_f/set", 17) == 0) { - //_ar_prms->Percent = round(degCtoF(value)); - //printf("SET PERCENT TO %d", _ar_prms->Percent); - //broadcast_aquapurestate(nc); - //write_cache(_ar_prms); - //_ar_prms->changed = true; set_swg_percent(tmp, true); + } else if (strncmp(&msg->topic.p[pt], "SWG/Boost/set", 13) == 0) { + if (atoi(tmp) == 1) + set_swg_boost(true); + else + set_swg_boost(false); } else if (strncmp(&msg->topic.p[pt], "SWG/set", 7) == 0) { - logMessage(LOG_NOTICE, "MQTT Trying to set no settable value %.*s to %.*s\n", msg->topic.len, msg->topic.p, msg->payload.len, msg->payload.p); + if (atoi(tmp) == 1) + set_swg_on(true); + else + set_swg_on(false); + //logMessage(LOG_NOTICE, "MQTT Trying to set no settable value %.*s to %.*s\n", msg->topic.len, msg->topic.p, msg->payload.len, msg->payload.p); //broadcast_aquapurestate(nc); _ar_prms->changed = true; } @@ -301,31 +367,32 @@ void action_web_request(struct mg_connection *nc, struct http_message *http_msg) mg_send_head(nc, 200, size, "Content-Type: application/json"); mg_send(nc, data, size); return; - } else if (strcmp(command, "swg_percent") == 0) { + } else if (strcmp(command, SWG_PERCENT_TOPIC) == 0 || + strcmp(command, "swg_percent") == 0) { char value[20]; mg_get_http_var(&http_msg->query_string, "value", value, sizeof(value)); - - //_ar_prms->Percent = atoi(value); - //printf("SET PERCENT TO %d\n", _ar_prms->Percent); - //broadcast_aquapurestate(nc); - //write_cache(_ar_prms); - //_ar_prms->changed = true; set_swg_percent(value, false); mg_send_head(nc, 200, strlen(GET_RTN_OK), "Content-Type: text/plain"); mg_send(nc, GET_RTN_OK, strlen(GET_RTN_OK)); return; - } else if (strcmp(command, "swg") == 0) { + } else if (strcmp(command, SWG_TOPIC) == 0 || + strcmp(command, "swg") == 0) { char value[20]; mg_get_http_var(&http_msg->query_string, "value", value, sizeof(value)); - if (strcmp(value, "off") == 0) { - set_swg_percent("0", false); - } - //_ar_prms->Percent = 0; - //printf("SET PERCENT TO %d\n", _ar_prms->Percent); - //broadcast_aquapurestate(nc); - //write_cache(_ar_prms); - //_ar_prms->changed = true; - //set_swg_percent(value, false); + if (strcmp(value, "off") == 0) + set_swg_on(false); + else + set_swg_on(true); + mg_send_head(nc, 200, strlen(GET_RTN_OK), "Content-Type: text/plain"); + mg_send(nc, GET_RTN_OK, strlen(GET_RTN_OK)); + return; + } else if (strcmp(command, SWG_BOOST_TOPIC) == 0 ) { + char value[20]; + mg_get_http_var(&http_msg->query_string, "value", value, sizeof(value)); + if (strcmp(value, "off") == 0) + set_swg_boost(false); + else + set_swg_boost(true); mg_send_head(nc, 200, strlen(GET_RTN_OK), "Content-Type: text/plain"); mg_send(nc, GET_RTN_OK, strlen(GET_RTN_OK)); return; @@ -362,13 +429,24 @@ void action_websocket_request(struct mg_connection *nc, struct websocket_message if (strcmp(request.first.value, "GET_DEVICES") == 0) { //char message[JSON_LABEL_SIZE*10]; //build_device_JSON(_aqualink_data, _aqualink_config->light_programming_button_pool, _aqualink_config->light_programming_button_spa, message, JSON_LABEL_SIZE*10, false); - int size = build_device_JSON(_ar_prms, data, JSON_STATUS_SIZE, false); - logMessage(LOG_DEBUG, "-->%s<--", data); + build_device_JSON(_ar_prms, data, JSON_STATUS_SIZE, false); + //logMessage(LOG_DEBUG, "-->%s<--", data); ws_send(nc, data); } else if (strcmp(request.first.key, "command") == 0) { if (strcmp(request.first.value, SWG_TOPIC) == 0) { - printf("Turn SWG on/off NOT IMPLIMENTED YET!\n"); - _ar_prms->changed = true; + //printf("Turn SWG on/off NOT IMPLIMENTED YET!\n"); + //_ar_prms->changed = true; + if (strcmp(request.second.value, "on") == 0) + set_swg_on(true); + else + set_swg_on(false); + } else if (strcmp(request.first.value, SWG_BOOST_TOPIC) == 0) { + //printf("Boost on/off NOT IMPLIMENTED YET!\n"); + //_ar_prms->changed = true; + if (strcmp(request.second.value, "on") == 0) + set_swg_boost(true); + else + set_swg_boost(false); } } else if (strcmp(request.first.key, "parameter") == 0) { if (strcmp(request.first.value, SWG_TOPIC) == 0) { // Should delete this soon @@ -466,7 +544,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { } break; case MG_EV_MQTT_PUBACK: mqtt_msg = (struct mg_mqtt_message *)ev_data; - logMessage(LOG_INFO, "MQTT: Message publishing acknowledged (msg_id: %d)\n", mqtt_msg->message_id); + logMessage(LOG_DEBUG, "MQTT: Message publishing acknowledged (msg_id: %d)\n", mqtt_msg->message_id); break; case MG_EV_MQTT_SUBACK: logMessage(LOG_INFO, "MQTT: Subscription(s) acknowledged\n"); diff --git a/aq_mqtt.h b/aq_mqtt.h index 6d806b1..e482e35 100644 --- a/aq_mqtt.h +++ b/aq_mqtt.h @@ -21,6 +21,7 @@ #define SWG_PERCENT_F_TOPIC SWG_TOPIC "/Percent_f" #define SWG_SETPOINT_TOPIC SWG_TOPIC "/setpoint" #define SWG_EXTENDED_TOPIC SWG_TOPIC "/fullstatus" +#define SWG_BOOST_TOPIC SWG_TOPIC "/Boost" #define FREEZE_PROTECT "Freeze_Protect" #define FREEZE_PROTECT_ENABELED FREEZE_PROTECT ENABELED_SUBT diff --git a/aq_serial.o b/aq_serial.o index a6dcf4f..b59e7f0 100644 Binary files a/aq_serial.o and b/aq_serial.o differ diff --git a/aquapure.c b/aquapure.c index 3d15b69..3752526 100644 --- a/aquapure.c +++ b/aquapure.c @@ -10,7 +10,7 @@ #include "mongoose.h" #include "aq_serial.h" #include "config.h" -#include "ap_config.h" +#include "SWG_device.h" #include "utils.h" #include "ap_net_services.h" @@ -19,7 +19,12 @@ //#define PACKET_MAX 10000 #define CACHE_FILE "/tmp/aquapure.cache" -#define TIMEOUT_TRIES 10 +// TIMEOUT_TRIES needs to be divisable by RETRY_NUL_READ. +// Number of RETRY_NUL_READ null reads = re send last message. ie re-send every 5 poll cycles of nothing read. +// Number of TIMEOUT_TRIES / RETRY_NUL_READ null reads set to connection faulure. ie 3 re-sends, and nothing read call SWG dead. +#define RETRY_NUL_READ 5 +#define TIMEOUT_TRIES 15 + #define AR_ID 0x50 @@ -139,9 +144,11 @@ int main(int argc, char *argv[]) { _ar_prms.PPM = TEMP_UNKNOWN; _ar_prms.Percent = 50; - _ar_prms.generating = false; + _ar_prms.default_percent = 50; + _ar_prms.boost = false; _ar_prms.cache_file = CACHE_FILE; _ar_prms.changed = true; + _ar_prms.connected = false; // Initialize the daemon's parameters. //init_parameters(); @@ -190,6 +197,7 @@ void main_loop() { //bool sendUpdate = false; bool broadcast = true; int cnt=0; + unsigned char corrected_status; logMessage(LOG_DEBUG, "Starting aquapured!\n"); @@ -241,97 +249,67 @@ void main_loop() { _keepRunning = false; } else if (packet_length == 0) { // Nothing read - logMessage(LOG_DEBUG_SERIAL,"Nothing read\n"); - //if (ar_connected == false && no_reply >= PING_POLL) { - //send_command(rs_fd, AR_ID, CMD_PROBE, 0x62, NUL); - send_1byte_command(rs_fd, AR_ID, CMD_PROBE); - //logMessage(LOG_DEBUG_SERIAL,"Send Probe\n"); - // no_reply = 0; - //} else { - no_reply++; - if (no_reply >= TIMEOUT_TRIES) { - logMessage(LOG_DEBUG_SERIAL,"*** %d BLANK READS *****\n",no_reply); - if (_ar_prms.ar_connected == true || _ar_prms.generating == true) { + no_reply++; + logMessage(LOG_DEBUG_SERIAL,"Nothing read try %d\n",no_reply); + + // Resend last command after X blank reads + if ( (no_reply % RETRY_NUL_READ) == 0 ) { + if ( _ar_prms.connected == true) + send_3byte_command(rs_fd, AR_ID, CMD_PERCENT, (unsigned char)_ar_prms.Percent, NUL); + else + send_1byte_command(rs_fd, AR_ID, CMD_PROBE); + } + + if (no_reply >= TIMEOUT_TRIES) { + logMessage(LOG_ERR,"%d BLANK READS, Calling SWG connection dead\n",no_reply); + if (_ar_prms.connected == true || _ar_prms.status != SWG_STATUS_OFFLINE) { //sendUpdate = true; - _ar_prms.changed = true; - } - _ar_prms.ar_connected = false; - _ar_prms.generating = false; - _ar_prms.status = SWG_STATUS_OFFLINE; - - //if (sendUpdate) - // broadcast = broadcast_aquapurestate(mgr.active_connections); - /* - if (_ar_prms.generating == true) { - _ar_prms.generating = false; - broadcast = broadcast_aquapurestate(mgr.active_connections); - }*/ - //ar_prms.generating = false; - no_reply = 0; + _ar_prms.changed = true; } - //} - // sleep(1); + _ar_prms.connected = false; + _ar_prms.status = SWG_STATUS_OFFLINE; + + no_reply = 0; + } } else if (packet_length > 0) { no_reply = 0; if (packet_buffer[PKT_DEST] == 0x00) { - _ar_prms.ar_connected = true; + _ar_prms.connected = true; if (getLogLevel() >= LOG_DEBUG_SERIAL) debugPacketPrint(AR_ID, packet_buffer, packet_length); switch (packet_buffer[PKT_CMD]) { case CMD_ACK: if (_forceConnection == true) - _ar_prms.generating = true; + _ar_prms.connected = true; - if (_ar_prms.generating == false) { - // Chlorinator Translator = GetID | HEX: 0x10|0x02|0x50|0x14|0x00|0x76|0x10|0x03| - // AquaLinkRD To 0x50 of type GetID | HEX: 0x10|0x02|0x50|0x14|0x01|0x77|0x10|0x03| + if (_ar_prms.connected == false) { send_2byte_command(rs_fd, AR_ID, CMD_GETID, 0x01); - //send_2byte_command(rs_fd, AR_ID, CMD_GETID, 0x01); - //send_command(rs_fd, AR_ID, CMD_GETID, 0x01, 0x77); // Returns AquaPure or aquapure - //send_command(rs_fd, AR_ID, CMD_GETID, 0x00, 0x76); // Returns BOOTS - //logMessage(LOG_DEBUG_SERIAL,"Send Get Status/ID\n"); } else { send_3byte_command(rs_fd, AR_ID, CMD_PERCENT, (unsigned char)_ar_prms.Percent, NUL); - //send_command(rs_fd, AR_ID, CMD_PERCENT, (unsigned char)_ar_prms.Percent, NUL); - //logMessage(LOG_DEBUG_SERIAL,"Send set percent salt to %d\n",_ar_prms.Percent); } break; case CMD_PPM: logMessage(LOG_DEBUG_SERIAL,"Received PPM %d\n", (packet_buffer[4] * 100)); - //sendUpdate = false; - if (_ar_prms.status != packet_buffer[5]) { - _ar_prms.status = packet_buffer[5]; - //sendUpdate = true; + if (_ar_prms.connected != true) { + _ar_prms.connected = true; _ar_prms.changed = true; } - - if (_ar_prms.status == 0x00 || _ar_prms.status == 0x04 || _ar_prms.status == 0x20) { - if (_ar_prms.PPM != packet_buffer[4] * 100) { - _ar_prms.PPM = packet_buffer[4] * 100; - //broadcast_aquapurestate(mgr.active_connections); - //sendUpdate = true; - _ar_prms.changed = true; - write_cache(&_ar_prms); - } - if (_ar_prms.generating == false) { - _ar_prms.generating = true; - //broadcast_aquapurestate(mgr.active_connections); - //sendUpdate = true; - _ar_prms.changed = true; - } - } else { - if (_ar_prms.generating == true) { - _ar_prms.generating = false; - //broadcast_aquapurestate(mgr.active_connections); - //sendUpdate = true; - _ar_prms.changed = true; - } + + // If ON status but % = 0 change status to off, since off is not supported on RS485 protocol. + corrected_status = (packet_buffer[5] == SWG_STATUS_ON && _ar_prms.Percent < 0)?SWG_STATUS_OFF:packet_buffer[5]; + + // Has status changed. + if (_ar_prms.status != corrected_status ) { + _ar_prms.status = corrected_status; + _ar_prms.changed = true; } - //if (sendUpdate) - // broadcast = broadcast_aquapurestate(mgr.active_connections); + if (_ar_prms.PPM != packet_buffer[4] * 100) { + _ar_prms.PPM = packet_buffer[4] * 100; + _ar_prms.changed = true; + } if (getLogLevel() >= LOG_DEBUG_SERIAL && _ar_prms.status != 0x00) debugStatusPrint(); @@ -339,6 +317,7 @@ void main_loop() { case CMD_MSG: // Want to fall through //send_command(rs_fd, AR_ID, CMD_PERCENT, (unsigned char)_ar_prms.Percent, NUL); send_3byte_command(rs_fd, AR_ID, CMD_PERCENT, (unsigned char)_ar_prms.Percent, NUL); + _ar_prms.connected = true; break; // case 0x16: // break; @@ -363,7 +342,7 @@ void main_loop() { if (cnt >= 600) { cnt = 0; - if (_ar_prms.ar_connected == true) + if (_ar_prms.connected == true) broadcast = false; } cnt ++; diff --git a/config.o b/config.o index f980e58..92428b5 100644 Binary files a/config.o and b/config.o differ diff --git a/json_messages.c b/json_messages.c index 9223792..f433034 100644 --- a/json_messages.c +++ b/json_messages.c @@ -28,7 +28,7 @@ #include "json_messages.h" //#include "domoticz.h" #include "aq_mqtt.h" -#include "ap_config.h" +#include "SWG_device.h" #include "version.h" @@ -79,7 +79,7 @@ const char* SWGstatus2test(unsigned char status) return "Check PCB"; break; } - return ""; + return "Unknown"; } const char* getStatus(struct aqualinkdata *aqdata) @@ -152,7 +152,7 @@ int build_device_JSON(struct apdata *aqdata, char* buffer, int size, bool homeki ((homekit_f)?SWG_PERCENT_F_TOPIC:SWG_PERCENT_TOPIC), "Salt Water Generator", aqdata->status == SWG_STATUS_ON?JSON_ON:JSON_OFF, - aqdata->status == SWG_STATUS_ON?JSON_ON:JSON_OFF, + ((aqdata->connected && (aqdata->Percent > 0) && (aqdata->status < SWG_STATUS_TURNING_OFF) )?JSON_ON:JSON_OFF), ((homekit)?2:0), ((homekit_f)?degFtoC(aqdata->Percent):aqdata->Percent), ((homekit)?2:0), @@ -186,6 +186,13 @@ int build_device_JSON(struct apdata *aqdata, char* buffer, int size, bool homeki */ } + length += sprintf(buffer+length, "{\"type\": \"switch\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"status\": \"%s\" },", + SWG_BOOST_TOPIC, + "Salt Water Generator Boost", + aqdata->boost == true?JSON_ON:JSON_OFF, + aqdata->boost == true?JSON_ON:JSON_OFF); + + if (buffer[length-1] == ',') length--; @@ -196,8 +203,6 @@ int build_device_JSON(struct apdata *aqdata, char* buffer, int size, bool homeki buffer[length] = '\0'; - logMessage(LOG_DEBUG, "-->%s<--", buffer); - return strlen(buffer); } diff --git a/json_messages.h b/json_messages.h index 9ac62dc..000ce83 100644 --- a/json_messages.h +++ b/json_messages.h @@ -1,7 +1,7 @@ #ifndef JSON_MESSAGES_H_ #define JSON_MESSAGES_H_ -#include "ap_config.h" +#include "SWG_device.h" //FUNCTION PROTOTYPES #define JSON_LABEL_SIZE 300 diff --git a/json_messages.o b/json_messages.o index ceabbbc..4c617b4 100644 Binary files a/json_messages.o and b/json_messages.o differ diff --git a/mongoose.o b/mongoose.o index 7e12569..c344123 100644 Binary files a/mongoose.o and b/mongoose.o differ diff --git a/release/aquapured b/release/aquapured index 3d323b6..af2c445 100755 Binary files a/release/aquapured and b/release/aquapured differ diff --git a/release/aquapured.conf b/release/aquapured.conf index e8fa7a3..46c04b2 100644 --- a/release/aquapured.conf +++ b/release/aquapured.conf @@ -19,7 +19,7 @@ log_level=DEBUG_SERIAL #web_directory=/var/www/aquapured/ web_directory=./web/ -socket_port=88 +socket_port=80 # The serial port the daemon access to read the Aqualink RS8 serial_port=/dev/ttyUSB0 diff --git a/release/aquapured.test.conf b/release/aquapured.test.conf index f611d50..7545305 100644 --- a/release/aquapured.test.conf +++ b/release/aquapured.test.conf @@ -11,9 +11,9 @@ # so, NOTICE also prints WARNING & ERROR # DEBUG_SERIAL would print everything possible -log_level=DEBUG_SERIAL +#log_level=DEBUG_SERIAL #log_level=DEBUG -#log_level=INFO +log_level=INFO #log_level=NOTICE #web_directory=/var/www/aquapured/ @@ -24,8 +24,8 @@ socket_port=88 # The serial port the daemon access to read the Aqualink RS8 -#serial_port=/dev/ttyUSB0 -serial_port=/dev/null +serial_port=/dev/ttyUSB0 +#serial_port=/dev/null # mqtt stuff mqtt_address = trident:1883 diff --git a/utils.o b/utils.o index af35131..4b1f1f0 100644 Binary files a/utils.o and b/utils.o differ diff --git a/version.h b/version.h index 60c3805..404c479 100644 --- a/version.h +++ b/version.h @@ -1,4 +1,4 @@ #define AQUAPURED_NAME "AquaPure Daemon" -#define AQUAPURED_VERSION "0.2" \ No newline at end of file +#define AQUAPURED_VERSION "0.3" \ No newline at end of file diff --git a/web/index.html b/web/index.html index 84f200d..6627e53 100644 --- a/web/index.html +++ b/web/index.html @@ -287,15 +287,22 @@ //console.log("Update " + data['devices'][obj].id); if ( data['devices'][obj].type == "value" ) { setLabel(data['devices'][obj].id, data['devices'][obj].value); - } else if ( data['devices'][obj].type == "setpoint_swg" || - data['devices'][obj].type == "setpoint_thermo" || + } else if ( data['devices'][obj].type == "setpoint_thermo" || data['devices'][obj].type == "setpoint_freeze" ) { setSlider(data['devices'][obj].setpoint_id, data['devices'][obj].value); - setButton(data['devices'][obj].id, data['devices'][obj].state) + setButton(data['devices'][obj].id, data['devices'][obj].state); + } else if ( data['devices'][obj].type == "setpoint_swg" ) { + setSlider(data['devices'][obj].setpoint_id, data['devices'][obj].value); + setButton(data['devices'][obj].id, data['devices'][obj].state); + //setButton(data['devices'][obj].id, data['devices'][obj].state); // This is correct, but using status for Aquapure + setButton(data['devices'][obj].id, data['devices'][obj].status); + } else if ( data['devices'][obj].type == "switch") { + setButton(data['devices'][obj].id, data['devices'][obj].state); } } } } + /* function setTitle(date, time) { document.getElementById("title").innerHTML = "AquapureD    "+formatSatus(date+" "+time)+""; @@ -422,7 +429,8 @@ cell4.innerHTML = "
"; //cell4.innerHTML = "
"; setSlider(object.setpoint_id, object.value); - setButton(object.id, object.state); + //setButton(object.id, object.state); // This is correct, but using status for Aquapure + setButton(object.id, object.status); } } @@ -475,6 +483,9 @@ if( (btn = document.getElementById('btn-toggle-' + id)) != null) btn.checked = isOn; */ + +console.log("Set "+id+" "+isOn); + if ( (source = document.getElementById('switch-'+id)) == null) return;