# HG changeset patch # User Michiel Broek # Date 1409668663 -7200 # Node ID 885e5243bb50f17b493afc14e880fa36e48c93a6 # Parent 12a5dbbfd0e3cd4419a8b7511c21a5e432e0acd5 UNIT PUT command logging added. diff -r 12a5dbbfd0e3 -r 885e5243bb50 thermferm/server.c --- a/thermferm/server.c Tue Sep 02 15:32:00 2014 +0200 +++ b/thermferm/server.c Tue Sep 02 16:37:43 2014 +0200 @@ -1602,15 +1602,23 @@ * don't understand. */ if (val && (strcmp(kwd, (char *)"NAME") == 0)) { - if (unit->name) + if (unit->name) { + if (strcmp(unit->name, val)) + syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val); free(unit->name); + } unit->name = xstrcpy(val); } else if (val && (strcmp(kwd, (char *)"VOLUME") == 0)) { - if (sscanf(val, "%f", &fval) == 1) + if (sscanf(val, "%f", &fval) == 1) { + if (unit->volume != fval) + syslog(LOG_NOTICE, "Fermenter unit %s volume %.3f to %.3f", unit->uuid, unit->volume, fval); unit->volume = fval; + } } else if (strcmp(kwd, (char *)"AIR_ADDRESS") == 0) { + if (val && unit->air_address && (strcmp(val, unit->air_address))) + syslog(LOG_NOTICE, "Fermenter unit %s air address `%s' to `%s'", unit->uuid, unit->air_address, val); if (unit->air_address) { device_count(FALSE, unit->air_address); free(unit->air_address); @@ -1622,6 +1630,8 @@ unit->air_address = NULL; } else if (strcmp(kwd, (char *)"BEER_ADDRESS") == 0) { + if (val && unit->beer_address && (strcmp(val, unit->beer_address))) + syslog(LOG_NOTICE, "Fermenter unit %s beer address `%s' to `%s'", unit->uuid, unit->beer_address, val); if (unit->beer_address) { device_count(FALSE, unit->beer_address); free(unit->beer_address); @@ -1633,6 +1643,8 @@ unit->beer_address = NULL; } else if (strcmp(kwd, (char *)"HEATER_ADDRESS") == 0) { + if (val && unit->heater_address && (strcmp(val, unit->heater_address))) + syslog(LOG_NOTICE, "Fermenter unit %s heater address `%s' to `%s'", unit->uuid, unit->heater_address, val); if (unit->heater_address) { device_count(FALSE, unit->heater_address); free(unit->heater_address); @@ -1644,14 +1656,22 @@ unit->heater_address = NULL; } else if (val && (strcmp(kwd, (char *)"HEATER_STATE") == 0)) { - if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) + if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { + if (unit->heater_state != ival) + syslog(LOG_NOTICE, "Fermenter unit %s heater state %d to %d", unit->uuid, unit->heater_state, ival); unit->heater_state = ival; + } } else if (val && (strcmp(kwd, (char *)"HEATER_DELAY") == 0)) { - if (sscanf(val, "%d", &ival) == 1) + if (sscanf(val, "%d", &ival) == 1) { + if (unit->heater_delay != ival) + syslog(LOG_NOTICE, "Fermenter unit %s heater delay %d to %d", unit->uuid, unit->heater_delay, ival); unit->heater_delay = ival; + } } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) { + if (val && unit->cooler_address && (strcmp(val, unit->cooler_address))) + syslog(LOG_NOTICE, "Fermenter unit %s cooler address `%s' to `%s'", unit->uuid, unit->cooler_address, val); if (unit->cooler_address) { device_count(FALSE, unit->cooler_address); free(unit->cooler_address); @@ -1663,14 +1683,22 @@ unit->cooler_address = NULL; } else if (val && (strcmp(kwd, (char *)"COOLER_STATE") == 0)) { - if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) + if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { + if (unit->cooler_state != ival) + syslog(LOG_NOTICE, "Fermenter unit %s cooler state %d to %d", unit->uuid, unit->cooler_state, ival); unit->cooler_state = ival; + } } else if (val && (strcmp(kwd, (char *)"COOLER_DELAY") == 0)) { - if (sscanf(val, "%d", &ival) == 1) + if (sscanf(val, "%d", &ival) == 1) { + if (unit->cooler_delay != ival) + syslog(LOG_NOTICE, "Fermenter unit %s cooler delay %d to %d", unit->uuid, unit->cooler_delay, ival); unit->cooler_delay = ival; + } } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) { + if (val && unit->fan_address && (strcmp(val, unit->fan_address))) + syslog(LOG_NOTICE, "Fermenter unit %s fan address `%s' to `%s'", unit->uuid, unit->fan_address, val); if (unit->fan_address) { device_count(FALSE, unit->fan_address); free(unit->fan_address); @@ -1682,14 +1710,22 @@ unit->fan_address = NULL; } else if (val && (strcmp(kwd, (char *)"FAN_STATE") == 0)) { - if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) + if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { + if (unit->fan_state != ival) + syslog(LOG_NOTICE, "Fermenter unit %s fan state %d to %d", unit->uuid, unit->fan_state, ival); unit->fan_state = ival; + } } else if (val && (strcmp(kwd, (char *)"FAN_DELAY") == 0)) { - if (sscanf(val, "%d", &ival) == 1) + if (sscanf(val, "%d", &ival) == 1) { + if (unit->fan_delay != ival) + syslog(LOG_NOTICE, "Fermenter unit %s fan delay %d to %d", unit->uuid, unit->fan_delay, ival); unit->fan_delay = ival; + } } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) { + if (val && unit->door_address && (strcmp(val, unit->door_address))) + syslog(LOG_NOTICE, "Fermenter unit %s door address `%s' to `%s'", unit->uuid, unit->door_address, val); if (unit->door_address) { device_count(FALSE, unit->door_address); free(unit->door_address); @@ -1706,7 +1742,7 @@ /* Initialize log if the unit is turned on */ if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) initlog(unit->name); - syslog(LOG_NOTICE, "Mode from %s to %s via web interface", UNITMODE[unit->mode], UNITMODE[i]); + syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]); unit->mode = i; /* Allways turn everything off after a mode change */ unit->PID_I_err = unit->PID_err_old = 0.0; @@ -1728,13 +1764,15 @@ } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 0)) { if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { - syslog(LOG_NOTICE, "Fridge temperature from %.1f to %.1f via web interface", unit->fridge_set, fval); + if (unit->fridge_set != fval) + syslog(LOG_NOTICE, "Fermenter unit %s fridge temperature %.1f to %.1f", unit->uuid, unit->fridge_set, fval); unit->fridge_set = fval; } } else if (val && (strcmp(kwd, (char *)"BEER_SET") == 0)) { if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { - syslog(LOG_NOTICE, "Beer temperature from %.1f to %.1f via web interface", unit->beer_set, fval); + if (unit->fridge_set != fval) + syslog(LOG_NOTICE, "Fermenter unit %s beer temperature %.1f to %.1f", unit->uuid, unit->beer_set, fval); unit->beer_set = fval; } @@ -1743,8 +1781,11 @@ /* * Only change profile if it is not active, else drop this one. */ + if (unit->profile && val && strcmp(unit->profile, val)) + syslog(LOG_NOTICE, "Fermenter unit %s profile name `%s' to `%s'", unit->uuid, unit->profile, val); if (unit->profile) free(unit->profile); + if (val) unit->profile = xstrcpy(val); else @@ -1766,29 +1807,29 @@ switch (i) { case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE) { unit->prof_state = PROFILE_OFF; - syslog(LOG_NOTICE, "Profile to OFF via web interface"); + syslog(LOG_NOTICE, "Fermenter unit %s profile to OFF", unit->uuid); } break; case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN) { unit->prof_state = PROFILE_PAUSE; - syslog(LOG_NOTICE, "Profile PAUSE via web interface"); + syslog(LOG_NOTICE, "Fermenter unit %s profile PAUSE", unit->uuid); } else if (unit->prof_state == PROFILE_PAUSE) { unit->prof_state = PROFILE_RUN; - syslog(LOG_NOTICE, "Profile RESUME via web interface"); + syslog(LOG_NOTICE, "Fermenter unit %s profile RESUME", unit->uuid); } break; case PROFILE_RUN: if (unit->prof_state == PROFILE_OFF) { unit->prof_state = PROFILE_RUN; unit->prof_started = time(NULL); unit->prof_paused = 0; - syslog(LOG_NOTICE, "Profile to RUN via web interface"); + syslog(LOG_NOTICE, "Fermenter unit %s profile to RUN", unit->uuid); } break; case PROFILE_DONE: break; /* Command is illegal */ case PROFILE_ABORT: if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) { unit->prof_state = PROFILE_OFF; unit->prof_started = 0; - syslog(LOG_NOTICE, "Profile ABORT via web interface"); + syslog(LOG_NOTICE, "Fermenter unit %s profile ABORT", unit->uuid); } break; } @@ -1797,20 +1838,32 @@ } } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MIN") == 0)) { - if (sscanf(val, "%f", &fval) == 1) + if (sscanf(val, "%f", &fval) == 1) { + if (unit->temp_set_min != fval) + syslog(LOG_NOTICE, "Fermenter unit %s temperature set minimum %.1f to %.1f", unit->uuid, unit->temp_set_min, fval); unit->temp_set_min = fval; + } } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MAX") == 0)) { - if (sscanf(val, "%f", &fval) == 1) + if (sscanf(val, "%f", &fval) == 1) { + if (unit->temp_set_max != fval) + syslog(LOG_NOTICE, "Fermenter unit %s temperature set maximum %.1f to %.1f", unit->uuid, unit->temp_set_max, fval); unit->temp_set_max = fval; + } } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_L") == 0)) { - if (sscanf(val, "%f", &fval) == 1) + if (sscanf(val, "%f", &fval) == 1) { + if (unit->idle_rangeL != fval) + syslog(LOG_NOTICE, "Fermenter unit %s idle range low %.1f to %.1f", unit->uuid, unit->idle_rangeL, fval); unit->idle_rangeL = fval; + } } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_H") == 0)) { - if (sscanf(val, "%f", &fval) == 1) + if (sscanf(val, "%f", &fval) == 1) { + if (unit->idle_rangeH != fval) + syslog(LOG_NOTICE, "Fermenter unit %s idle range high %.1f to %.1f", unit->uuid, unit->idle_rangeH, fval); unit->idle_rangeH = fval; + } } }