# HG changeset patch # User Michiel Broek # Date 1405180673 -7200 # Node ID 1302abe92eb165330dd3e2e81ea7c955390ec6e4 # Parent 012576d7386d27c996c838d1142ba79f095b6d50 Made temperature sensors working in the units diff -r 012576d7386d -r 1302abe92eb1 thermferm/rdconfig.c --- a/thermferm/rdconfig.c Fri Jul 11 22:53:33 2014 +0200 +++ b/thermferm/rdconfig.c Sat Jul 12 17:57:53 2014 +0200 @@ -29,6 +29,7 @@ #define MY_ENCODING "utf-8" +const char TEMPSTATE[3][8] = { "OK", "MISSING", "ERROR" }; const char UNITMODE[5][8] = { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }; const char UNITmode[5] = { 'o', 'n', 'f', 'b', 'p' }; const char PROFSTATE[4][6] = { "OFF", "PAUSE", "RUN", "DONE" }; @@ -62,6 +63,8 @@ if (Config.air_address) free(Config.air_address); Config.air_address = NULL; + Config.air_temperature = 20000; + Config.air_state = 1; // missing for (tmp2 = Config.units; tmp2; tmp2 = tmp2->next) { if (tmp2->uuid) @@ -173,9 +176,19 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if (Config.air_address && (rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", Config.air_address)) < 0) { - syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); - return 1; + if (Config.air_address) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", Config.air_address)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_STATE", "%d", Config.air_state)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_TEMPERATURE", "%d", Config.air_temperature)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } #ifdef HAVE_WIRINGPI_H @@ -303,13 +316,33 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if (tmp3->air_address && ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", tmp3->air_address)) < 0)) { - syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); - return 1; + if (tmp3->air_address) { + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", tmp3->air_address)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_STATE", "%d", tmp3->air_state)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_TEMPERATURE", "%d", tmp3->air_temperature)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } - if (tmp3->beer_address && ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", tmp3->beer_address)) < 0)) { - syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); - return 1; + if (tmp3->beer_address) { + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", tmp3->beer_address)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_STATE", "%d", tmp3->beer_state)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_TEMPERATURE", "%d", tmp3->beer_temperature)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if (tmp3->io1_address && ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IO1_ADDRESS", "%s", tmp3->io1_address)) < 0)) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); @@ -631,7 +664,8 @@ unit->uuid = unit->name = unit->air_address = unit->beer_address = unit->io1_address = unit->io2_address = unit->profile = NULL; unit->volume = 0.0; unit->heater_available = unit->cooler_available = unit->fan_available = FALSE; - unit->air_temp = unit->beer_temp = unit->beer_set = unit->fridge_set = 20.0; + unit->air_temperature = unit->beer_temperature = unit->beer_set = unit->fridge_set = 20.0; + unit->air_state = unit->beer_state = 1; // missing unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0; unit->temp_set_min = 1.0; unit->temp_set_max = 30.0; @@ -665,9 +699,33 @@ if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_ADDRESS"))) { unit->air_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_STATE"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->air_state = ival; + xmlFree(key); + } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_TEMPERATURE"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->air_temperature = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_ADDRESS"))) { unit->beer_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_STATE"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->beer_state = ival; + xmlFree(key); + } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_TEMPERATURE"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->beer_temperature = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"IO1_ADDRESS"))) { unit->io1_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } diff -r 012576d7386d -r 1302abe92eb1 thermferm/server.c --- a/thermferm/server.c Fri Jul 11 22:53:33 2014 +0200 +++ b/thermferm/server.c Sat Jul 12 17:57:53 2014 +0200 @@ -33,6 +33,7 @@ extern sys_config Config; extern const char UNITMODE[5][8]; extern const char UNITmode[5]; +extern const char TEMPSTATE[3][8]; int s; /* connected socket */ int ls; /* listen socket */ @@ -150,8 +151,10 @@ unit->name = xstrcpy(param); unit->air_address = unit->beer_address = unit->io1_address = unit->io2_address = unit->profile = NULL; unit->volume = 0.0; + unit->air_state = unit->beer_state = 1; unit->heater_available = unit->cooler_available = unit->fan_available = FALSE; - unit->air_temp = unit->beer_temp = unit->beer_set = unit->fridge_set = 20.0; + unit->air_temperature = unit->beer_temperature = 20000; + unit->beer_set = unit->fridge_set = 20.0; unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0; unit->temp_set_min = 1.0; unit->temp_set_max = 30.0; @@ -276,11 +279,13 @@ srv_send((char *)"UUID,%s", unit->uuid); if (unit->air_address) { srv_send((char *)"AIR_ADDRESS,%s", unit->air_address); - srv_send((char *)"AIR_TEMP,%.1f", unit->air_temp); + srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]); + srv_send((char *)"AIR_TEMPERATURE,%.3f", unit->air_temperature / 1000.0); } if (unit->beer_address) { srv_send((char *)"BEER_ADDRESS,%s", unit->beer_address); - srv_send((char *)"BEER_TEMP,%.1f", unit->beer_temp); + srv_send((char *)"BEER_STATE,%s", TEMPSTATE[unit->beer_state]); + srv_send((char *)"BEER_TEMPERATURE,%.3f", unit->beer_temperature / 1000.0); } if (unit->io1_address) { srv_send((char *)"IO1_ADDRESS,%s", unit->io1_address); diff -r 012576d7386d -r 1302abe92eb1 thermferm/thermferm.h --- a/thermferm/thermferm.h Fri Jul 11 22:53:33 2014 +0200 +++ b/thermferm/thermferm.h Sat Jul 12 17:57:53 2014 +0200 @@ -67,9 +67,11 @@ char *name; /* friendly name */ float volume; /* Volume of this unit */ char *air_address; /* DS18B20 address */ - int air_temp; /* Air temperature * 1000 */ + int air_state; /* 0=ok, 1=missing, 2=error */ + int air_temperature; /* Air temperature in C * 1000 */ char *beer_address; /* DS18B20 address */ - int beer_temp; /* Beer temperature * 1000 */ + int beer_state; /* 0=ok, 1=missing, 2=error */ + int beer_temperature; /* Beer temperature in C * 1000 */ char *io1_address; /* DS2413 address */ char *io2_address; /* DS2413 address */ int heater_available; /* Heater available */ @@ -148,6 +150,8 @@ int my_port; /* my client/server port */ unsigned char tempFormat; /* Temperature format, C or F */ char *air_address; /* 1-wire environment sensor */ + int air_state; /* 0=ok, 1=missing, 2=error */ + int air_temperature; /* Air temperature in C * 1000 */ w1_therm *w1therms; /* 1-wire temp sensors */ #ifdef HAVE_WIRINGPI_H int lcd_cols; /* LCD display columns */ diff -r 012576d7386d -r 1302abe92eb1 thermferm/units.c --- a/thermferm/units.c Fri Jul 11 22:53:33 2014 +0200 +++ b/thermferm/units.c Sat Jul 12 17:57:53 2014 +0200 @@ -64,6 +64,8 @@ if (rc != 1) { syslog(LOG_NOTICE, "sensor %s data parse error", address); rc = 3; + } else { + rc = 0; } } else { syslog(LOG_NOTICE, "sensor %s CRC error", address); @@ -90,7 +92,7 @@ #endif { units_list *unit; - int temp, deviation; + int rc, temp, deviation; /* * Initialize units for processing @@ -134,7 +136,8 @@ break; if (unit->air_address) { - if (read_w1_28(unit->air_address, &temp) == 0) { + rc = read_w1_28(unit->air_address, &temp); + if (rc == 0) { /* * It is possible to have read errors or extreme values. * This can happen with bad connections so we compare the @@ -144,32 +147,43 @@ * Maximum error is 20 degrees for now. */ deviation = 20000; - if ((unit->air_temp == 0) || - (unit->air_temp && (temp > (int)unit->air_temp - deviation) && (temp < ((int)unit->air_temp + deviation)))) { - unit->air_temp = temp; + if ((unit->air_temperature == 0) || + (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) { + unit->air_temperature = temp; + unit->air_state = 0; } else { - syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temp, temp); + syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp); if (debug) { - fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temp, temp); + fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp); } } + } else if (rc == 2) { + unit->air_state = 1; + } else { + unit->air_state = 2; } } if (my_shutdown) break; if (unit->beer_address) { - if (read_w1_28(unit->beer_address, &temp) == 0) { + rc = read_w1_28(unit->beer_address, &temp); + if (rc == 0) { deviation = 20000; - if ((unit->beer_temp == 0) || - (unit->beer_temp && (temp > (int)unit->beer_temp - deviation) && (temp < ((int)unit->beer_temp + deviation)))) { - unit->beer_temp = temp; + if ((unit->beer_temperature == 0) || + (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { + unit->beer_temperature = temp; + unit->beer_state = 0; } else { - syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temp, temp); + syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp); if (debug) { - fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temp, temp); + fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp); } } + } else if (rc == 2) { + unit->beer_state = 1; + } else { + unit->beer_state = 2; } } if (my_shutdown)