176 mosquitto_publish(my_mosq, &mqtt_mid_sent, topic, 0, NULL, mqtt_qos, retain); |
176 mosquitto_publish(my_mosq, &mqtt_mid_sent, topic, 0, NULL, mqtt_qos, retain); |
177 } |
177 } |
178 |
178 |
179 |
179 |
180 |
180 |
|
181 void pub_domoticz_temp(int idx, char *value) { |
|
182 char *dload = NULL; |
|
183 char sidx[10]; |
|
184 |
|
185 if (idx == 0) |
|
186 return; |
|
187 |
|
188 sprintf(sidx, "%d", idx); |
|
189 |
|
190 dload = xstrcpy((char *)"{\"command\":\"udevice\",\"idx\":"); |
|
191 dload = xstrcat(dload, sidx); |
|
192 dload = xstrcat(dload, (char *)",\"nvalue\":0,\"svalue\":\""); |
|
193 dload = xstrcat(dload, value); |
|
194 dload = xstrcat(dload, (char *)"\"}"); |
|
195 publisher(mosq, (char *)"domoticz/in", dload, false); |
|
196 free(dload); |
|
197 dload = NULL; |
|
198 } |
|
199 |
|
200 |
|
201 |
181 char *unit_data(units_list *unit, bool birth) |
202 char *unit_data(units_list *unit, bool birth) |
182 { |
203 { |
183 char *payload = NULL; |
204 char *payload = NULL; |
184 char buf[128]; |
205 char buf[128]; |
185 bool comma = false; |
206 bool comma = false; |
204 payload = xstrcat(payload, (char *)TEMPSTATE[unit->air_state]); |
225 payload = xstrcat(payload, (char *)TEMPSTATE[unit->air_state]); |
205 payload = xstrcat(payload, (char *)"\",\"temperature\":"); |
226 payload = xstrcat(payload, (char *)"\",\"temperature\":"); |
206 sprintf(buf, "%.3f", unit->air_temperature / 1000.0); |
227 sprintf(buf, "%.3f", unit->air_temperature / 1000.0); |
207 payload = xstrcat(payload, buf); |
228 payload = xstrcat(payload, buf); |
208 payload = xstrcat(payload, (char *)"}"); |
229 payload = xstrcat(payload, (char *)"}"); |
|
230 pub_domoticz_temp(unit->air_idx, buf); |
209 } else { |
231 } else { |
210 payload = xstrcat(payload, (char *)"\",\"air\":null"); |
232 payload = xstrcat(payload, (char *)"\",\"air\":null"); |
211 } |
233 } |
212 |
234 |
213 if (unit->beer_address) { |
235 if (unit->beer_address) { |
217 payload = xstrcat(payload, (char *)TEMPSTATE[unit->beer_state]); |
239 payload = xstrcat(payload, (char *)TEMPSTATE[unit->beer_state]); |
218 payload = xstrcat(payload, (char *)"\",\"temperature\":"); |
240 payload = xstrcat(payload, (char *)"\",\"temperature\":"); |
219 sprintf(buf, "%.3f", unit->beer_temperature / 1000.0); |
241 sprintf(buf, "%.3f", unit->beer_temperature / 1000.0); |
220 payload = xstrcat(payload, buf); |
242 payload = xstrcat(payload, buf); |
221 payload = xstrcat(payload, (char *)"}"); |
243 payload = xstrcat(payload, (char *)"}"); |
|
244 pub_domoticz_temp(unit->beer_idx, buf); |
222 } else { |
245 } else { |
223 payload = xstrcat(payload, (char *)",\"beer\":null"); |
246 payload = xstrcat(payload, (char *)",\"beer\":null"); |
224 } |
247 } |
225 |
248 |
226 if (unit->heater_address) { |
249 if (unit->heater_address) { |
228 payload = xstrcat(payload, unit->heater_address); |
251 payload = xstrcat(payload, unit->heater_address); |
229 payload = xstrcat(payload, (char *)"\",\"state\":"); |
252 payload = xstrcat(payload, (char *)"\",\"state\":"); |
230 sprintf(buf, "%d", unit->heater_state); |
253 sprintf(buf, "%d", unit->heater_state); |
231 payload = xstrcat(payload, buf); |
254 payload = xstrcat(payload, buf); |
232 payload = xstrcat(payload, (char *)"}"); |
255 payload = xstrcat(payload, (char *)"}"); |
|
256 pub_domoticz_temp(unit->heater_idx, buf); |
233 } else { |
257 } else { |
234 payload = xstrcat(payload, (char *)",\"heater\":null"); |
258 payload = xstrcat(payload, (char *)",\"heater\":null"); |
235 } |
259 } |
236 |
260 |
237 if (unit->cooler_address) { |
261 if (unit->cooler_address) { |
239 payload = xstrcat(payload, unit->cooler_address); |
263 payload = xstrcat(payload, unit->cooler_address); |
240 payload = xstrcat(payload, (char *)"\",\"state\":"); |
264 payload = xstrcat(payload, (char *)"\",\"state\":"); |
241 sprintf(buf, "%d", unit->cooler_state); |
265 sprintf(buf, "%d", unit->cooler_state); |
242 payload = xstrcat(payload, buf); |
266 payload = xstrcat(payload, buf); |
243 payload = xstrcat(payload, (char *)"}"); |
267 payload = xstrcat(payload, (char *)"}"); |
|
268 pub_domoticz_temp(unit->cooler_idx, buf); |
244 } else { |
269 } else { |
245 payload = xstrcat(payload, (char *)",\"cooler\":null"); |
270 payload = xstrcat(payload, (char *)",\"cooler\":null"); |
246 } |
271 } |
247 |
272 |
248 if (unit->fan_address) { |
273 if (unit->fan_address) { |
250 payload = xstrcat(payload, unit->fan_address); |
275 payload = xstrcat(payload, unit->fan_address); |
251 payload = xstrcat(payload, (char *)"\",\"state\":"); |
276 payload = xstrcat(payload, (char *)"\",\"state\":"); |
252 sprintf(buf, "%d", unit->fan_state); |
277 sprintf(buf, "%d", unit->fan_state); |
253 payload = xstrcat(payload, buf); |
278 payload = xstrcat(payload, buf); |
254 payload = xstrcat(payload, (char *)"}"); |
279 payload = xstrcat(payload, (char *)"}"); |
|
280 pub_domoticz_temp(unit->fan_idx, buf); |
255 } else { |
281 } else { |
256 payload = xstrcat(payload, (char *)",\"fan\":null"); |
282 payload = xstrcat(payload, (char *)",\"fan\":null"); |
257 } |
283 } |
258 |
284 |
259 if (unit->door_address) { |
285 if (unit->door_address) { |
261 payload = xstrcat(payload, unit->door_address); |
287 payload = xstrcat(payload, unit->door_address); |
262 payload = xstrcat(payload, (char *)"\",\"state\":"); |
288 payload = xstrcat(payload, (char *)"\",\"state\":"); |
263 sprintf(buf, "%d", unit->door_state); |
289 sprintf(buf, "%d", unit->door_state); |
264 payload = xstrcat(payload, buf); |
290 payload = xstrcat(payload, buf); |
265 payload = xstrcat(payload, (char *)"}"); |
291 payload = xstrcat(payload, (char *)"}"); |
|
292 pub_domoticz_temp(unit->door_idx, buf); |
266 } else { |
293 } else { |
267 payload = xstrcat(payload, (char *)",\"door\":null"); |
294 payload = xstrcat(payload, (char *)",\"door\":null"); |
268 } |
295 } |
269 |
296 |
270 if (unit->light_address) { |
297 if (unit->light_address) { |
272 payload = xstrcat(payload, unit->light_address); |
299 payload = xstrcat(payload, unit->light_address); |
273 payload = xstrcat(payload, (char *)"\",\"state\":"); |
300 payload = xstrcat(payload, (char *)"\",\"state\":"); |
274 sprintf(buf, "%d", unit->light_state); |
301 sprintf(buf, "%d", unit->light_state); |
275 payload = xstrcat(payload, buf); |
302 payload = xstrcat(payload, buf); |
276 payload = xstrcat(payload, (char *)"}"); |
303 payload = xstrcat(payload, (char *)"}"); |
|
304 pub_domoticz_temp(unit->light_idx, buf); |
277 } else { |
305 } else { |
278 payload = xstrcat(payload, (char *)",\"light\":null"); |
306 payload = xstrcat(payload, (char *)",\"light\":null"); |
279 } |
307 } |
280 |
308 |
281 if (unit->psu_address) { |
309 if (unit->psu_address) { |
283 payload = xstrcat(payload, unit->psu_address); |
311 payload = xstrcat(payload, unit->psu_address); |
284 payload = xstrcat(payload, (char *)"\",\"state\":"); |
312 payload = xstrcat(payload, (char *)"\",\"state\":"); |
285 sprintf(buf, "%d", unit->psu_state); |
313 sprintf(buf, "%d", unit->psu_state); |
286 payload = xstrcat(payload, buf); |
314 payload = xstrcat(payload, buf); |
287 payload = xstrcat(payload, (char *)"}"); |
315 payload = xstrcat(payload, (char *)"}"); |
|
316 pub_domoticz_temp(unit->psu_idx, buf); |
288 } else { |
317 } else { |
289 payload = xstrcat(payload, (char *)",\"psu\":null"); |
318 payload = xstrcat(payload, (char *)",\"psu\":null"); |
290 } |
319 } |
291 |
320 |
292 payload = xstrcat(payload, (char *)",\"mode\":\""); |
321 payload = xstrcat(payload, (char *)",\"mode\":\""); |
404 |
433 |
405 |
434 |
406 void publishNData(bool birth, int flag) |
435 void publishNData(bool birth, int flag) |
407 { |
436 { |
408 #ifdef HAVE_MOSQUITTO_H |
437 #ifdef HAVE_MOSQUITTO_H |
409 char *payload = NULL, buf[64]; |
438 char *payload = NULL, sidx[10], buf[64]; |
410 struct utsname ubuf; |
439 struct utsname ubuf; |
411 bool comma = false; |
440 bool comma = false; |
412 |
441 |
413 payload = payload_header(); |
442 payload = payload_header(); |
414 payload = xstrcat(payload, (char *)"{"); |
443 payload = xstrcat(payload, (char *)"{"); |
467 else |
496 else |
468 publisher(mosq, topic_base((char *)"NDATA"), payload, false); |
497 publisher(mosq, topic_base((char *)"NDATA"), payload, false); |
469 |
498 |
470 free(payload); |
499 free(payload); |
471 payload = NULL; |
500 payload = NULL; |
|
501 |
|
502 if ((Config.temp_address || Config.hum_address) && Config.temp_hum_idx) { |
|
503 sprintf(sidx, "%d", Config.temp_hum_idx); |
|
504 sprintf(buf, "%.1f;%.1f;0", Config.temp_value / 1000.0, Config.hum_value / 1000.0); |
|
505 |
|
506 payload = xstrcpy((char *)"{\"command\":\"udevice\",\"idx\":"); |
|
507 payload = xstrcat(payload, sidx); |
|
508 payload = xstrcat(payload, (char *)",\"nvalue\":0,\"svalue\":\""); |
|
509 payload = xstrcat(payload, buf); |
|
510 payload = xstrcat(payload, (char *)"\"}"); |
|
511 publisher(mosq, (char *)"domoticz/in", payload, false); |
|
512 free(payload); |
|
513 payload = NULL; |
|
514 } |
472 #endif |
515 #endif |
473 } |
516 } |
474 |
517 |
475 |
518 |
476 |
519 |