diff -r 99c47a8a61cb -r 5e538c4e1ecb thermferm/thermferm.c --- a/thermferm/thermferm.c Sat Jul 12 21:59:19 2014 +0200 +++ b/thermferm/thermferm.c Sat Jul 12 22:32:29 2014 +0200 @@ -43,6 +43,8 @@ #ifndef HAVE_WIRINGPI_H pthread_t threads[3]; #endif +extern const char UNITMODE[5][8]; + int server(void); void help(void); @@ -226,10 +228,11 @@ int server(void) { - char buf[1024]; + char buf[1024], *filename; time_t now, last = (time_t)0; w1_therm *tmp1; - int rc, run = 1, temp; + units_list *unit; + int rc, run = 1, temp, seconds = 0; #ifndef HAVE_WIRINGPI_H long t = 0; #endif @@ -282,7 +285,18 @@ } snprintf(buf, 1023, "tempA,tempB"); - logger((char *)"thermferm.log", (char *)"thermferm", buf); + logger((char *)"thermferm.log", buf); + + for (unit = Config.units; unit; unit = unit->next) { + if (unit->mode != UNITMODE_OFF) { + snprintf(buf, 1023, "Mode,Air,Beer,Target,Heater,Cooler,Fan,Door"); + filename = xstrcpy(unit->name); + filename = xstrcat(filename, (char *)".log"); + logger(filename, buf); + free(filename); + filename = NULL; + } + } do { lcdupdate = FALSE; @@ -311,17 +325,38 @@ } #endif + /* + * Timed schedulers + */ now = time(NULL); - if (((int)now - (int)last) > 60) { + if (now != last) { last = now; - if (Config.w1therms) { - tmp1 = Config.w1therms; - temp = tmp1->lastval; - tmp1 = tmp1->next; - if (temp && tmp1->lastval && run) { - snprintf(buf, 1023, "%.2f,%.2f", temp / 1000.0, tmp1->lastval / 1000.0); - logger((char *)"thermferm.log", (char *)"thermferm", buf); + seconds++; + + if (seconds == 60) { + seconds = 0; + + if (Config.w1therms) { + tmp1 = Config.w1therms; + temp = tmp1->lastval; + tmp1 = tmp1->next; + if (temp && tmp1->lastval && run) { + snprintf(buf, 1023, "%.2f,%.2f", temp / 1000.0, tmp1->lastval / 1000.0); + logger((char *)"thermferm.log", buf); + } } + + for (unit = Config.units; unit; unit = unit->next) { + if (unit->mode != UNITMODE_OFF) { + snprintf(buf, 1023, "%s,%.3f,%.3f,Target,Heater,Cooler,Fan,Door", + UNITMODE[unit->mode], unit->air_temperature / 1000.0, unit->beer_temperature / 1000.0); + filename = xstrcpy(unit->name); + filename = xstrcat(filename, (char *)".log"); + logger(filename, buf); + free(filename); + filename = NULL; + } + } } } usleep(100000);