diff -r 602d9968960f -r 5aa914eb644e thermferm/rdconfig.c --- a/thermferm/rdconfig.c Mon May 02 16:15:37 2016 +0200 +++ b/thermferm/rdconfig.c Mon May 09 21:35:55 2016 +0200 @@ -65,10 +65,10 @@ Config.temp_state = Config.hum_state = 1; // missing Config.hum_value = 50000; #ifdef HAVE_MOSQUITTO_H - if (Config.mosq_host) - free(Config.mosq_host); - Config.mosq_host = NULL; - Config.mosq_port = 1883; + if (Config.mqtt_host) + free(Config.mqtt_host); + Config.mqtt_host = NULL; + Config.mqtt_port = 1883; #endif for (tmp2 = Config.units; tmp2; tmp2 = tmp2->next) { @@ -244,6 +244,20 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NEXT_UNIT", "%d", Config.next_unit)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } +#ifdef HAVE_MOSQUITTO_H + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_HOST", "%s", Config.mqtt_host)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PORT", "%d", Config.mqtt_port)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } +#endif /* * Start an element named "LCDS" as child of THERMFERM. @@ -320,6 +334,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ALIAS", "%s", tmp3->alias)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME", "%.1f", tmp3->volume)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; @@ -1004,7 +1022,7 @@ /* * Parse a fermenter unit */ -int parseUnit(xmlDocPtr doc, xmlNodePtr cur) +int parseUnit(xmlDocPtr doc, xmlNodePtr cur, int number) { xmlChar *key; int i, ival; @@ -1014,7 +1032,7 @@ unit = (units_list *)malloc(sizeof(units_list)); unit->next = NULL; unit->version = 1; - unit->uuid = unit->name = unit->air_address = unit->beer_address = unit->heater_address = \ + unit->uuid = unit->name = unit->alias = unit->air_address = unit->beer_address = unit->heater_address = \ unit->cooler_address = unit->fan_address = unit->door_address = \ unit->light_address = unit->psu_address = unit->profile = NULL; unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0; @@ -1052,6 +1070,9 @@ if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) { unit->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"ALIAS"))) { + unit->alias = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"VOLUME"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%f", &val) == 1) @@ -1392,6 +1413,15 @@ cur = cur->next; } + /* + * If there is no alias name, create it. + */ + if (unit->alias == NULL) { + char an[128]; + sprintf(an, "unit%d", number); + unit->alias = xstrcpy(an); + } + if (Config.units == NULL) { Config.units = unit; } else { @@ -1413,7 +1443,8 @@ cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"UNIT"))) { - parseUnit(doc, cur); + parseUnit(doc, cur, Config.next_unit); + Config.next_unit++; } cur = cur->next; } @@ -1983,9 +2014,10 @@ syslog(LOG_NOTICE, "rdconfig: using %s", mypath); #ifdef HAVE_MOSQUITTO_H - Config.mosq_host = xstrcpy((char *)"localhost"); - Config.mosq_port = 1883; + Config.mqtt_host = xstrcpy((char *)"localhost"); + Config.mqtt_port = 1883; #endif + Config.next_unit = 1; if ((cur = xmlDocGetRootElement(doc)) == NULL) { syslog(LOG_NOTICE, "XML file %s empty.", mypath); @@ -2032,6 +2064,23 @@ if ((!xmlStrcmp(cur->name, (const xmlChar *)"HUM_ADDRESS"))) { Config.hum_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"NEXT_UNIT"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + Config.next_unit = ival; + xmlFree(key); + } +#ifdef HAVE_MOSQUITTO_H + if ((!xmlStrcmp(cur->name, (const xmlChar *)"MQTT_HOST"))) { + Config.mqtt_host = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"MQTT_PORT"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + Config.mqtt_port = ival; + xmlFree(key); + } +#endif if ((!xmlStrcmp(cur->name, (const xmlChar *)"LCDS"))) { parseLCDs(doc, cur); }