diff -r 4091d4fe217f -r ab9f22ab57b5 thermferm/server.c --- a/thermferm/server.c Wed Jul 25 20:08:13 2018 +0200 +++ b/thermferm/server.c Tue Jul 31 16:42:11 2018 +0200 @@ -92,10 +92,10 @@ vsnprintf(out, SS_BUFSIZE-1, format, va_ptr); va_end(va_ptr); - if (debug) { - syslog(LOG_NOTICE, "send: \"%s\"", out); - fprintf(stdout, "send: \"%s\"\n", out); - } +// if (debug) { +// syslog(LOG_NOTICE, "send: \"%s\"", out); +// fprintf(stdout, "send: \"%s\"\n", out); +// } if (send(s, out, strlen(out), 0) != strlen(out)) { syslog(LOG_NOTICE, "srv_send failed"); @@ -148,10 +148,10 @@ } } - if (debug) { - syslog(LOG_NOTICE, "recv: %d `%s'", bytesloaded, buffer); - fprintf(stdout, "recv: %d `%s'\n", bytesloaded, buffer); - } +// if (debug) { +// syslog(LOG_NOTICE, "recv: %d `%s'", bytesloaded, buffer); +// fprintf(stdout, "recv: %d `%s'\n", bytesloaded, buffer); +// } return bytesloaded; } @@ -371,7 +371,9 @@ found = 0; for (unit = Config.units; unit; unit = unit->next) { if (unit->mode != UNITMODE_OFF) { - logname = xstrcpy(unit->name); + logname = xstrcpy(unit->product_code); + logname = xstrcat(logname, (char *)" "); + logname = xstrcat(logname, unit->product_name); logname = xstrcat(logname, (char *)".log"); if (! strcmp(result->d_name, logname)) found = 1; @@ -1190,7 +1192,7 @@ */ srv_send((char *)"212 Fermenter list follows:"); for (unit = Config.units; unit; unit = unit->next) { - srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]); + srv_send((char *)"%s,%s,%s", unit->uuid, unit->alias, UNITMODE[unit->mode]); } srv_send((char *)"."); return 0; @@ -1810,8 +1812,15 @@ Config.units = current->next; free(current->uuid); current->uuid = NULL; - free(current->name); - current->name = NULL; + if (current->product_uuid) + free(current->product_uuid); + current->product_uuid = NULL; + if (current->product_code) + free(current->product_code); + current->product_code = NULL; + if (current->product_name) + free(current->product_name); + current->product_name = NULL; if (current->air_address) free(current->air_address); current->air_address = NULL; @@ -1853,8 +1862,15 @@ } else { free(current->uuid); current->uuid = NULL; - free(current->name); - current->name = NULL; + if (current->product_uuid) + free(current->product_uuid); + current->product_uuid = NULL; + if (current->product_code) + free(current->product_code); + current->product_code = NULL; + if (current->product_name) + free(current->product_name); + current->product_name = NULL; if (current->air_address) free(current->air_address); current->air_address = NULL; @@ -1945,7 +1961,7 @@ if ((strcmp(opt, (char *)"LIST") == 0) && (param == NULL)) { srv_send((char *)"212 Fermenter list follows:"); for (unit = Config.units; unit; unit = unit->next) { - srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]); + srv_send((char *)"%s,%s,%s", unit->uuid, unit->alias, UNITMODE[unit->mode]); } srv_send((char *)"."); return 0; @@ -1967,7 +1983,9 @@ unit->uuid = malloc(37); uuid_generate(uu); uuid_unparse(uu, unit->uuid); - unit->name = xstrcpy(param); + unit->product_uuid = NULL; + unit->product_code = xstrcpy((char *)"FAKE0000"); + unit->product_name = xstrcpy(param); unit->alias = xstrcpy(an); unit->air_address = unit->beer_address = unit->chiller_address = unit->heater_address = unit->cooler_address = \ unit->fan_address = unit->door_address = unit->light_address = \ @@ -2050,9 +2068,10 @@ for (unit = Config.units; unit; unit = unit->next) { if (strcmp(param, unit->uuid) == 0) { srv_send((char *)"213 Unit listing follows:"); - srv_send((char *)"NAME,%s", unit->name); srv_send((char *)"UUID,%s", unit->uuid); srv_send((char *)"ALIAS,%s", unit->alias); + srv_send((char *)"PRODUCT_NAME,%s", unit->product_name); + srv_send((char *)"PRODUCT_CODE,%s", unit->product_code); srv_send((char *)"MODE,%s", UNITMODE[unit->mode]); srv_send((char *)"VOLUME,%2f", unit->volume); srv_send((char *)"AIR_ADDRESS,%s", unit->air_address); @@ -2170,14 +2189,24 @@ * but may also sent everything. Simply ignore things we * don't understand. */ - if (val && (strcmp(kwd, (char *)"NAME") == 0)) { - if (unit->name) { - if (strcmp(unit->name, val)) { - syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val); + if (val && (strcmp(kwd, (char *)"PRODUCT_CODE") == 0)) { + if (unit->product_code) { + if (strcmp(unit->product_code, val)) { + syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->product_code, val); } - free(unit->name); + free(unit->product_code); } - unit->name = xstrcpy(val); + unit->product_code = xstrcpy(val); + unit->mqtt_flag |= MQTT_FLAG_DATA; + + } else if (val && (strcmp(kwd, (char *)"PRODUCT_NAME") == 0)) { + if (unit->product_name) { + if (strcmp(unit->product_name, val)) { + syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->product_name, val); + } + free(unit->product_name); + } + unit->product_name = xstrcpy(val); unit->mqtt_flag |= MQTT_FLAG_DATA; } else if (val && (strcmp(kwd, (char *)"VOLUME") == 0)) { @@ -2441,7 +2470,7 @@ unit->mqtt_flag |= MQTT_FLAG_DATA; /* Initialize log if the unit is turned on */ if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) { - initlog(unit->name); + 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; @@ -2651,6 +2680,7 @@ if (unit->mqtt_flag & MQTT_FLAG_DEATH) { publishDDeath(unit); } + unit->mqtt_flag |= MQTT_FLAG_DLOG; // Something to log } #endif }