# HG changeset patch # User Michiel Broek # Date 1557412817 -7200 # Node ID 95cf33f8021f7cb3adc9732f0cc0bc797b6877b9 # Parent 230a502b75ec0ccec521afc3d185a95d2ef8458a Removed writing local unit data logs diff -r 230a502b75ec -r 95cf33f8021f thermferm/Makefile --- a/thermferm/Makefile Sun Apr 28 19:59:43 2019 +0200 +++ b/thermferm/Makefile Thu May 09 16:40:17 2019 +0200 @@ -54,20 +54,19 @@ # DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT # Dependencies generated by make depend +mqtt.o: thermferm.h rdconfig.h devices.h xutil.h mqtt.h rc-switch.o: thermferm.h xutil.h rc-switch.h -mqtt.o: thermferm.h rdconfig.h logger.h devices.h xutil.h mqtt.h slcd.o: thermferm.h slcd.h futil.h xutil.h panel.o: thermferm.h lcd-pcf8574.h slcd.h panel.h devices.o: thermferm.h devices.h rc-switch.h panel.h xutil.h lcd-buffer.o: thermferm.h lcd-buffer.h lcd-pcf8574.h slcd.h panel.h futil.o: thermferm.h futil.h -thermferm.o: lock.h logger.h rdconfig.h devices.h server.h thermferm.h simulator.h lcd-pcf8574.h lcd-buffer.h slcd.h panel.h futil.h xutil.h pid.h mqtt.h +thermferm.o: lock.h rdconfig.h devices.h server.h thermferm.h simulator.h lcd-pcf8574.h lcd-buffer.h slcd.h panel.h futil.h xutil.h pid.h mqtt.h lock.o: lock.h thermferm.h -logger.o: logger.h thermferm.h futil.h xutil.h lcd-pcf8574.o: thermferm.h lcd-pcf8574.h slcd.h pid.o: thermferm.h pid.h xutil.o: thermferm.h xutil.h -server.o: rdconfig.h thermferm.h logger.h devices.h server.h lcd-buffer.h xutil.h mqtt.h +server.o: rdconfig.h thermferm.h devices.h server.h lcd-buffer.h xutil.h mqtt.h simulator.o: thermferm.h simulator.h rdconfig.o: rdconfig.h thermferm.h pid.h futil.h xutil.h # End of generated dependencies diff -r 230a502b75ec -r 95cf33f8021f thermferm/devices.c --- a/thermferm/devices.c Sun Apr 28 19:59:43 2019 +0200 +++ b/thermferm/devices.c Thu May 09 16:40:17 2019 +0200 @@ -350,8 +350,6 @@ if ((write_w1(device->address, (char *)"output", output)) == 0) { syslog(LOG_NOTICE, "DS2413 PIO%c value=%d (%s)", (device->subdevice == 0) ? 'A' : 'B', (value == 0) ? 0 : 1, device->comment); - if (debug) - fprintf(stdout, "DS2413 PIO%c value=%d (%s)\n", (device->subdevice == 0) ? 'A' : 'B', (value == 0) ? 0 : 1, device->comment); device->value = (value == 0) ? 0 : 1; device->timestamp = time(NULL); } diff -r 230a502b75ec -r 95cf33f8021f thermferm/logger.c --- a/thermferm/logger.c Sun Apr 28 19:59:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/***************************************************************************** - * Copyright (C) 2014-2019 - * - * Michiel Broek - * - * This file is part of the mbsePi-apps - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2, or (at your option) any - * later version. - * - * mbsePi-apps is distributed in the hope that it will be useful, 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. - * - * You should have received a copy of the GNU General Public License - * along with ThermFerm; see the file COPYING. If not, write to the Free - * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - *****************************************************************************/ - -#include "logger.h" -#include "thermferm.h" -#include "futil.h" -#include "xutil.h" - - -void initlog(char *code, char *name) -{ - char buf[128], *filename; - - snprintf(buf, 127, "Mode,Air,Beer,Target_L,S_Heater,S_Cooler,S_Fan,S_Door,U_Heater,U_Cooler,U_Fan,Room,Target_H,Chiller,Event"); - filename = xstrcpy(code); - filename = xstrcat(filename, (char *)" "); - filename = xstrcat(filename, name); - filename = xstrcat(filename, (char *)".log"); - logger(filename, buf); - free(filename); - filename = NULL; -} - - - -void logger(char *filename, char *data) -{ - struct timeval now; - struct tm ptm; - char *outstr = NULL, *name = NULL; - FILE *logfile; - - if (getenv((char *)"USER") == NULL) { - name = xstrcpy((char *)"/root"); - } else { - name = xstrcpy(getenv((char *)"HOME")); - } - name = xstrcat(name, (char *)"/.thermferm/log/"); - mkdirs(name, 0755); - name = xstrcat(name, filename); - - gettimeofday(&now, NULL); - localtime_r(&now.tv_sec, &ptm); - outstr = calloc(10240, sizeof(char)); - snprintf(outstr, 10239, "%04d-%02d-%02d %02d:%02d,%s\n", ptm.tm_year + 1900, ptm.tm_mon + 1, ptm.tm_mday, ptm.tm_hour, ptm.tm_min, data); - - if ((logfile = fopen(name, "a+"))) { - fprintf(logfile, outstr); - fclose(logfile); - } else { - syslog(LOG_NOTICE, "logger: cannot open %s for writing", name); - } - - free(outstr); - outstr = NULL; - free(name); - name = NULL; -} - - diff -r 230a502b75ec -r 95cf33f8021f thermferm/logger.h --- a/thermferm/logger.h Sun Apr 28 19:59:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -#ifndef LOGGER_H -#define LOGGER_H - - -void logger(char *, char *); -void initlog(char *, char *); - - -#endif diff -r 230a502b75ec -r 95cf33f8021f thermferm/mqtt.c --- a/thermferm/mqtt.c Sun Apr 28 19:59:43 2019 +0200 +++ b/thermferm/mqtt.c Thu May 09 16:40:17 2019 +0200 @@ -22,7 +22,6 @@ #include "thermferm.h" #include "rdconfig.h" -#include "logger.h" #include "devices.h" #include "xutil.h" #include "mqtt.h" @@ -153,9 +152,8 @@ void my_log_callback(struct mosquitto *my_mosq, void *obj, int level, const char *str) { -// syslog(LOG_NOTICE, "MQTT: %s", str); - if (debug) - fprintf(stdout, "MQTT: %s\n", str); +// if (debug) +// fprintf(stdout, "MQTT: %s\n", str); } @@ -238,7 +236,6 @@ unit->mqtt_flag |= MQTT_FLAG_DATA; /* Initialize log if the unit is turned on */ if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) { - initlog(unit->product_code, unit->product_name); unit->mqtt_flag |= MQTT_FLAG_BIRTH; } else if ((unit->mode != UNITMODE_OFF) && (i == UNITMODE_OFF)) { unit->mqtt_flag |= MQTT_FLAG_DEATH; @@ -442,7 +439,6 @@ cmd = NULL; } } else if (json_object_object_get_ex(profile, "uuid", &profile1)) { -// syslog(LOG_NOTICE, "profile new profile"); if ((unit->prof_state == PROFILE_OFF) || (unit->prof_state == PROFILE_DONE) || (unit->prof_state == PROFILE_ABORT)) { if (unit->profile_uuid) free(unit->profile_uuid); @@ -458,8 +454,6 @@ } unit->profile_steps = NULL; unit->profile_duration = unit->profile_totalsteps = 0; -// syslog(LOG_NOTICE, "profile new profile: old cleared"); - unit->profile_uuid = xstrcpy((char *)json_object_get_string(profile1)); if (json_object_object_get_ex(profile, "name", &val)) { unit->profile_name = xstrcpy((char *)json_object_get_string(val)); diff -r 230a502b75ec -r 95cf33f8021f thermferm/server.c --- a/thermferm/server.c Sun Apr 28 19:59:43 2019 +0200 +++ b/thermferm/server.c Thu May 09 16:40:17 2019 +0200 @@ -22,7 +22,6 @@ #include "rdconfig.h" #include "thermferm.h" -#include "logger.h" #include "devices.h" #include "server.h" #include "lcd-buffer.h" @@ -2195,7 +2194,6 @@ unit->mqtt_flag |= MQTT_FLAG_DATA; /* Initialize log if the unit is turned on */ if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) { - initlog(unit->product_code, unit->product_name); unit->mqtt_flag |= MQTT_FLAG_BIRTH; } else if ((unit->mode != UNITMODE_OFF) && (i == UNITMODE_OFF)) { unit->mqtt_flag |= MQTT_FLAG_DEATH; diff -r 230a502b75ec -r 95cf33f8021f thermferm/thermferm.c --- a/thermferm/thermferm.c Sun Apr 28 19:59:43 2019 +0200 +++ b/thermferm/thermferm.c Thu May 09 16:40:17 2019 +0200 @@ -21,7 +21,6 @@ *****************************************************************************/ #include "lock.h" -#include "logger.h" #include "rdconfig.h" #include "devices.h" #include "server.h" @@ -405,7 +404,6 @@ { current_unit->mqtt_flag |= MQTT_FLAG_DATA; if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) { - initlog(current_unit->product_code, current_unit->product_name); current_unit->mqtt_flag |= MQTT_FLAG_BIRTH; } else if ((current_unit->mode != UNITMODE_OFF) && (mode == UNITMODE_OFF)) { current_unit->mqtt_flag |= MQTT_FLAG_DEATH; @@ -1008,8 +1006,6 @@ int server(void) { - char buf[1024], *filename, target_lo[40], target_hi[40], heater[40], cooler[40], fan[40], door[40]; - char use_heater[40], use_cooler[40], use_fan[40], room_temp[40]; time_t now, last = (time_t)0, ndata = (time_t)0;; units_list *unit; prof_step *step; @@ -1122,13 +1118,6 @@ } else { syslog(LOG_NOTICE, "Starting unit `%s' in off state", unit->alias); } - - /* - * Initialize logfile - */ - if (unit->mode != UNITMODE_OFF) { - initlog(unit->product_code, unit->product_name); - } } printf("Units started\n"); publishDBirthAll(); @@ -1963,60 +1952,10 @@ seconds = 0; /* - * Log temperature and status every minute if unit is active. + * Publish data every minute if unit is active. */ for (unit = Config.units; unit; unit = unit->next) { if (unit->mode != UNITMODE_OFF) { - - snprintf(target_lo, 39, "NA"); - snprintf(target_hi, 39, "NA"); - snprintf(heater, 39, "NA"); - snprintf(cooler, 39, "NA"); - snprintf(fan, 39, "NA"); - snprintf(door, 39, "NA"); - snprintf(use_heater, 39, "NA"); - snprintf(use_cooler, 39, "NA"); - snprintf(use_fan, 39, "NA"); - snprintf(room_temp, 39, "NA"); - - if ((unit->mode == UNITMODE_BEER) || (unit->mode == UNITMODE_FRIDGE) || (unit->mode == UNITMODE_PROFILE)) { - snprintf(target_lo, 39, "%.1f", unit->PID_heat->SetP); - snprintf(target_hi, 39, "%.1f", unit->PID_cool->SetP); - } - - if (unit->heater_address) { - snprintf(heater, 39, "%d", unit->heater_state); - snprintf(use_heater, 39, "%d", unit->heater_usage); - } - if (unit->cooler_address) { - snprintf(cooler, 39, "%d", unit->cooler_state); - snprintf(use_cooler, 39, "%d", unit->cooler_usage); - } - if (unit->fan_address) { - snprintf(fan, 39, "%d", unit->fan_state); - snprintf(use_fan, 39, "%d", unit->fan_usage); - } - if (unit->door_address) { - snprintf(door, 39, "%d", unit->door_state); - } - if (Config.temp_address) { - snprintf(room_temp, 39, "%.3f", Config.temp_value / 1000.0); - } - - snprintf(buf, 1023, "%s,%.3f,%.3f,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%.3f,%s", - UNITMODE[unit->mode], unit->air_temperature / 1000.0, - unit->beer_temperature / 1000.0, - target_lo, heater, cooler, fan, door, use_heater, use_cooler, use_fan, room_temp, target_hi, - unit->chiller_temperature / 1000.0, - (unit->event_msg) ? unit->event_msg : (char *)""); - filename = xstrcpy(unit->product_code); - filename = xstrcat(filename, (char *)" "); - filename = xstrcat(filename, unit->product_name); - filename = xstrcat(filename, (char *)".log"); - logger(filename, buf); - free(filename); - filename = NULL; - publishDLog(unit); if (unit->event_msg) free(unit->event_msg);