thermferm/mqtt.c

Mon, 21 Jan 2019 17:11:50 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 21 Jan 2019 17:11:50 +0100
changeset 577
7a29f835e20a
parent 575
86496d2bc4bb
child 578
d694abd9d809
permissions
-rw-r--r--

DLOG messages are no longer retained.

499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
2 * Copyright (C) 2016-2019
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 #include "thermferm.h"
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
24 #include "rdconfig.h"
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
25 #include "logger.h"
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
26 #include "devices.h"
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 #include "xutil.h"
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 #include "mqtt.h"
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 extern sys_config Config;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 extern int debug;
550
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
32 extern int my_shutdown;
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
33 extern int my_reboot;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
34 extern const char UNITMODE[5][8];
566
776a605befa5 Added Carbonation stage.
Michiel Broek <mbroek@mbse.eu>
parents: 564
diff changeset
35 extern const char UNITSTAGE[4][12];
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
36 extern const char PROFSTATE[5][6];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
37 extern const char TEMPSTATE[3][8];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
38
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
39 int Sequence = 0;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
40
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 /* Global variables for use in callbacks. */
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 int mqtt_qos = 0;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 int mqtt_status = STATUS_CONNECTING;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 int mqtt_mid_sent = 0;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 int mqtt_last_mid = -1;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 int mqtt_last_mid_sent = -1;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 int mqtt_connected = TRUE;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 int mqtt_disconnect_sent = FALSE;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 int mqtt_connect_lost = FALSE;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 int mqtt_my_shutdown = FALSE;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 int mqtt_use = FALSE;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 int keepalive = 60;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 unsigned int max_inflight = 20;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 struct mosquitto *mosq = NULL;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 char *state = NULL;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 char my_hostname[256];
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
62
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
63 char *payload_header(void)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
64 {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
65 char *tmp, buf[128];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
66
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
67 tmp = xstrcpy((char *)"{\"timestamp\":");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
68 sprintf(buf, "%ld", time(NULL));
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
69 tmp = xstrcat(tmp, buf);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
70 tmp = xstrcat(tmp, (char *)",\"seq\":");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
71 sprintf(buf, "%d", Sequence++);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
72 tmp = xstrcat(tmp, buf);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
73 tmp = xstrcat(tmp, (char *)",\"metric\":");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
74 return tmp;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
75 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
76
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
77
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
78
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
79 char *topic_base(char *msgtype)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
80 {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
81 char *tmp;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
82
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
83 tmp = xstrcpy((char *)"mbv1.0/fermenters/");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
84 tmp = xstrcat(tmp, msgtype);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
85 tmp = xstrcat(tmp, (char *)"/");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
86 tmp = xstrcat(tmp, my_hostname);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
87 return tmp;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
88 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
89
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
90
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
91
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 void my_connect_callback(struct mosquitto *my_mosq, void *obj, int result)
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
94 char *topic = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
95
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 if (mqtt_connect_lost) {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
97 mqtt_connect_lost = FALSE;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
98 syslog(LOG_NOTICE, "MQTT: reconnect: %s", mosquitto_connack_string(result));
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 if (!result) {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
102 topic = topic_base((char *)"NCMD");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
103 topic = xstrcat(topic, (char *)"/#");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
104 mosquitto_subscribe(mosq, NULL, topic, 0);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
105 free(topic);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
106 topic = topic_base((char *)"DCMD");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
107 topic = xstrcat(topic, (char *)"/#");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
108 mosquitto_subscribe(mosq, NULL, topic, 0);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
109 free(topic);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
110 topic = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
111 mqtt_status = STATUS_CONNACK_RECVD;
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 } else {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
113 syslog(LOG_NOTICE, "MQTT: my_connect_callback: %s\n", mosquitto_connack_string(result));
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 void my_disconnect_callback(struct mosquitto *my_mosq, void *obj, int rc)
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 if (mqtt_my_shutdown) {
500
5aa914eb644e Units now have an unique alias name so that the MQTT messages are more friendly.
Michiel Broek <mbroek@mbse.eu>
parents: 499
diff changeset
122 syslog(LOG_NOTICE, "MQTT: acknowledged DISCONNECT from %s", Config.mqtt_host);
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 mqtt_connected = FALSE;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 } else {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 /*
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 * The remote server was brought down. We must keep running
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 */
500
5aa914eb644e Units now have an unique alias name so that the MQTT messages are more friendly.
Michiel Broek <mbroek@mbse.eu>
parents: 499
diff changeset
128 syslog(LOG_NOTICE, "MQTT: received DISCONNECT from %s, connection lost", Config.mqtt_host);
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 mqtt_connect_lost = TRUE;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 void my_publish_callback(struct mosquitto *my_mosq, void *obj, int mid)
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 mqtt_last_mid_sent = mid;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
142 void my_subscribe_callback(struct mosquitto *my_mosq, void *userdata, int mid, int qos_count, const int *granted_qos)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
143 {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
144 int i;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
145
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
146 syslog(LOG_NOTICE, "Subscribed (mid: %d): %d", mid, granted_qos[0]);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
147 for (i = 1; i < qos_count; i++) {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
148 syslog(LOG_NOTICE, " %d", granted_qos[i]);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
149 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
150 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
151
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
152
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
153
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 void my_log_callback(struct mosquitto *my_mosq, void *obj, int level, const char *str)
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 {
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
156 // syslog(LOG_NOTICE, "MQTT: %s", str);
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 if (debug)
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 fprintf(stdout, "MQTT: %s\n", str);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
163 void my_message_callback(struct mosquitto *my_mosq, void *userdata, const struct mosquitto_message *message)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
164 {
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
165 char *message_type, *message_node, *message_alias;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
166 units_list *unit;
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
167 prof_step *step, *oldstep;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
168 struct json_object *jobj, *metric, *val, *setpoint, *profile, *profile1, *steps, *step1;
550
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
169 time_t timestamp;
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
170 int timediff;
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
171
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
172 if (message->payloadlen) {
550
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
173 /*
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
174 * Process received commands
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
175 */
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
176 strtok(message->topic, "/"); // Ignore mbv1.0
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
177 strtok(NULL, "/"); // Ignore group_id
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
178 message_type = strtok(NULL, "/");
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
179 message_node = strtok(NULL, "/\0");
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
180 message_alias = strtok(NULL, "\0");
550
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
181
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
182 jobj = json_tokener_parse(message->payload);
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
183 if (json_object_object_get_ex(jobj, "timestamp", &val)) {
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
184 timestamp = json_object_get_int(val);
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
185 timediff = (int)timestamp - time(NULL);
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
186 if ((timediff < 61) && (timediff > -61)) {
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
187 if (json_object_object_get_ex(jobj, "metric", &metric)) {
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
188 if ((json_object_object_get_ex(metric, "Node Control/Reboot", &val)) && (strcmp(message_type, "NCMD") == 0)) {
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
189 if (json_object_get_boolean(val) == true) {
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
190 syslog(LOG_NOTICE, "MQTT: `Node Control/Reboot' command");
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
191 /*
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
192 * Reboot. The erver process will restart which is handled
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
193 * in the main thread loop.
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
194 */
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
195 my_reboot = my_shutdown = TRUE;
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
196 return;
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
197 }
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
198 }
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
199 if ((json_object_object_get_ex(metric, "Node Control/Rebirth", &val)) && (strcmp(message_type, "NCMD") == 0)) {
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
200 if (json_object_get_boolean(val) == true) {
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
201 /*
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
202 * Resend all birth certificates.
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
203 */
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
204 syslog(LOG_NOTICE, "MQTT: `Node Control/Rebirth' command");
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
205 publishNData(true, 0);
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
206 publishDBirthAll();
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
207 return;
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
208 }
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
209 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
210
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
211 /*
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
212 * DCMD, commands and configuration changes for a single fermenter.
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
213 */
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
214 if ((strcmp(message_type, "DCMD") == 0) && message_node && message_alias) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
215 syslog(LOG_NOTICE, "%s", (char *)json_object_get_string(metric));
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
216 for (unit = Config.units ; unit; unit = unit->next) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
217 if (strcmp(unit->alias, message_alias) == 0) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
218 syslog(LOG_NOTICE, "MQTT: DCMD for %s/%s", (char *)message_node, (char *)message_alias);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
219 if (json_object_object_get_ex(metric, "stage", &val)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
220 for (int i = 0; i < 4; i++) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
221 if (strcmp((char *)json_object_get_string(val), UNITSTAGE[i]) == 0) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
222 if (unit->stage != i) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
223 syslog(LOG_NOTICE, "DCMD change fermenter %s: stage to %s", message_alias, UNITSTAGE[i]);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
224 unit->mqtt_flag |= MQTT_FLAG_DATA;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
225 unit->stage = i;
575
86496d2bc4bb Version 0.9.2 DLOG messages every minute unless a unit is off. More event messages added. The target temperatur is now taken from the PIDs.
Michiel Broek <mbroek@mbse.eu>
parents: 571
diff changeset
226 if ((unit->mode != UNITMODE_OFF) && ! unit->event_msg)
86496d2bc4bb Version 0.9.2 DLOG messages every minute unless a unit is off. More event messages added. The target temperatur is now taken from the PIDs.
Michiel Broek <mbroek@mbse.eu>
parents: 571
diff changeset
227 unit->event_msg = xstrcpy((char *)UNITSTAGE[i]);
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
228 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
229 break;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
230 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
231 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
232 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
233
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
234 if (json_object_object_get_ex(metric, "mode", &val)) {
571
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
235 for (int i = 0; i < 5; i++) {
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
236 if (strcmp((char *)json_object_get_string(val), UNITMODE[i]) == 0) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
237 if (unit->mode != i) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
238 unit->mqtt_flag |= MQTT_FLAG_DATA;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
239 /* Initialize log if the unit is turned on */
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
240 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
241 initlog(unit->product_code, unit->product_name);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
242 unit->mqtt_flag |= MQTT_FLAG_BIRTH;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
243 } else if ((unit->mode != UNITMODE_OFF) && (i == UNITMODE_OFF)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
244 unit->mqtt_flag |= MQTT_FLAG_DEATH;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
245 }
571
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
246 if (i == UNITMODE_PROFILE) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
247 /* Do some checks and refuse profile mode cannot be set */
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
248 if (unit->profile_uuid == NULL) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
249 syslog(LOG_NOTICE, "Fermenter unit %s refuse profile, not loaded", message_alias);
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
250 break;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
251 }
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
252 }
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
253 syslog(LOG_NOTICE, "DCMD change fermenter %s: mode to %s", message_alias, UNITMODE[i]);
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
254 unit->mode = i;
575
86496d2bc4bb Version 0.9.2 DLOG messages every minute unless a unit is off. More event messages added. The target temperatur is now taken from the PIDs.
Michiel Broek <mbroek@mbse.eu>
parents: 571
diff changeset
255 if ((unit->mode != UNITMODE_OFF) && ! unit->event_msg)
86496d2bc4bb Version 0.9.2 DLOG messages every minute unless a unit is off. More event messages added. The target temperatur is now taken from the PIDs.
Michiel Broek <mbroek@mbse.eu>
parents: 571
diff changeset
256 unit->event_msg = xstrcpy((char *)UNITMODE[i]);
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
257 /* Allways turn everything off after a mode change */
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
258 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
259 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
260 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
261 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
262 device_out(unit->heater_address, unit->heater_state);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
263 device_out(unit->cooler_address, unit->cooler_state);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
264 device_out(unit->fan_address, unit->fan_state);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
265 device_out(unit->light_address, unit->light_state);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
266 if (unit->mode == UNITMODE_PROFILE) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
267 /*
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
268 * Set a sane default until it will be overruled by the
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
269 * main processing loop.
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
270 */
571
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
271 unit->prof_target_lo = unit->profile_inittemp_lo;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
272 unit->prof_target_hi = unit->profile_inittemp_hi;;
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
273 unit->prof_fridge_mode = 0;
571
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
274 unit->prof_state = PROFILE_OFF;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
275 unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
276 unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
277 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
278 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
279 break;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
280 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
281 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
282 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
283
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
284 if (json_object_object_get_ex(metric, "setpoint", &setpoint)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
285 if ((unit->mode == UNITMODE_FRIDGE) || (unit->mode == UNITMODE_BEER)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
286 /*
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
287 * Only set new setpoints if running in FRIDGE or in BEER mode.
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
288 */
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
289 if (json_object_object_get_ex(setpoint, "low", &val))
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
290 unit->PID_heat->SetP = json_object_get_double(val);
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
291 if (json_object_object_get_ex(setpoint, "high", &val))
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
292 unit->PID_cool->SetP = json_object_get_double(val);
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
293 if (unit->mode == UNITMODE_FRIDGE)
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
294 unit->fridge_set = unit->PID_heat->SetP + ((unit->PID_cool->SetP - unit->PID_heat->SetP) / 2);
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
295 else
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
296 unit->beer_set = unit->PID_heat->SetP + ((unit->PID_cool->SetP - unit->PID_heat->SetP) / 2);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
297 unit->mqtt_flag |= MQTT_FLAG_DATA;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
298 syslog(LOG_NOTICE, "DCMD change fermenter %s: setpoints %.1f %.1f", message_alias, unit->PID_heat->SetP, unit->PID_cool->SetP);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
299 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
300 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
301
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
302 if ((json_object_object_get_ex(metric, "heater", &setpoint)) && (unit->mode == UNITMODE_NONE)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
303 if (json_object_object_get_ex(setpoint, "state", &val)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
304 if (json_object_get_int(val) != unit->heater_state) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
305 unit->heater_state = json_object_get_int(val);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
306 if (unit->heater_state) // Safety
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
307 unit->cooler_state = 0;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
308 unit->mqtt_flag |= MQTT_FLAG_DATA;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
309 syslog(LOG_NOTICE, "DCMD change fermenter %s: heater_state to %d", message_alias, unit->heater_state);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
310 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
311 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
312 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
313
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
314 if ((json_object_object_get_ex(metric, "cooler", &setpoint)) && (unit->mode == UNITMODE_NONE)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
315 if (json_object_object_get_ex(setpoint, "state", &val)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
316 if (json_object_get_int(val) != unit->cooler_state) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
317 unit->cooler_state = json_object_get_int(val);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
318 if (unit->cooler_state)
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
319 unit->heater_state = 0;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
320 unit->mqtt_flag |= MQTT_FLAG_DATA;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
321 syslog(LOG_NOTICE, "DCMD change fermenter %s: cooler_state to %d", message_alias, unit->cooler_state);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
322 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
323 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
324 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
325
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
326 if ((json_object_object_get_ex(metric, "fan", &setpoint)) && (unit->mode == UNITMODE_NONE)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
327 if (json_object_object_get_ex(setpoint, "state", &val)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
328 if (json_object_get_int(val) != unit->fan_state) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
329 unit->fan_state = json_object_get_int(val);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
330 unit->mqtt_flag |= MQTT_FLAG_DATA;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
331 syslog(LOG_NOTICE, "DCMD change fermenter %s: fan_state to %d", message_alias, unit->fan_state);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
332 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
333 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
334 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
335
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
336 if ((json_object_object_get_ex(metric, "light", &setpoint)) && (unit->mode == UNITMODE_NONE)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
337 if (json_object_object_get_ex(setpoint, "state", &val)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
338 if (json_object_get_int(val) != unit->light_state) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
339 unit->light_state = json_object_get_int(val);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
340 unit->mqtt_flag |= MQTT_FLAG_DATA;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
341 syslog(LOG_NOTICE, "DCMD change fermenter %s: light_state to %d", message_alias, unit->light_state);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
342 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
343 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
344 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
345
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
346 if ((json_object_object_get_ex(metric, "product", &setpoint)) && (unit->mode == UNITMODE_OFF)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
347 if (json_object_object_get_ex(setpoint, "code", &val)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
348 if (strcmp((char *)json_object_get_string(val), unit->product_code)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
349 free(unit->product_code);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
350 unit->product_code = xstrcpy((char *)json_object_get_string(val));
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
351 unit->mqtt_flag |= MQTT_FLAG_DATA;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
352 syslog(LOG_NOTICE, "DCMD change fermenter %s: product_code to `%s'", message_alias, unit->product_code);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
353 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
354 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
355 if (json_object_object_get_ex(setpoint, "name", &val)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
356 if (strcmp((char *)json_object_get_string(val), unit->product_name)) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
357 free(unit->product_name);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
358 unit->product_name = xstrcpy((char *)json_object_get_string(val));
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
359 unit->mqtt_flag |= MQTT_FLAG_DATA;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
360 syslog(LOG_NOTICE, "DCMD change fermenter %s: product_name to `%s'", message_alias, unit->product_name);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
361 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
362 }
571
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
363 if (json_object_object_get_ex(setpoint, "uuid", &val)) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
364 if (strcmp((char *)json_object_get_string(val), unit->product_uuid)) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
365 free(unit->product_uuid);
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
366 unit->product_uuid = xstrcpy((char *)json_object_get_string(val));
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
367 unit->mqtt_flag |= MQTT_FLAG_DATA;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
368 syslog(LOG_NOTICE, "DCMD change fermenter %s: product_uuid to `%s'", message_alias, unit->product_uuid);
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
369 }
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
370 }
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
371 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
372
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
373 if (json_object_object_get_ex(metric, "profile", &profile)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
374 if (json_object_object_get_ex(profile, "command", &profile1)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
375 syslog(LOG_NOTICE, "profile command");
571
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
376 if (unit->mode == UNITMODE_PROFILE) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
377 char *cmd = xstrcpy((char *)json_object_get_string(profile1));
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
378 if (! strcmp(cmd, (char *)"off")) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
379 if (unit->prof_state == PROFILE_DONE) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
380 unit->prof_state = PROFILE_OFF;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
381 syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile to OFF", message_alias);
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
382 unit->mqtt_flag |= MQTT_FLAG_DATA;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
383 }
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
384 } else if (! strcmp(cmd, (char *)"pause")) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
385 if (unit->prof_state == PROFILE_RUN) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
386 unit->prof_state = PROFILE_PAUSE;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
387 syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile to PAUSE", message_alias);
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
388 unit->mqtt_flag |= MQTT_FLAG_DATA;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
389 } else if (unit->prof_state == PROFILE_PAUSE) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
390 unit->prof_state = PROFILE_RUN;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
391 syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile resume RUN", message_alias);
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
392 unit->mqtt_flag |= MQTT_FLAG_DATA;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
393 }
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
394 } else if (! strcmp(cmd, (char *)"start")) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
395 if (unit->prof_state == PROFILE_OFF) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
396 unit->prof_state = PROFILE_RUN;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
397 unit->prof_started = time(NULL);
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
398 unit->prof_paused = unit->prof_primary_done = 0;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
399 unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
400 syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile start RUN", message_alias);
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
401 unit->mqtt_flag |= MQTT_FLAG_DATA;
575
86496d2bc4bb Version 0.9.2 DLOG messages every minute unless a unit is off. More event messages added. The target temperatur is now taken from the PIDs.
Michiel Broek <mbroek@mbse.eu>
parents: 571
diff changeset
402 if (! unit->event_msg)
86496d2bc4bb Version 0.9.2 DLOG messages every minute unless a unit is off. More event messages added. The target temperatur is now taken from the PIDs.
Michiel Broek <mbroek@mbse.eu>
parents: 571
diff changeset
403 unit->event_msg = xstrcpy((char *)"Profile start");
571
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
404 }
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
405 } else if (! strcmp(cmd, (char *)"abort")) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
406 if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
407 unit->prof_state = PROFILE_OFF;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
408 unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
409 unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
410 syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile ABORT", message_alias);
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
411 unit->mqtt_flag |= MQTT_FLAG_DATA;
575
86496d2bc4bb Version 0.9.2 DLOG messages every minute unless a unit is off. More event messages added. The target temperatur is now taken from the PIDs.
Michiel Broek <mbroek@mbse.eu>
parents: 571
diff changeset
412 if (! unit->event_msg)
86496d2bc4bb Version 0.9.2 DLOG messages every minute unless a unit is off. More event messages added. The target temperatur is now taken from the PIDs.
Michiel Broek <mbroek@mbse.eu>
parents: 571
diff changeset
413 unit->event_msg = xstrcpy((char *)"Profile abort");
571
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
414 }
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
415 } else if (! strcmp(cmd, (char *)"done")) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
416 if (unit->prof_state == PROFILE_DONE) {
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
417 unit->prof_state = PROFILE_OFF;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
418 unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
419 unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
420 syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile OFF", message_alias);
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
421 unit->mqtt_flag |= MQTT_FLAG_DATA;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
422 }
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
423 }
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
424 free(cmd);
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
425 cmd = NULL;
6f8eda55ec2c Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents: 570
diff changeset
426 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
427 } else if (json_object_object_get_ex(profile, "uuid", &profile1)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
428 // syslog(LOG_NOTICE, "profile new profile");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
429 if ((unit->prof_state == PROFILE_OFF) || (unit->prof_state == PROFILE_DONE) || (unit->prof_state == PROFILE_ABORT)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
430 if (unit->profile_uuid)
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
431 free(unit->profile_uuid);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
432 if (unit->profile_name)
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
433 free(unit->profile_name);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
434 if (unit->profile_steps) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
435 for (step = unit->profile_steps; step; step = oldstep) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
436 if (step->name)
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
437 free(step->name);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
438 oldstep = step->next;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
439 free(step);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
440 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
441 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
442 unit->profile_steps = NULL;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
443 unit->profile_duration = unit->profile_totalsteps = 0;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
444 // syslog(LOG_NOTICE, "profile new profile: old cleared");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
445
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
446 unit->profile_uuid = xstrcpy((char *)json_object_get_string(profile1));
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
447 if (json_object_object_get_ex(profile, "name", &val)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
448 unit->profile_name = xstrcpy((char *)json_object_get_string(val));
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
449 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
450 if (json_object_object_get_ex(profile, "inittemp", &setpoint)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
451 if (json_object_object_get_ex(setpoint, "low", &val)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
452 unit->profile_inittemp_lo = json_object_get_double(val);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
453 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
454 if (json_object_object_get_ex(setpoint, "high", &val)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
455 unit->profile_inittemp_hi = json_object_get_double(val);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
456 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
457 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
458 if (json_object_object_get_ex(profile, "fridgemode", &val)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
459 unit->profile_fridge_mode = json_object_get_int(val);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
460 if (unit->profile_fridge_mode)
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
461 unit->profile_fridge_mode = 100;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
462 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
463 if (json_object_object_get_ex(profile, "steps", &steps)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
464 int arraylen = json_object_array_length(steps);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
465 syslog(LOG_NOTICE, "profile new profile: start %d steps", arraylen);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
466 for (int i = 0; i < arraylen; i++) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
467 /*
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
468 * Parse the array of steps
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
469 */
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
470 step1 = json_object_array_get_idx(steps, i);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
471 unit->profile_totalsteps++;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
472
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
473 step = (prof_step *)malloc(sizeof(prof_step));
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
474 step->next = NULL;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
475 step->name = NULL;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
476 step->steptime = step->resttime = step->fridge_mode = 0;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
477 step->target_lo = step->target_hi = 20.0;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
478
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
479 if (json_object_object_get_ex(step1, "name", &val)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
480 step->name = xstrcpy((char *)json_object_get_string(val));
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
481 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
482 if (json_object_object_get_ex(step1, "steptime", &val)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
483 step->steptime = json_object_get_int(val);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
484 unit->profile_duration += step->steptime;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
485 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
486 if (json_object_object_get_ex(step1, "resttime", &val)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
487 step->resttime = json_object_get_int(val);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
488 unit->profile_duration += step->resttime;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
489 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
490 if (json_object_object_get_ex(step1, "fridgemode", &val)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
491 step->fridge_mode = json_object_get_int(val);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
492 if (step->fridge_mode)
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
493 step->fridge_mode = 100;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
494 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
495 if (json_object_object_get_ex(step1, "target_lo", &val)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
496 step->target_lo = json_object_get_double(val);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
497 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
498 if (json_object_object_get_ex(step1, "target_hi", &val)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
499 step->target_hi = json_object_get_double(val);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
500 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
501
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
502 syslog(LOG_NOTICE, "profile new profile: add step %d", unit->profile_totalsteps);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
503 if (unit->profile_steps == NULL) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
504 unit->profile_steps = step;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
505 } else {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
506 for (oldstep = unit->profile_steps; oldstep; oldstep = oldstep->next) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
507 if (oldstep->next == NULL) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
508 oldstep->next = step;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
509 break;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
510 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
511 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
512 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
513 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
514 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
515 unit->mqtt_flag |= MQTT_FLAG_DATA;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
516 syslog(LOG_NOTICE, "DCMD change fermenter %s: install profile `%s'", message_alias, unit->profile_name);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
517 wrconfig();
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
518 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
519 } else {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
520 if ((unit->prof_state == PROFILE_OFF) || (unit->prof_state == PROFILE_DONE) || (unit->prof_state == PROFILE_ABORT)) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
521 syslog(LOG_NOTICE, "DCMD change fermenter %s: delete profile `%s'", message_alias, unit->profile_name);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
522 if (unit->profile_uuid)
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
523 free(unit->profile_uuid);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
524 if (unit->profile_name)
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
525 free(unit->profile_name);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
526 unit->profile_uuid = unit->profile_name = NULL;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
527 if (unit->profile_steps) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
528 for (step = unit->profile_steps; step; step = oldstep) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
529 if (step->name)
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
530 free(step->name);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
531 oldstep = step->next;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
532 free(step);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
533 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
534 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
535 unit->profile_steps = NULL;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
536 unit->profile_inittemp_lo = unit->profile_inittemp_hi = 20.0;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
537 unit->prof_percent = unit->profile_fridge_mode = 0;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
538 unit->prof_state = PROFILE_OFF;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
539 unit->profile_duration = unit->profile_totalsteps = 0;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
540 unit->prof_started = unit->prof_paused = unit->prof_primary_done = (time_t)0;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
541 unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
542 unit->mqtt_flag |= MQTT_FLAG_DATA;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
543 wrconfig();
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
544 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
545 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
546 }
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
547 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
548
569
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
549 if (unit->mqtt_flag) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
550 if (unit->mqtt_flag & MQTT_FLAG_BIRTH) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
551 publishDBirth(unit);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
552 } else {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
553 publishDData(unit);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
554 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
555 if (unit->mqtt_flag & MQTT_FLAG_DEATH) {
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
556 publishDDeath(unit);
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
557 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
558 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
559 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
560 return;
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
561 }
550
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
562 syslog(LOG_NOTICE, "MQTT: %s payload not understood\n", (char *)message->payload);
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
563 return;
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
564 }
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
565 } else {
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
566 syslog(LOG_NOTICE, "MQTT: got payload with timestamp %d seconds error", timediff);
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
567 return;
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
568 }
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
569 }
04c942cded91 Versie 0.8.3. Enkele debug console berichten verwijderd. De MQTT NCMD reboot en rebirth commando's geimplementeerd.
Michiel Broek <mbroek@mbse.eu>
parents: 549
diff changeset
570
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
571 syslog(LOG_NOTICE, "MQTT: message callback %s :: %d", message->topic, message->payloadlen);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
572 } else {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
573 syslog(LOG_NOTICE, "MQTT: message callback %s (null)", message->topic);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
574 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
575 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
576
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
577
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
578
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
579 void publisher(struct mosquitto *my_mosq, char *topic, char *payload, bool retain) {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
580 // publish the data
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
581 if (payload)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
582 mosquitto_publish(my_mosq, &mqtt_mid_sent, topic, strlen(payload), payload, mqtt_qos, retain);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
583 else
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
584 mosquitto_publish(my_mosq, &mqtt_mid_sent, topic, 0, NULL, mqtt_qos, retain);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
585 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
586
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
587
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
588
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
589 void pub_domoticz_temp(int idx, int value) {
513
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
590 char *dload = NULL;
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
591 char sidx[10], sval[20];
513
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
592
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
593 if (idx == 0)
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
594 return;
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
595
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
596 sprintf(sidx, "%d", idx);
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
597 sprintf(sval, "%.3f", value / 1000.0);
513
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
598
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
599 dload = xstrcpy((char *)"{\"command\":\"udevice\",\"idx\":");
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
600 dload = xstrcat(dload, sidx);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
601 dload = xstrcat(dload, (char *)",\"nvalue\":0,\"svalue\":\"");
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
602 dload = xstrcat(dload, sval);
513
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
603 dload = xstrcat(dload, (char *)"\"}");
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
604 publisher(mosq, (char *)"domoticz/in", dload, false);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
605 free(dload);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
606 dload = NULL;
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
607 }
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
608
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
609
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
610
514
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
611 void pub_domoticz_output(int idx, int value) {
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
612 char *dload = NULL;
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
613 char sidx[10], sval[10];
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
614
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
615 if (idx == 0)
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
616 return;
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
617
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
618 sprintf(sidx, "%d", idx);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
619 sprintf(sval, "%d", value);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
620
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
621 dload = xstrcpy((char *)"{\"command\":\"udevice\",\"idx\":");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
622 dload = xstrcat(dload, sidx);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
623 dload = xstrcat(dload, (char *)",\"nvalue\":");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
624 if (value >= 50)
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
625 dload = xstrcat(dload, (char *)"1");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
626 else
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
627 dload = xstrcat(dload, (char *)"0");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
628 dload = xstrcat(dload, (char *)",\"svalue\":\"");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
629 dload = xstrcat(dload, sval);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
630 dload = xstrcat(dload, (char *)"\"}");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
631 publisher(mosq, (char *)"domoticz/in", dload, false);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
632 free(dload);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
633 dload = NULL;
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
634 }
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
635
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
636
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
637
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
638 char *unit_data(units_list *unit, bool birth)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
639 {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
640 char *payload = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
641 char buf[128];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
642 bool comma = false;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
643 prof_step *pstep;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
644
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
645 payload = xstrcpy((char *)"{");
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
646
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
647 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
648 * Fixed unit values, never change these!
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
649 */
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
650 if (birth) {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
651 payload = xstrcat(payload, (char *)"\"uuid\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
652 payload = xstrcat(payload, unit->uuid);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
653 payload = xstrcat(payload, (char *)"\",\"alias\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
654 payload = xstrcat(payload, unit->alias);
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
655 payload = xstrcat(payload, (char *)"\",");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
656 }
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
657
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
658 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
659 * Product (beer) loaded information.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
660 */
554
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
661 if ((unit->product_name && strlen(unit->product_name)) ||
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
662 (unit->product_code && strlen(unit->product_code)) ||
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
663 (unit->product_uuid && strlen(unit->product_uuid))) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
664 comma = false;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
665 payload = xstrcat(payload, (char *)"\"product\":{");
564
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
666 if (unit->product_uuid && strlen(unit->product_uuid) && strcmp((char *)"(null)", unit->product_uuid)) {
554
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
667 payload = xstrcat(payload, (char *)"\"uuid\":\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
668 payload = xstrcat(payload, unit->product_uuid);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
669 payload = xstrcat(payload, (char *)"\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
670 comma = true;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
671 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
672 if (unit->product_code && strlen(unit->product_code)) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
673 if (comma)
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
674 payload = xstrcat(payload, (char *)",");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
675 payload = xstrcat(payload, (char *)"\"code\":\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
676 payload = xstrcat(payload, unit->product_code);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
677 payload = xstrcat(payload, (char *)"\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
678 comma = true;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
679 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
680 if (unit->product_name && strlen(unit->product_name)) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
681 if (comma)
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
682 payload = xstrcat(payload, (char *)",");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
683 payload = xstrcat(payload, (char *)"\"name\":\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
684 payload = xstrcat(payload, unit->product_name);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
685 payload = xstrcat(payload, (char *)"\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
686 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
687 payload = xstrcat(payload, (char *)"}");
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
688 }
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
689
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
690 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
691 * Air temperature sensor
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
692 */
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
693 if (unit->air_address) {
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
694 payload = xstrcat(payload, (char *)",\"air\":{\"address\":\"");
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
695 payload = xstrcat(payload, unit->air_address);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
696 payload = xstrcat(payload, (char *)"\",\"state\":\"");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
697 payload = xstrcat(payload, (char *)TEMPSTATE[unit->air_state]);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
698 payload = xstrcat(payload, (char *)"\",\"temperature\":");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
699 sprintf(buf, "%.3f", unit->air_temperature / 1000.0);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
700 payload = xstrcat(payload, buf);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
701 payload = xstrcat(payload, (char *)"}");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
702 } else {
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
703 payload = xstrcat(payload, (char *)",\"air\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
704 }
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
705
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
706 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
707 * Beer temperature sensor
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
708 */
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
709 if (unit->beer_address) {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
710 payload = xstrcat(payload, (char *)",\"beer\":{\"address\":\"");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
711 payload = xstrcat(payload, unit->beer_address);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
712 payload = xstrcat(payload, (char *)"\",\"state\":\"");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
713 payload = xstrcat(payload, (char *)TEMPSTATE[unit->beer_state]);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
714 payload = xstrcat(payload, (char *)"\",\"temperature\":");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
715 sprintf(buf, "%.3f", unit->beer_temperature / 1000.0);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
716 payload = xstrcat(payload, buf);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
717 payload = xstrcat(payload, (char *)"}");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
718 } else {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
719 payload = xstrcat(payload, (char *)",\"beer\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
720 }
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
721
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
722 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
723 * External chiller temperature sensor
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
724 */
518
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
725 if (unit->chiller_address) {
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
726 payload = xstrcat(payload, (char *)",\"chiller\":{\"address\":\"");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
727 payload = xstrcat(payload, unit->chiller_address);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
728 payload = xstrcat(payload, (char *)"\",\"state\":\"");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
729 payload = xstrcat(payload, (char *)TEMPSTATE[unit->chiller_state]);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
730 payload = xstrcat(payload, (char *)"\",\"temperature\":");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
731 sprintf(buf, "%.3f", unit->chiller_temperature / 1000.0);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
732 payload = xstrcat(payload, buf);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
733 payload = xstrcat(payload, (char *)"}");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
734 } else {
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
735 payload = xstrcat(payload, (char *)",\"chiller\":null");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
736 }
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
737
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
738 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
739 * Heater control, power 0..100% and usage count.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
740 */
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
741 if (unit->heater_address) {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
742 payload = xstrcat(payload, (char *)",\"heater\":{\"address\":\"");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
743 payload = xstrcat(payload, unit->heater_address);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
744 payload = xstrcat(payload, (char *)"\",\"state\":");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
745 sprintf(buf, "%d", unit->heater_state);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
746 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
747 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
748 sprintf(buf, "%d", unit->heater_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
749 payload = xstrcat(payload, buf);
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
750 payload = xstrcat(payload, (char *)"}");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
751 } else {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
752 payload = xstrcat(payload, (char *)",\"heater\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
753 }
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
754
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
755 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
756 * Cooler control, power 0..100% and usage counter.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
757 */
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
758 if (unit->cooler_address) {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
759 payload = xstrcat(payload, (char *)",\"cooler\":{\"address\":\"");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
760 payload = xstrcat(payload, unit->cooler_address);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
761 payload = xstrcat(payload, (char *)"\",\"state\":");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
762 sprintf(buf, "%d", unit->cooler_state);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
763 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
764 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
765 sprintf(buf, "%d", unit->cooler_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
766 payload = xstrcat(payload, buf);
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
767 payload = xstrcat(payload, (char *)"}");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
768 } else {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
769 payload = xstrcat(payload, (char *)",\"cooler\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
770 }
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
771
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
772 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
773 * Fan control, 0..100% and usage counter.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
774 */
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
775 if (unit->fan_address) {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
776 payload = xstrcat(payload, (char *)",\"fan\":{\"address\":\"");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
777 payload = xstrcat(payload, unit->fan_address);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
778 payload = xstrcat(payload, (char *)"\",\"state\":");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
779 sprintf(buf, "%d", unit->fan_state);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
780 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
781 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
782 sprintf(buf, "%d", unit->fan_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
783 payload = xstrcat(payload, buf);
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
784 payload = xstrcat(payload, (char *)"}");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
785 } else {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
786 payload = xstrcat(payload, (char *)",\"fan\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
787 }
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
788
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
789 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
790 * Interior lights control, 0..100% and usage counter.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
791 */
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
792 if (unit->light_address) {
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
793 payload = xstrcat(payload, (char *)",\"light\":{\"address\":\"");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
794 payload = xstrcat(payload, unit->light_address);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
795 payload = xstrcat(payload, (char *)"\",\"state\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
796 sprintf(buf, "%d", unit->light_state);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
797 payload = xstrcat(payload, buf);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
798 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
799 sprintf(buf, "%d", unit->light_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
800 payload = xstrcat(payload, buf);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
801 payload = xstrcat(payload, (char *)"}");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
802 } else {
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
803 payload = xstrcat(payload, (char *)",\"light\":null");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
804 }
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
805
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
806 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
807 * Door sensor.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
808 */
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
809 if (unit->door_address) {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
810 payload = xstrcat(payload, (char *)",\"door\":{\"address\":\"");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
811 payload = xstrcat(payload, unit->door_address);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
812 payload = xstrcat(payload, (char *)"\",\"state\":");
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
813 sprintf(buf, "%d", (unit->door_state) ? 0:1);
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
814 payload = xstrcat(payload, buf);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
815 payload = xstrcat(payload, (char *)"}");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
816 } else {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
817 payload = xstrcat(payload, (char *)",\"door\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
818 }
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
819
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
820 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
821 * PSU status
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
822 */
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
823 if (unit->psu_address) {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
824 payload = xstrcat(payload, (char *)",\"psu\":{\"address\":\"");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
825 payload = xstrcat(payload, unit->psu_address);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
826 payload = xstrcat(payload, (char *)"\",\"state\":");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
827 sprintf(buf, "%d", unit->psu_state);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
828 payload = xstrcat(payload, buf);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
829 payload = xstrcat(payload, (char *)"}");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
830 } else {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
831 payload = xstrcat(payload, (char *)",\"psu\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
832 }
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
833
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
834 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
835 * Working mode and setpoints
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
836 */
564
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
837 payload = xstrcat(payload, (char *)",\"stage\":\"");
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
838 payload = xstrcat(payload, (char *)UNITSTAGE[unit->stage]);
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
839 payload = xstrcat(payload, (char *)"\",\"mode\":\"");
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
840 payload = xstrcat(payload, (char *)UNITMODE[unit->mode]);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
841 payload = xstrcat(payload, (char *)"\",\"setpoint\":{\"low\":");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
842 sprintf(buf, "%.1f", unit->PID_heat->SetP);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
843 payload = xstrcat(payload, buf);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
844 payload = xstrcat(payload, (char *)",\"high\":");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
845 sprintf(buf, "%.1f", unit->PID_cool->SetP);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
846 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
847 payload = xstrcat(payload, (char *)"},\"alarm\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
848 sprintf(buf, "%d", unit->alarm_flag);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
849 payload = xstrcat(payload, buf);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
850
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
851 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
852 * Loaded profile and state
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
853 */
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
854 if (unit->profile_uuid) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
855 payload = xstrcat(payload, (char *)",\"profile\":{\"uuid\":\"");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
856 payload = xstrcat(payload, unit->profile_uuid);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
857 payload = xstrcat(payload, (char *)"\",\"name\":\"");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
858 payload = xstrcat(payload, unit->profile_name);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
859 payload = xstrcat(payload, (char *)"\",\"state\":\"");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
860 payload = xstrcat(payload, (char *)PROFSTATE[unit->prof_state]);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
861 payload = xstrcat(payload, (char *)"\",\"percent\":");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
862 sprintf(buf, "%d", unit->prof_percent);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
863 payload = xstrcat(payload, buf);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
864 payload = xstrcat(payload, (char *)",\"inittemp\":{\"low\":");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
865 sprintf(buf, "%.1f", unit->profile_inittemp_lo);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
866 payload = xstrcat(payload, buf);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
867 payload = xstrcat(payload, (char *)",\"high\":");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
868 sprintf(buf, "%.1f", unit->profile_inittemp_hi);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
869 payload = xstrcat(payload, buf);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
870 payload = xstrcat(payload, (char *)"},\"fridgemode\":");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
871 sprintf(buf, "%d", unit->profile_fridge_mode);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
872 payload = xstrcat(payload, buf);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
873 comma = false;
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
874 if (unit->profile_steps) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
875 payload = xstrcat(payload, (char *)",\"steps\":[");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
876 for (pstep = unit->profile_steps; pstep; pstep = pstep->next) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
877 if (comma)
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
878 payload = xstrcat(payload, (char *)",");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
879 payload = xstrcat(payload, (char *)"{\"resttime\":");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
880 sprintf(buf, "%d", pstep->resttime);
548
2924fe4911d9 Versie 0.8.1. Geen DDATA als fermenter uit staat. Profile JSON formaat is nu werkend.
Michiel Broek <mbroek@mbse.eu>
parents: 547
diff changeset
881 payload = xstrcat(payload, buf);
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
882 payload = xstrcat(payload, (char *)",\"steptime\":");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
883 sprintf(buf, "%d", pstep->steptime);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
884 payload = xstrcat(payload, buf);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
885 payload = xstrcat(payload, (char *)",\"target\":{\"low\":");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
886 sprintf(buf, "%.1f", pstep->target_lo);
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
887 payload = xstrcat(payload, buf);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
888 payload = xstrcat(payload, (char *)",\"high\":");
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
889 sprintf(buf, "%.1f", pstep->target_hi);
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
890 payload = xstrcat(payload, buf);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
891 payload = xstrcat(payload, (char *)"},\"fridgemode\":");
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
892 sprintf(buf, "%d", pstep->fridge_mode);
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
893 payload = xstrcat(payload, buf);
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
894 if (pstep->name) {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
895 payload = xstrcat(payload, (char *)",\"name\":\"");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
896 payload = xstrcat(payload, pstep->name);
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
897 payload = xstrcat(payload, (char *)"\"");
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
898 }
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
899 payload = xstrcat(payload, (char *)"}");
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
900 comma = true;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
901 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
902 payload = xstrcat(payload, (char *)"]");
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
903 } else {
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
904 payload = xstrcat(payload, (char *)",\"steps\":null");
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
905 }
570
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
906 payload = xstrcat(payload, (char *)"}");
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
907 } else {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
908 payload = xstrcat(payload, (char *)",\"profile\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
909 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
910 payload = xstrcat(payload, (char *)"}");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
911
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
912 return payload;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
913 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
914
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
915
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
916
533
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
917 /**
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
918 * @brief Publish DBIRTH for all active units. If there are no active units, don't
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
919 * publish anything. This function should be called at program start.
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
920 */
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
921 void publishDBirthAll(void)
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
922 {
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
923 char *topic = NULL, *payload = NULL, *payloadu = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
924 units_list *unit;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
925 int comma = FALSE;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
926
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
927 payload = payload_header();
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
928 payload = xstrcat(payload, (char *)"{\"units\":[");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
929 for (unit = Config.units; unit; unit = unit->next) {
533
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
930 if (unit->mode != UNITMODE_OFF) {
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
931 if (comma)
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
932 payload = xstrcat(payload, (char *)",");
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
933 payloadu = unit_data(unit, true);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
934 payload = xstrcat(payload, payloadu);
533
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
935 comma = TRUE;
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
936 free(payloadu);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
937 payloadu = NULL;
533
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
938 }
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
939 }
533
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
940 if (comma) { // Only publish if there is at least one unit active.
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
941 payload = xstrcat(payload, (char *)"]}}");
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
942 topic = topic_base((char *)"DBIRTH");
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
943 publisher(mosq, topic, payload, true);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
944 free(topic);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
945 topic = NULL;
533
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
946 }
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
947 free(payload);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
948 payload = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
949 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
950
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
951
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
952
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
953 void publishDData(units_list *unit)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
954 {
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
955 char *payload = NULL, *payloadu = NULL, *topic = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
956
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
957 if (mqtt_use) {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
958 payload = payload_header();
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
959 payloadu = unit_data(unit, false);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
960 payload = xstrcat(payload, payloadu);
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
961 payload = xstrcat(payload, (char *)"}");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
962 topic = xstrcat(topic_base((char *)"DDATA"), (char *)"/");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
963 topic = xstrcat(topic, unit->alias);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
964 publisher(mosq, topic, payload, false);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
965 free(payload);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
966 payload = NULL;
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
967 free(payloadu);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
968 payloadu = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
969 free(topic);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
970 topic = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
971 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
972 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
973
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
974
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
975
533
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
976 void publishDBirth(units_list *unit)
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
977 {
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
978 char *payload = NULL, *topic = NULL;
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
979
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
980 if (mqtt_use) {
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
981 payload = payload_header();
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
982 payload = xstrcat(payload, unit_data(unit, true));
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
983 payload = xstrcat(payload, (char *)"}");
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
984 topic = xstrcat(topic_base((char *)"DBIRTH"), (char *)"/");
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
985 topic = xstrcat(topic, unit->alias);
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
986 publisher(mosq, topic, payload, true);
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
987 free(payload);
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
988 payload = NULL;
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
989 free(topic);
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
990 topic = NULL;
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
991 }
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
992 }
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
993
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
994
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
995
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
996 void publishDDeath(units_list *unit)
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
997 {
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
998 char *topic = NULL;
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
999
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1000 if (mqtt_use) {
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1001 // First delete presistent DBIRTH topic
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1002 topic = xstrcat(topic_base((char *)"DBIRTH"), (char *)"/");
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1003 topic = xstrcat(topic, unit->alias);
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1004 publisher(mosq, topic, NULL, true);
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1005 free(topic);
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1006 topic = NULL;
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1007 topic = xstrcat(topic_base((char *)"DDEATH"), (char *)"/");
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1008 topic = xstrcat(topic, unit->alias);
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1009 publisher(mosq, topic, NULL, true);
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1010 free(topic);
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1011 topic = NULL;
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1012 }
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1013 }
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1014
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1015
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1016
554
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1017 void publishDLog(units_list *unit)
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1018 {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1019 char buf[32], *payload = NULL, *topic = NULL;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1020 bool comma = false;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1021
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1022 if (mqtt_use) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1023 payload = payload_header();
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1024 payload = xstrcat(payload, (char *)"{");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1025
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1026 if ((unit->product_name && strlen(unit->product_name)) ||
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1027 (unit->product_code && strlen(unit->product_code)) ||
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1028 (unit->product_uuid && strlen(unit->product_uuid))) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1029 comma = false;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1030 payload = xstrcat(payload, (char *)"\"product\":{");
564
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1031 if (unit->product_uuid && strlen(unit->product_uuid) && strcmp((char *)"(null)", unit->product_uuid)) {
554
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1032 payload = xstrcat(payload, (char *)"\"uuid\":\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1033 payload = xstrcat(payload, unit->product_uuid);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1034 payload = xstrcat(payload, (char *)"\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1035 comma = true;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1036 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1037 if (unit->product_code && strlen(unit->product_code)) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1038 if (comma)
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1039 payload = xstrcat(payload, (char *)",");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1040 payload = xstrcat(payload, (char *)"\"code\":\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1041 payload = xstrcat(payload, unit->product_code);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1042 payload = xstrcat(payload, (char *)"\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1043 comma = true;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1044 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1045 if (unit->product_name && strlen(unit->product_name)) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1046 if (comma)
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1047 payload = xstrcat(payload, (char *)",");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1048 payload = xstrcat(payload, (char *)"\"name\":\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1049 payload = xstrcat(payload, unit->product_name);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1050 payload = xstrcat(payload, (char *)"\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1051 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1052 payload = xstrcat(payload, (char *)"}");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1053 comma = true;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1054 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1055
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1056 if (comma)
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1057 payload = xstrcat(payload, (char *)",");
564
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1058 payload = xstrcat(payload, (char *)"\"stage\":\"");
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1059 payload = xstrcat(payload, (char *)UNITSTAGE[unit->stage]);
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1060 payload = xstrcat(payload, (char *)"\",\"mode\":\"");
554
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1061 payload = xstrcat(payload, (char *)UNITMODE[unit->mode]);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1062 payload = xstrcat(payload, (char *)"\",\"temperature\":{");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1063 comma = false;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1064 if (unit->air_address) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1065 payload = xstrcat(payload, (char *)"\"air\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1066 sprintf(buf, "%.3f", unit->air_temperature / 1000.0);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1067 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1068 comma = true;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1069 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1070 if (unit->beer_address) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1071 if (comma)
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1072 payload = xstrcat(payload, (char *)",");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1073 payload = xstrcat(payload, (char *)"\"beer\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1074 sprintf(buf, "%.3f", unit->beer_temperature / 1000.0);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1075 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1076 comma = true;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1077 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1078 if (unit->chiller_address) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1079 if (comma)
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1080 payload = xstrcat(payload, (char *)",");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1081 payload = xstrcat(payload, (char *)"\"chiller\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1082 sprintf(buf, "%.3f", unit->chiller_temperature / 1000.0);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1083 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1084 comma = true;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1085 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1086 if (Config.temp_address) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1087 if (comma)
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1088 payload = xstrcat(payload, (char *)",");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1089 payload = xstrcat(payload, (char *)"\"room\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1090 sprintf(buf, "%.1f", Config.temp_value / 1000.0);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1091 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1092 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1093 payload = xstrcat(payload, (char *)"},\"setpoint\":{\"low\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1094 sprintf(buf, "%.1f", unit->PID_heat->SetP);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1095 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1096 payload = xstrcat(payload, (char *)",\"high\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1097 sprintf(buf, "%.1f", unit->PID_cool->SetP);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1098 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1099 payload = xstrcat(payload, (char *)"}");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1100 if (unit->heater_address) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1101 payload = xstrcat(payload, (char *)",\"heater\":{\"power\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1102 sprintf(buf, "%d", unit->heater_state);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1103 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1104 payload = xstrcat(payload, (char *)",\"usage\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1105 sprintf(buf, "%d", unit->heater_usage);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1106 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1107 payload = xstrcat(payload, (char *)"}");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1108 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1109 if (unit->cooler_address) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1110 payload = xstrcat(payload, (char *)",\"cooler\":{\"power\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1111 sprintf(buf, "%d", unit->cooler_state);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1112 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1113 payload = xstrcat(payload, (char *)",\"usage\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1114 sprintf(buf, "%d", unit->cooler_usage);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1115 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1116 payload = xstrcat(payload, (char *)"}");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1117 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1118 if (unit->fan_address) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1119 payload = xstrcat(payload, (char *)",\"fan\":{\"power\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1120 sprintf(buf, "%d", unit->fan_state);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1121 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1122 payload = xstrcat(payload, (char *)",\"usage\":");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1123 sprintf(buf, "%d", unit->fan_usage);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1124 payload = xstrcat(payload, buf);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1125 payload = xstrcat(payload, (char *)"}");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1126 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1127 // sg
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1128 if (unit->event_msg) {
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1129 payload = xstrcat(payload, (char *)",\"event\":\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1130 payload = xstrcat(payload, unit->event_msg);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1131 payload = xstrcat(payload, (char *)"\"");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1132 }
555
c6f04bfcec2c Add fermenter uuid to the DLOG message
Michiel Broek <mbroek@mbse.eu>
parents: 554
diff changeset
1133 payload = xstrcat(payload, (char *)",\"fermenter_uuid\":\"");
c6f04bfcec2c Add fermenter uuid to the DLOG message
Michiel Broek <mbroek@mbse.eu>
parents: 554
diff changeset
1134 payload = xstrcat(payload, unit->uuid);
c6f04bfcec2c Add fermenter uuid to the DLOG message
Michiel Broek <mbroek@mbse.eu>
parents: 554
diff changeset
1135 payload = xstrcat(payload, (char *)"\"}}");
554
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1136
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1137 topic = xstrcat(topic_base((char *)"DLOG"), (char *)"/");
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1138 topic = xstrcat(topic, unit->alias);
577
7a29f835e20a DLOG messages are no longer retained.
Michiel Broek <mbroek@mbse.eu>
parents: 575
diff changeset
1139 publisher(mosq, topic, payload, false);
554
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1140 free(payload);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1141 payload = NULL;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1142 free(topic);
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1143 topic = NULL;
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1144 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1145 }
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1146
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1147
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1148
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1149 void publishNData(bool birth, int flag)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1150 {
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1151 char *topic = NULL, *payload = NULL, sidx[10], buf[64];
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1152 struct utsname ubuf;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1153 bool comma = false;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1154
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1155 payload = payload_header();
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1156 payload = xstrcat(payload, (char *)"{");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1157
540
5a26429abbf8 Versie 0.6.7. Globale uuid toegevoegd voor de NBIRTH payload.
Michiel Broek <mbroek@mbse.eu>
parents: 535
diff changeset
1158 if (birth) {
5a26429abbf8 Versie 0.6.7. Globale uuid toegevoegd voor de NBIRTH payload.
Michiel Broek <mbroek@mbse.eu>
parents: 535
diff changeset
1159 payload = xstrcat(payload, (char *)"\"uuid\":\"");
5a26429abbf8 Versie 0.6.7. Globale uuid toegevoegd voor de NBIRTH payload.
Michiel Broek <mbroek@mbse.eu>
parents: 535
diff changeset
1160 payload = xstrcat(payload, Config.uuid);
544
e2889b17f48c Versie 0.6.8. Code cleanup. Publish NDATA MQTT bericht iedere 5 minuten of als er een THB wijziging is.
Michiel Broek <mbroek@mbse.eu>
parents: 543
diff changeset
1161 payload = xstrcat(payload, (char *)"\",");
508
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1162 #ifdef HAVE_WIRINGPI_H
563
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1163 /*
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1164 * Get the info from the WiringPi libary
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1165 */
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1166 int model, rev, mem, maker, warranty;
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1167 piBoardId (&model, &rev, &mem, &maker, &warranty);
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1168 payload = xstrcat(payload, (char *)"\"properties\":{\"hardwaremake\":\"Raspberry Pi ");
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1169 payload = xstrcat(payload, (char *)piMakerNames[maker]);
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1170 payload = xstrcat(payload, (char *)"\",\"hardwaremodel\":\"");
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1171 payload = xstrcat(payload, (char *)piModelNames[model]);
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1172 payload = xstrcat(payload, (char *)" rev ");
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1173 payload = xstrcat(payload, (char *)piRevisionNames[rev]);
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1174 payload = xstrcat(payload, (char *)"\"");
508
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1175 #else
544
e2889b17f48c Versie 0.6.8. Code cleanup. Publish NDATA MQTT bericht iedere 5 minuten of als er een THB wijziging is.
Michiel Broek <mbroek@mbse.eu>
parents: 543
diff changeset
1176 if (uname(&ubuf) == 0) {
e2889b17f48c Versie 0.6.8. Code cleanup. Publish NDATA MQTT bericht iedere 5 minuten of als er een THB wijziging is.
Michiel Broek <mbroek@mbse.eu>
parents: 543
diff changeset
1177 payload = xstrcat(payload, (char *)"\"properties\":{\"hardwaremake\":\"");
e2889b17f48c Versie 0.6.8. Code cleanup. Publish NDATA MQTT bericht iedere 5 minuten of als er een THB wijziging is.
Michiel Broek <mbroek@mbse.eu>
parents: 543
diff changeset
1178 payload = xstrcat(payload, ubuf.machine);
e2889b17f48c Versie 0.6.8. Code cleanup. Publish NDATA MQTT bericht iedere 5 minuten of als er een THB wijziging is.
Michiel Broek <mbroek@mbse.eu>
parents: 543
diff changeset
1179 payload = xstrcat(payload, (char *)"\",\"hardwaremodel\":\"Unknown\"");
e2889b17f48c Versie 0.6.8. Code cleanup. Publish NDATA MQTT bericht iedere 5 minuten of als er een THB wijziging is.
Michiel Broek <mbroek@mbse.eu>
parents: 543
diff changeset
1180 } else {
e2889b17f48c Versie 0.6.8. Code cleanup. Publish NDATA MQTT bericht iedere 5 minuten of als er een THB wijziging is.
Michiel Broek <mbroek@mbse.eu>
parents: 543
diff changeset
1181 payload = xstrcat(payload, (char *)"\"properties\":{\"hardwaremake\":\"Unknown\",\"hardwaremodel\":\"Unknown\"");
e2889b17f48c Versie 0.6.8. Code cleanup. Publish NDATA MQTT bericht iedere 5 minuten of als er een THB wijziging is.
Michiel Broek <mbroek@mbse.eu>
parents: 543
diff changeset
1182 }
508
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1183 #endif
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1184 if (uname(&ubuf) == 0) {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1185 payload = xstrcat(payload, (char *)",\"os\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1186 payload = xstrcat(payload, ubuf.sysname);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1187 payload = xstrcat(payload, (char *)"\",\"os_version\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1188 payload = xstrcat(payload, ubuf.release);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1189 payload = xstrcat(payload, (char *)"\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1190 } else {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1191 payload = xstrcat(payload, (char *)",\"os\":\"Unknown\",\"os_version\":\"Unknown\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1192 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1193
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1194 payload = xstrcat(payload, (char *)",\"FW\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1195 payload = xstrcat(payload, (char *)VERSION);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1196 payload = xstrcat(payload, (char *)"\"}");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1197 comma = true;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1198 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1199
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1200 if (Config.temp_address || Config.hum_address) {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1201 if (comma)
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1202 payload = xstrcat(payload, (char *)",");
541
a5530abb16dd Fixed spelling error
Michiel Broek <mbroek@mbse.eu>
parents: 540
diff changeset
1203 payload = xstrcat(payload, (char *)"\"THB\":{");
510
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1204 if (Config.temp_address) {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1205 payload = xstrcat(payload, (char *)"\"temperature\":");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1206 sprintf(buf, "%.1f", Config.temp_value / 1000.0);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1207 payload = xstrcat(payload, buf);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1208 }
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1209 if (Config.temp_address && Config.hum_address)
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1210 payload = xstrcat(payload, (char *)",");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1211 if (Config.hum_address) {
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1212 payload = xstrcat(payload, (char *)"\"humidity\":");
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1213 sprintf(buf, "%.1f", Config.hum_value / 1000.0);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1214 payload = xstrcat(payload, buf);
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1215 }
2da3d3340403 Version 0.6.0. The MQTT data messages are now allways the same length so that openhab will function with the message updates.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
1216 payload = xstrcat(payload, (char *)"}");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1217 }
549
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1218
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1219 /*
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1220 * Find our network information
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1221 */
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1222 FILE *f;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1223 char line[100], *ifname, *c, ip[NI_MAXHOST];
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1224 struct ifaddrs *ifaddr, *ifa;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1225 int family, s;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1226
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1227 if (birth && (f = fopen("/proc/net/route" , "r"))) {
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1228 while (fgets(line, 100, f)) {
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1229 ifname = strtok(line , " \t");
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1230 c = strtok(NULL , " \t");
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1231
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1232 // Take the entry with destination '00000000'
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1233 if (ifname != NULL && c != NULL && (strcmp(c , "00000000") == 0)) {
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1234
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1235 if (getifaddrs(&ifaddr) == -1) {
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1236 syslog(LOG_NOTICE, "error getifaddrs error %d", errno);
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1237 goto neterr;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1238 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1239
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1240 //Walk through linked list, maintaining head pointer so we can free list later
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1241 for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1242 if (ifa->ifa_addr == NULL) {
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1243 continue;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1244 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1245
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1246 family = ifa->ifa_addr->sa_family;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1247
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1248 if ((strcmp( ifa->ifa_name, ifname) == 0) && (family == AF_INET)) {
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1249 s = getnameinfo(ifa->ifa_addr, (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), ip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1250 if (s != 0) {
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1251 syslog(LOG_NOTICE, "getnameinfo() error=%d for %s", errno, ifname);
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1252 goto neterr;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1253 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1254 payload = xstrcat(payload, (char *)",\"net\":{\"address\":\"");
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1255 payload = xstrcat(payload, ip);
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1256 payload = xstrcat(payload, (char *)"\",\"ifname\":\"");
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1257 payload = xstrcat(payload, ifname);
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1258 payload = xstrcat(payload, (char *)"\",\"rssi\":0}");
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1259 // TODO: get rssi if wlan interface.
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1260 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1261 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1262
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1263 freeifaddrs(ifaddr);
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1264 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1265 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1266 fclose(f);
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1267 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1268 neterr:
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1269
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1270 payload = xstrcat(payload, (char *)"}}");
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1271 if (birth) {
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1272 topic = topic_base((char *)"NBIRTH");
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1273 publisher(mosq, topic, payload, true);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1274 } else {
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1275 topic = topic_base((char *)"NDATA");
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1276 publisher(mosq, topic, payload, false);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1277 }
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1278 free(topic);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1279 topic = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1280 free(payload);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1281 payload = NULL;
513
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1282
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1283 if ((Config.temp_address || Config.hum_address) && Config.temp_hum_idx) {
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1284 sprintf(sidx, "%d", Config.temp_hum_idx);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1285 sprintf(buf, "%.1f;%.1f;0", Config.temp_value / 1000.0, Config.hum_value / 1000.0);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1286
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1287 payload = xstrcpy((char *)"{\"command\":\"udevice\",\"idx\":");
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1288 payload = xstrcat(payload, sidx);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1289 payload = xstrcat(payload, (char *)",\"nvalue\":0,\"svalue\":\"");
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1290 payload = xstrcat(payload, buf);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1291 payload = xstrcat(payload, (char *)"\"}");
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1292 publisher(mosq, (char *)"domoticz/in", payload, false);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1293 free(payload);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1294 payload = NULL;
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1295 }
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1296 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1297
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1298
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1299
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1300 void mqtt_connect(void)
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1301 {
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1302 char *id = NULL, *topic;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1303 char err[1024];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1304 int rc;
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1305
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1306 /*
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1307 * Initialize mosquitto communication
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1308 */
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1309 gethostname(my_hostname, 255);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1310 mosquitto_lib_init();
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1311 id = xstrcpy((char *)"thermferm/");
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1312 id = xstrcat(id, my_hostname);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1313 if (strlen(id) > MOSQ_MQTT_ID_MAX_LENGTH) {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1314 /*
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1315 * Enforce maximum client id length of 23 characters
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1316 */
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1317 id[MOSQ_MQTT_ID_MAX_LENGTH] = '\0';
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1318 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1319
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1320 mosq = mosquitto_new(id, TRUE, NULL);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1321 if (!mosq) {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1322 switch(errno) {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1323 case ENOMEM:
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1324 syslog(LOG_NOTICE, "MQTT: mosquitto_new: Out of memory");
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1325 break;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1326 case EINVAL:
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1327 syslog(LOG_NOTICE, "MQTT: mosquitto_new: Invalid id");
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1328 break;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1329 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1330 mosquitto_lib_cleanup();
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1331 return;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1332 }
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1333 free(id);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1334 id = NULL;
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1335
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1336 /*
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1337 * Set our will
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1338 */
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1339 topic = topic_base((char *)"NDEATH");
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1340 if ((rc = mosquitto_will_set(mosq, topic, 0, NULL, mqtt_qos, false))) {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1341 if (rc > MOSQ_ERR_SUCCESS)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1342 syslog(LOG_NOTICE, "MQTT: mosquitto_will_set: %s", mosquitto_strerror(rc));
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1343 mosquitto_lib_cleanup();
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1344 return;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1345 }
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1346 free(topic);
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1347
509
b5ae9017194f Turn off MQTT debug
Michiel Broek <mbroek@mbse.eu>
parents: 508
diff changeset
1348 if (debug)
b5ae9017194f Turn off MQTT debug
Michiel Broek <mbroek@mbse.eu>
parents: 508
diff changeset
1349 mosquitto_log_callback_set(mosq, my_log_callback);
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1350 mosquitto_max_inflight_messages_set(mosq, max_inflight);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1351 mosquitto_connect_callback_set(mosq, my_connect_callback);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1352 mosquitto_disconnect_callback_set(mosq, my_disconnect_callback);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1353 mosquitto_publish_callback_set(mosq, my_publish_callback);
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1354 mosquitto_message_callback_set(mosq, my_message_callback);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1355 mosquitto_subscribe_callback_set(mosq, my_subscribe_callback);
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1356
500
5aa914eb644e Units now have an unique alias name so that the MQTT messages are more friendly.
Michiel Broek <mbroek@mbse.eu>
parents: 499
diff changeset
1357 if ((rc = mosquitto_connect(mosq, Config.mqtt_host, Config.mqtt_port, keepalive))) {
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1358 if (rc == MOSQ_ERR_ERRNO) {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1359 strerror_r(errno, err, 1024);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1360 syslog(LOG_NOTICE, "MQTT: mosquitto_connect: error: %s", err);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1361 } else {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1362 syslog(LOG_NOTICE, "MQTT: mosquitto_connect: unable to connect (%d)", rc);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1363 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1364 mosquitto_lib_cleanup();
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1365 syslog(LOG_NOTICE, "MQTT: will run without an MQTT broker.");
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1366 } else {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1367 mqtt_use = TRUE;
500
5aa914eb644e Units now have an unique alias name so that the MQTT messages are more friendly.
Michiel Broek <mbroek@mbse.eu>
parents: 499
diff changeset
1368 syslog(LOG_NOTICE, "MQTT: connected with %s:%d", Config.mqtt_host, Config.mqtt_port);
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1369
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1370 /*
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1371 * Initialise is complete, report our presence state
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1372 */
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1373 mosquitto_loop_start(mosq);
533
49580ca85ab7 Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.
Michiel Broek <mbroek@mbse.eu>
parents: 518
diff changeset
1374 publishNData(true, 0);
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1375 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1376 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1377
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1378
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1379
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1380 void mqtt_disconnect(void)
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1381 {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1382 int rc;
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1383 char *topic;
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1384
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1385 if (mqtt_use) {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1386 /*
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1387 * Final publish 0 to clients/<hostname>/thermferm/state
504
862de87f9f89 Added some MQTT publish clear functions. Version 0.5.8
Michiel Broek <mbroek@mbse.eu>
parents: 500
diff changeset
1388 * After that, remove the retained topic.
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1389 */
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1390 syslog(LOG_NOTICE, "MQTT disconnecting");
561
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1391 topic = topic_base((char *)"DBIRTH");
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1392 publisher(mosq, topic, NULL, true); // Not always needed, but ...
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1393 free(topic);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1394 topic = topic_base((char *)"DDEATH");
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1395 publisher(mosq, topic, NULL, true);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1396 free(topic);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1397 topic = topic_base((char *)"NBIRTH");
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1398 publisher(mosq, topic, NULL, true);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1399 free(topic);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1400 topic = topic_base((char *)"NDEATH");
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1401 publisher(mosq, topic, NULL, true);
fcfc3dbe85fa Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents: 557
diff changeset
1402 free(topic);
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1403 mqtt_last_mid = mqtt_mid_sent;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1404 mqtt_status = STATUS_WAITING;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1405 mqtt_my_shutdown = TRUE;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1406
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1407 do {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1408 if (mqtt_status == STATUS_WAITING) {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1409 if (mqtt_last_mid_sent == mqtt_last_mid && mqtt_disconnect_sent == FALSE) {
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1410 mosquitto_disconnect(mosq);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1411 mqtt_disconnect_sent = TRUE;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1412 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1413 usleep(100000);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1414 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1415 rc = MOSQ_ERR_SUCCESS;
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1416 } while (rc == MOSQ_ERR_SUCCESS && mqtt_connected);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1417
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1418 mosquitto_loop_stop(mosq, FALSE);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1419 mosquitto_destroy(mosq);
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1420 mosquitto_lib_cleanup();
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1421 mqtt_use = FALSE;
534
92b546d4a839 Versie 0.6.4. Aan de global setup de MQTT instellingen toegevoegd. Die zijn er ook als MQTT niet op het systeem aanwezig is. Indien het de global setup wijzigd, wordt de MQTT verbinding opnieuw gemaakt.
Michiel Broek <mbroek@mbse.eu>
parents: 533
diff changeset
1422 mqtt_status = STATUS_CONNECTING;
92b546d4a839 Versie 0.6.4. Aan de global setup de MQTT instellingen toegevoegd. Die zijn er ook als MQTT niet op het systeem aanwezig is. Indien het de global setup wijzigd, wordt de MQTT verbinding opnieuw gemaakt.
Michiel Broek <mbroek@mbse.eu>
parents: 533
diff changeset
1423 mqtt_mid_sent = 0;
92b546d4a839 Versie 0.6.4. Aan de global setup de MQTT instellingen toegevoegd. Die zijn er ook als MQTT niet op het systeem aanwezig is. Indien het de global setup wijzigd, wordt de MQTT verbinding opnieuw gemaakt.
Michiel Broek <mbroek@mbse.eu>
parents: 533
diff changeset
1424 mqtt_last_mid = -1;
92b546d4a839 Versie 0.6.4. Aan de global setup de MQTT instellingen toegevoegd. Die zijn er ook als MQTT niet op het systeem aanwezig is. Indien het de global setup wijzigd, wordt de MQTT verbinding opnieuw gemaakt.
Michiel Broek <mbroek@mbse.eu>
parents: 533
diff changeset
1425 mqtt_last_mid_sent = -1;
92b546d4a839 Versie 0.6.4. Aan de global setup de MQTT instellingen toegevoegd. Die zijn er ook als MQTT niet op het systeem aanwezig is. Indien het de global setup wijzigd, wordt de MQTT verbinding opnieuw gemaakt.
Michiel Broek <mbroek@mbse.eu>
parents: 533
diff changeset
1426 mqtt_connected = TRUE;
92b546d4a839 Versie 0.6.4. Aan de global setup de MQTT instellingen toegevoegd. Die zijn er ook als MQTT niet op het systeem aanwezig is. Indien het de global setup wijzigd, wordt de MQTT verbinding opnieuw gemaakt.
Michiel Broek <mbroek@mbse.eu>
parents: 533
diff changeset
1427 mqtt_disconnect_sent = FALSE;
92b546d4a839 Versie 0.6.4. Aan de global setup de MQTT instellingen toegevoegd. Die zijn er ook als MQTT niet op het systeem aanwezig is. Indien het de global setup wijzigd, wordt de MQTT verbinding opnieuw gemaakt.
Michiel Broek <mbroek@mbse.eu>
parents: 533
diff changeset
1428 mqtt_connect_lost = FALSE;
92b546d4a839 Versie 0.6.4. Aan de global setup de MQTT instellingen toegevoegd. Die zijn er ook als MQTT niet op het systeem aanwezig is. Indien het de global setup wijzigd, wordt de MQTT verbinding opnieuw gemaakt.
Michiel Broek <mbroek@mbse.eu>
parents: 533
diff changeset
1429 mqtt_my_shutdown = FALSE;
499
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1430 syslog(LOG_NOTICE, "MQTT disconnected");
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1431 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1432 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1433
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1434

mercurial