63 Config.temp_hum_idx = 0; |
63 Config.temp_hum_idx = 0; |
64 Config.temp_address = Config.hum_address = NULL; |
64 Config.temp_address = Config.hum_address = NULL; |
65 Config.temp_value = 20000; |
65 Config.temp_value = 20000; |
66 Config.temp_state = Config.hum_state = 1; // missing |
66 Config.temp_state = Config.hum_state = 1; // missing |
67 Config.hum_value = 50000; |
67 Config.hum_value = 50000; |
68 #ifdef HAVE_MOSQUITTO_H |
|
69 if (Config.mqtt_host) |
68 if (Config.mqtt_host) |
70 free(Config.mqtt_host); |
69 free(Config.mqtt_host); |
71 Config.mqtt_host = NULL; |
70 Config.mqtt_host = NULL; |
72 Config.mqtt_port = 1883; |
71 Config.mqtt_port = 1883; |
73 #endif |
72 if (Config.mqtt_username) |
|
73 free(Config.mqtt_username); |
|
74 Config.mqtt_username = NULL; |
|
75 if (Config.mqtt_password) |
|
76 free(Config.mqtt_password); |
|
77 Config.mqtt_password = NULL; |
74 |
78 |
75 for (tmp2 = Config.units; tmp2; tmp2 = tmp2->next) { |
79 for (tmp2 = Config.units; tmp2; tmp2 = tmp2->next) { |
76 if (tmp2->uuid) |
80 if (tmp2->uuid) |
77 free(tmp2->uuid); |
81 free(tmp2->uuid); |
78 if (tmp2->name) |
82 if (tmp2->name) |
253 } |
257 } |
254 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NEXT_UNIT", "%d", Config.next_unit)) < 0) { |
258 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NEXT_UNIT", "%d", Config.next_unit)) < 0) { |
255 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
259 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
256 return 1; |
260 return 1; |
257 } |
261 } |
258 #ifdef HAVE_MOSQUITTO_H |
|
259 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_HOST", "%s", Config.mqtt_host)) < 0) { |
262 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_HOST", "%s", Config.mqtt_host)) < 0) { |
260 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
263 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
261 return 1; |
264 return 1; |
262 } |
265 } |
263 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PORT", "%d", Config.mqtt_port)) < 0) { |
266 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PORT", "%d", Config.mqtt_port)) < 0) { |
264 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
267 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
265 return 1; |
268 return 1; |
266 } |
269 } |
267 #endif |
270 if (Config.mqtt_username && Config.mqtt_password) { |
|
271 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_USER", "%s", Config.mqtt_username)) < 0) { |
|
272 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
273 return 1; |
|
274 } |
|
275 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PASS", "%s", Config.mqtt_password)) < 0) { |
|
276 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
277 return 1; |
|
278 } |
|
279 } |
268 |
280 |
269 /* |
281 /* |
270 * Start an element named "LCDS" as child of THERMFERM. |
282 * Start an element named "LCDS" as child of THERMFERM. |
271 */ |
283 */ |
272 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "LCDS")) < 0) { |
284 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "LCDS")) < 0) { |
2129 return 1; |
2141 return 1; |
2130 } |
2142 } |
2131 } |
2143 } |
2132 syslog(LOG_NOTICE, "rdconfig: using %s", mypath); |
2144 syslog(LOG_NOTICE, "rdconfig: using %s", mypath); |
2133 |
2145 |
2134 #ifdef HAVE_MOSQUITTO_H |
|
2135 Config.mqtt_host = xstrcpy((char *)"localhost"); |
2146 Config.mqtt_host = xstrcpy((char *)"localhost"); |
2136 Config.mqtt_port = 1883; |
2147 Config.mqtt_port = 1883; |
2137 #endif |
|
2138 Config.next_unit = 1; |
2148 Config.next_unit = 1; |
2139 |
2149 |
2140 if ((cur = xmlDocGetRootElement(doc)) == NULL) { |
2150 if ((cur = xmlDocGetRootElement(doc)) == NULL) { |
2141 syslog(LOG_NOTICE, "XML file %s empty.", mypath); |
2151 syslog(LOG_NOTICE, "XML file %s empty.", mypath); |
2142 xmlFreeDoc(doc); |
2152 xmlFreeDoc(doc); |
2192 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
2202 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
2193 if (sscanf((const char *)key, "%d", &ival) == 1) |
2203 if (sscanf((const char *)key, "%d", &ival) == 1) |
2194 Config.next_unit = ival; |
2204 Config.next_unit = ival; |
2195 xmlFree(key); |
2205 xmlFree(key); |
2196 } |
2206 } |
2197 #ifdef HAVE_MOSQUITTO_H |
|
2198 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MQTT_HOST"))) { |
2207 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MQTT_HOST"))) { |
2199 Config.mqtt_host = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
2208 Config.mqtt_host = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
2200 } |
2209 } |
2201 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MQTT_PORT"))) { |
2210 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MQTT_PORT"))) { |
2202 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
2211 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
2203 if (sscanf((const char *)key, "%d", &ival) == 1) |
2212 if (sscanf((const char *)key, "%d", &ival) == 1) |
2204 Config.mqtt_port = ival; |
2213 Config.mqtt_port = ival; |
2205 xmlFree(key); |
2214 xmlFree(key); |
2206 } |
2215 } |
2207 #endif |
2216 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MQTT_USER"))) { |
|
2217 Config.mqtt_username = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
2218 } |
|
2219 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MQTT_PASS"))) { |
|
2220 Config.mqtt_password = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
2221 } |
2208 if ((!xmlStrcmp(cur->name, (const xmlChar *)"LCDS"))) { |
2222 if ((!xmlStrcmp(cur->name, (const xmlChar *)"LCDS"))) { |
2209 parseLCDs(doc, cur); |
2223 parseLCDs(doc, cur); |
2210 } |
2224 } |
2211 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FERMENTERS"))) { |
2225 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FERMENTERS"))) { |
2212 parseFermenters(doc, cur); |
2226 parseFermenters(doc, cur); |