thermferm/mqtt.c

Sun, 07 Jul 2019 14:28:37 +0200

author
Chiel Broek <mbse@mbse.eu>
date
Sun, 07 Jul 2019 14:28:37 +0200
changeset 602
ca795b871158
parent 598
363dc36d2450
child 606
798dd0c4fd00
permissions
-rw-r--r--

Fix for non Pi hardware and virtual Pi's.

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 "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
26 #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
27 #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
28
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 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
30 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
31 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
32 extern int my_reboot;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
33 extern const char UNITMODE[5][8];
566
776a605befa5 Added Carbonation stage.
Michiel Broek <mbroek@mbse.eu>
parents: 564
diff changeset
34 extern const char UNITSTAGE[4][12];
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
35 extern const char PROFSTATE[5][6];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
36 extern const char TEMPSTATE[3][8];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
37
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
38 int Sequence = 0;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
39
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
40
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 /* 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
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59
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
598
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
61 #ifndef HAVE_WIRINGPI_H
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
62
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
63 /*
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
64 * Code from wiringPi written by Gordon Henderson.
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
65 * Copied here to have some sort of hardware detection without wiringPi.
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
66 */
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
67 const char *piModelNames [20] =
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
68 {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
69 "Model A", // 0
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
70 "Model B", // 1
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
71 "Model A+", // 2
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
72 "Model B+", // 3
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
73 "Pi 2", // 4
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
74 "Alpha", // 5
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
75 "CM", // 6
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
76 "Unknown07", // 07
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
77 "Pi 3", // 08
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
78 "Pi Zero", // 09
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
79 "CM3", // 10
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
80 "Unknown11", // 11
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
81 "Pi Zero-W", // 12
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
82 "Pi 3B+", // 13
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
83 "Pi 3A+", // 14
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
84 "Unknown15", // 15
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
85 "CM3+", // 16
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
86 "Unknown17", // 17
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
87 "Unknown18", // 18
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
88 "Unknown19", // 19
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
89 };
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
90 const char *piRevisionNames [16] =
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
91 {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
92 "00",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
93 "01",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
94 "02",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
95 "03",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
96 "04",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
97 "05",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
98 "06",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
99 "07",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
100 "08",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
101 "09",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
102 "10",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
103 "11",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
104 "12",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
105 "13",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
106 "14",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
107 "15",
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
108 } ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
109 const char *piMakerNames [16] =
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
110 {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
111 "Sony", // 0
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
112 "Egoman", // 1
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
113 "Embest", // 2
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
114 "Unknown", // 3
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
115 "Embest", // 4
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
116 "Unknown05", // 5
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
117 "Unknown06", // 6
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
118 "Unknown07", // 7
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
119 "Unknown08", // 8
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
120 "Unknown09", // 9
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
121 "Unknown10", // 10
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
122 "Unknown11", // 11
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
123 "Unknown12", // 12
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
124 "Unknown13", // 13
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
125 "Unknown14", // 14
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
126 "Unknown15", // 15
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
127 } ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
128 const int piMemorySize [8] =
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
129 {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
130 256, // 0
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
131 512, // 1
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
132 1024, // 2
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
133 0, // 3
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
134 0, // 4
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
135 0, // 5
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
136 0, // 6
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
137 0, // 7
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
138 } ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
139
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
140 void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
141 {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
142 FILE *cpuFd ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
143 char line [120] ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
144 char *c ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
145 unsigned int revision ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
146 int bRev, bType, bProc, bMfg, bMem, bWarranty ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
147
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
148 *model = -1; // Mark no info
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
149 if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL) {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
150 syslog(LOG_NOTICE, "Unable to open /proc/cpuinfo") ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
151 return;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
152 }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
153
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
154 while (fgets (line, 120, cpuFd) != NULL)
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
155 if (strncmp (line, "Revision", 8) == 0)
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
156 break ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
157
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
158 fclose (cpuFd) ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
159
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
160 if (strncmp (line, "Revision", 8) != 0) {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
161 syslog(LOG_NOTICE, "No \"Revision\" line");
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
162 return;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
163 }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
164
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
165 // Chomp trailing CR/NL
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
166
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
167 for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
168 *c = 0 ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
169
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
170 if (debug)
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
171 fprintf(stdout, "piBoardId: Revision string: %s\n", line) ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
172
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
173 // Need to work out if it's using the new or old encoding scheme:
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
174
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
175 // Scan to the first character of the revision number
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
176
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
177 for (c = line ; *c ; ++c)
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
178 if (*c == ':')
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
179 break ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
180
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
181 if (*c != ':') {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
182 syslog(LOG_NOTICE, "Bogus \"Revision\" line (no colon)") ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
183 return;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
184 }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
185
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
186 // Chomp spaces
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
187
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
188 ++c ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
189 while (isspace (*c))
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
190 ++c ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
191
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
192 if (!isxdigit (*c))
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
193 syslog(LOG_NOTICE, "Bogus \"Revision\" line (no hex digit at start of revision)") ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
194
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
195 revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
196
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
197 // Check for new way:
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
198
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
199 if ((revision & (1 << 23)) != 0) { // New way
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
200 if (debug)
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
201 fprintf(stdout, "piBoardId: New Way: revision is: %08X\n", revision) ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
202
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
203 bRev = (revision & (0x0F << 0)) >> 0 ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
204 bType = (revision & (0xFF << 4)) >> 4 ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
205 bProc = (revision & (0x0F << 12)) >> 12 ; // Not used for now.
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
206 bMfg = (revision & (0x0F << 16)) >> 16 ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
207 bMem = (revision & (0x07 << 20)) >> 20 ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
208 bWarranty = (revision & (0x03 << 24)) != 0 ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
209
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
210 *model = bType ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
211 *rev = bRev ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
212 *mem = bMem ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
213 *maker = bMfg ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
214 *warranty = bWarranty ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
215
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
216 if (debug)
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
217 fprintf(stdout, "piBoardId: rev: %d, type: %d, proc: %d, mfg: %d, mem: %d, warranty: %d\n", bRev, bType, bProc, bMfg, bMem, bWarranty) ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
218 } else { // Old way
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
219 if (debug)
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
220 fprintf(stdout, "piBoardId: Old Way: revision is: %s\n", c) ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
221
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
222 if (!isdigit (*c)) {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
223 syslog(LOG_NOTICE, "Bogus \"Revision\" line (no digit at start of revision)") ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
224 return;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
225 }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
226
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
227 // Make sure its long enough
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
228
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
229 if (strlen (c) < 4) {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
230 syslog(LOG_NOTICE, "Bogus \"Revision\" line (not long enough)") ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
231 return;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
232 }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
233
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
234 // If longer than 4, we'll assume it's been overvolted
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
235
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
236 *warranty = strlen (c) > 4 ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
237
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
238 // Extract last 4 characters:
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
239
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
240 c = c + strlen (c) - 4 ;
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
241
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
242 // Fill out the replys as appropriate
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
243
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
244 /**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
245 else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
246
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
247 else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
248 else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
249 else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
250
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
251 else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
252 else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
253 else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
254
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
255 else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
256 else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
257 else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
258
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
259 else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
260 else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_EMBEST ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
261 else if (strcmp (c, "0016") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
262 else if (strcmp (c, "0019") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
263 else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_1 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
264 else if (strcmp (c, "0014") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_1 ; *mem = 1 ; *maker = PI_MAKER_EMBEST ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
265 else if (strcmp (c, "0017") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_1 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
266 else if (strcmp (c, "001a") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_1 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
267
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
268 else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_SONY ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
269 else if (strcmp (c, "0015") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 1 ; *maker = PI_MAKER_EMBEST ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
270 else if (strcmp (c, "0018") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_SONY ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
271 else if (strcmp (c, "001b") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
272
602
ca795b871158 Fix for non Pi hardware and virtual Pi's.
Chiel Broek <mbse@mbse.eu>
parents: 598
diff changeset
273 else { *model = -1 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
598
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
274 }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
275 }
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
276 #endif
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
277
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
278
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
279
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
280 char *payload_header(void)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
281 {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
282 char *tmp, buf[128];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
283
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
284 tmp = xstrcpy((char *)"{\"timestamp\":");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
285 sprintf(buf, "%ld", time(NULL));
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
286 tmp = xstrcat(tmp, buf);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
287 tmp = xstrcat(tmp, (char *)",\"seq\":");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
288 sprintf(buf, "%d", Sequence++);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
289 tmp = xstrcat(tmp, buf);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
290 tmp = xstrcat(tmp, (char *)",\"metric\":");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
291 return tmp;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
292 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
293
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
294
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
295
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
296 char *topic_base(char *msgtype)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
297 {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
298 char *tmp;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
299
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
300 tmp = xstrcpy((char *)"mbv1.0/fermenters/");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
301 tmp = xstrcat(tmp, msgtype);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
302 tmp = xstrcat(tmp, (char *)"/");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
303 tmp = xstrcat(tmp, my_hostname);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
304 return tmp;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
305 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
306
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
307
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
308
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
309 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
310 {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
311 char *topic = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
312
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
313 if (mqtt_connect_lost) {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
314 mqtt_connect_lost = FALSE;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
315 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
316 }
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
317
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
318 if (!result) {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
319 topic = topic_base((char *)"NCMD");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
320 topic = xstrcat(topic, (char *)"/#");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
321 mosquitto_subscribe(mosq, NULL, topic, 0);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
322 free(topic);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
323 topic = topic_base((char *)"DCMD");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
324 topic = xstrcat(topic, (char *)"/#");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
325 mosquitto_subscribe(mosq, NULL, topic, 0);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
326 free(topic);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
327 topic = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
328 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
329 } else {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
330 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
331 }
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
332 }
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
333
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
334
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
335
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
336 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
337 {
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
338 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
339 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
340 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
341 } 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
342 /*
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
343 * 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
344 */
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
345 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
346 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
347 }
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
348 }
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
349
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
350
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
351
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
352 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
353 {
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
354 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
355 }
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
356
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
357
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
358
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
359 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
360 {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
361 int i;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
362
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
363 syslog(LOG_NOTICE, "Subscribed (mid: %d): %d", mid, granted_qos[0]);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
364 for (i = 1; i < qos_count; i++) {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
365 syslog(LOG_NOTICE, " %d", granted_qos[i]);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
366 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
367 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
368
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
369
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
370
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
371 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
372 {
591
95cf33f8021f Removed writing local unit data logs
Michiel Broek <mbroek@mbse.eu>
parents: 582
diff changeset
373 // if (debug)
95cf33f8021f Removed writing local unit data logs
Michiel Broek <mbroek@mbse.eu>
parents: 582
diff changeset
374 // fprintf(stdout, "MQTT: %s\n", 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
375 }
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
376
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
377
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
378
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
379 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
380 {
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
381 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
382 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
383 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
384 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
385 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
386 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
387
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
388 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
389 /*
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
390 * 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
391 */
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
392 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
393 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
394 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
395 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
396 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
397
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
398 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
399 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
400 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
401 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
402 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
403 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
404 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
405 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
406 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
407 /*
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
408 * 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
409 * 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
410 */
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
411 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
412 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
413 }
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
414 }
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
415 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
416 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
417 /*
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
418 * 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
419 */
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
420 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
421 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
422 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
423 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
424 }
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
425 }
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
426
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 /*
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 * 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
429 */
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
430 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
431 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
432 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
433 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
434 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
435 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
436 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
437 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
438 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
439 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
440 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
441 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
442 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
443 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
444 }
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
445 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
446 }
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
447 }
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
448 }
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
449
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
450 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
451 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
452 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
453 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
454 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
455 /* 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
456 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
457 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
458 } 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
459 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
460 }
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
461 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
462 /* 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
463 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
464 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
465 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
466 }
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
467 }
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
468 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
469 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
470 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
471 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
472 /* 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
473 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
474 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
582
ba340e00aab2 Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.
Chiel Broek <mbse@mbse.eu>
parents: 579
diff changeset
475 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = unit->light_timer = 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
476 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
477 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
478 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
479 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
480 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
481 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
482 /*
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
483 * 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
484 * 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
485 */
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
486 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
487 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
488 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
489 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
490 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
491 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
492 }
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
493 }
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
494 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
495 }
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
496 }
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
497 }
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
498
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
499 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
500 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
501 /*
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
502 * 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
503 */
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
504 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
505 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
506 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
507 unit->PID_cool->SetP = json_object_get_double(val);
578
d694abd9d809 Version 0.9.3. Splitted the temperature low and high settings in fridge and beer mode.
Michiel Broek <mbroek@mbse.eu>
parents: 577
diff changeset
508 if (unit->mode == UNITMODE_FRIDGE) {
d694abd9d809 Version 0.9.3. Splitted the temperature low and high settings in fridge and beer mode.
Michiel Broek <mbroek@mbse.eu>
parents: 577
diff changeset
509 unit->fridge_set_lo = unit->PID_heat->SetP;
d694abd9d809 Version 0.9.3. Splitted the temperature low and high settings in fridge and beer mode.
Michiel Broek <mbroek@mbse.eu>
parents: 577
diff changeset
510 unit->fridge_set_hi = unit->PID_cool->SetP;
d694abd9d809 Version 0.9.3. Splitted the temperature low and high settings in fridge and beer mode.
Michiel Broek <mbroek@mbse.eu>
parents: 577
diff changeset
511 } else {
d694abd9d809 Version 0.9.3. Splitted the temperature low and high settings in fridge and beer mode.
Michiel Broek <mbroek@mbse.eu>
parents: 577
diff changeset
512 unit->beer_set_lo = unit->PID_heat->SetP;
d694abd9d809 Version 0.9.3. Splitted the temperature low and high settings in fridge and beer mode.
Michiel Broek <mbroek@mbse.eu>
parents: 577
diff changeset
513 unit->beer_set_hi = unit->PID_cool->SetP;
d694abd9d809 Version 0.9.3. Splitted the temperature low and high settings in fridge and beer mode.
Michiel Broek <mbroek@mbse.eu>
parents: 577
diff changeset
514 }
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
515 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
516 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
517 }
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
518 }
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
519
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
520 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
521 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
522 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
523 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
524 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
525 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
526 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
527 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
528 }
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
529 }
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
530 }
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
531
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
532 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
533 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
534 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
535 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
536 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
537 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
538 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
539 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
540 }
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
541 }
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
542 }
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
543
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
544 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
545 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
546 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
547 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
548 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
549 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
550 }
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 }
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 }
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
553
582
ba340e00aab2 Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.
Chiel Broek <mbse@mbse.eu>
parents: 579
diff changeset
554 if (json_object_object_get_ex(metric, "light", &setpoint)) {
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
555 if (json_object_object_get_ex(setpoint, "state", &val)) {
582
ba340e00aab2 Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.
Chiel Broek <mbse@mbse.eu>
parents: 579
diff changeset
556 if (json_object_get_int(val) > 0) {
ba340e00aab2 Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.
Chiel Broek <mbse@mbse.eu>
parents: 579
diff changeset
557 unit->light_timer = 300; // 5 minutes
ba340e00aab2 Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.
Chiel Broek <mbse@mbse.eu>
parents: 579
diff changeset
558 syslog(LOG_NOTICE, "DCMD set fermenter %s: light_timer 300", message_alias);
ba340e00aab2 Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.
Chiel Broek <mbse@mbse.eu>
parents: 579
diff changeset
559 if (!unit->light_state) {
ba340e00aab2 Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.
Chiel Broek <mbse@mbse.eu>
parents: 579
diff changeset
560 unit->light_state = 1;
ba340e00aab2 Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.
Chiel Broek <mbse@mbse.eu>
parents: 579
diff changeset
561 unit->mqtt_flag |= MQTT_FLAG_DATA;
ba340e00aab2 Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.
Chiel Broek <mbse@mbse.eu>
parents: 579
diff changeset
562 syslog(LOG_NOTICE, "DCMD change fermenter %s: light_state to %d", message_alias, unit->light_state);
ba340e00aab2 Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.
Chiel Broek <mbse@mbse.eu>
parents: 579
diff changeset
563 }
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
564 }
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
565 }
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
566 }
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
567
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
568 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
569 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
570 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
571 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
572 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
573 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
574 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
575 }
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
576 }
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
577 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
578 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
579 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
580 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
581 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
582 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
583 }
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
584 }
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
585 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
586 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
587 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
588 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
589 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
590 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
591 }
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
592 }
579
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
593 if (json_object_object_get_ex(setpoint, "yeast_lo", &val)) {
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
594 unit->yeast_lo = json_object_get_double(val);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
595 unit->mqtt_flag |= MQTT_FLAG_DATA;
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
596 syslog(LOG_NOTICE, "DCMD change fermenter %s: yeast_lo to `%.1f'", message_alias, unit->yeast_lo);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
597 }
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
598 if (json_object_object_get_ex(setpoint, "yeast_hi", &val)) {
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
599 unit->yeast_hi = json_object_get_double(val);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
600 unit->mqtt_flag |= MQTT_FLAG_DATA;
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
601 syslog(LOG_NOTICE, "DCMD change fermenter %s: yeast_lo to `%.1f'", message_alias, unit->yeast_hi);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
602 }
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
603 }
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
604
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
605 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
606 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
607 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
608 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
609 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
610 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
611 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
612 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
613 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
614 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
615 }
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
616 } 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
617 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
618 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
619 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
620 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
621 } 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
622 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
623 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
624 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
625 }
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
626 } 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
627 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
628 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
629 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
630 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
631 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
632 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
633 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
634 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
635 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
636 }
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
637 } 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
638 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
639 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
640 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
641 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
642 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
643 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
644 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
645 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
646 }
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
647 } 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
648 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
649 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
650 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
651 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
652 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
653 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
654 }
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
655 }
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
656 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
657 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
658 }
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
659 } 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
660 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
661 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
662 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
663 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
664 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
665 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
666 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
667 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
668 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
669 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
670 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
671 }
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
672 }
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
673 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
674 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
675 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
676 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
677 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
678 }
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
679 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
680 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
681 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
682 }
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
683 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
684 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
685 }
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
686 }
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
687 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
688 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
689 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
690 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
691 }
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
692 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
693 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
694 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
695 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
696 /*
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
697 * 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
698 */
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
699 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
700 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
701
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
702 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
703 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
704 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
705 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
706 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
707
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
708 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
709 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
710 }
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
711 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
712 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
713 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
714 }
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
715 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
716 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
717 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
718 }
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
719 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
720 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
721 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
722 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
723 }
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
724 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
725 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
726 }
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
727 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
728 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
729 }
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
730
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
731 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
732 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
733 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
734 } 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
735 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
736 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
737 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
738 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
739 }
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
740 }
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
741 }
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
742 }
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
743 }
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
744 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
745 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
746 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
747 }
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
748 } 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
749 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
750 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
751 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
752 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
753 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
754 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
755 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
756 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
757 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
758 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
759 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
760 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
761 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
762 }
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
763 }
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
764 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
765 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
766 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
767 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
768 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
769 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
770 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
771 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
772 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
773 }
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
774 }
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
775 }
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
776 }
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
777
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
778 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
779 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
780 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
781 } 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
782 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
783 }
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
784 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
785 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
786 }
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
787 }
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
788 }
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
789 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
790 }
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
791 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
792 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
793 }
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
794 } 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
795 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
796 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
797 }
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
798 }
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
799
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
800 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
801 } else {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
802 syslog(LOG_NOTICE, "MQTT: message callback %s (null)", message->topic);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
803 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
804 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
805
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
806
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
807
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
808 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
809 // publish the data
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
810 if (payload)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
811 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
812 else
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
813 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
814 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
815
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
816
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
817
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
818 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
819 char *dload = NULL;
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
820 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
821
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
822 if (idx == 0)
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
823 return;
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
824
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
825 sprintf(sidx, "%d", idx);
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
826 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
827
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
828 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
829 dload = xstrcat(dload, sidx);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
830 dload = xstrcat(dload, (char *)",\"nvalue\":0,\"svalue\":\"");
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
831 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
832 dload = xstrcat(dload, (char *)"\"}");
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
833 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
834 free(dload);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
835 dload = NULL;
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
836 }
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
837
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
838
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
839
514
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
840 void pub_domoticz_output(int idx, int value) {
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
841 char *dload = NULL;
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
842 char sidx[10], sval[10];
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
843
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
844 if (idx == 0)
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
845 return;
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
846
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
847 sprintf(sidx, "%d", idx);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
848 sprintf(sval, "%d", value);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
849
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
850 dload = xstrcpy((char *)"{\"command\":\"udevice\",\"idx\":");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
851 dload = xstrcat(dload, sidx);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
852 dload = xstrcat(dload, (char *)",\"nvalue\":");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
853 if (value >= 50)
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
854 dload = xstrcat(dload, (char *)"1");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
855 else
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
856 dload = xstrcat(dload, (char *)"0");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
857 dload = xstrcat(dload, (char *)",\"svalue\":\"");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
858 dload = xstrcat(dload, sval);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
859 dload = xstrcat(dload, (char *)"\"}");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
860 publisher(mosq, (char *)"domoticz/in", dload, false);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
861 free(dload);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
862 dload = NULL;
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
863 }
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
864
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
865
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
866
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
867 char *unit_data(units_list *unit, bool birth)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
868 {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
869 char *payload = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
870 char buf[128];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
871 bool comma = false;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
872 prof_step *pstep;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
873
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
874 payload = xstrcpy((char *)"{");
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
875
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
876 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
877 * Fixed unit values, never change these!
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
878 */
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
879 if (birth) {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
880 payload = xstrcat(payload, (char *)"\"uuid\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
881 payload = xstrcat(payload, unit->uuid);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
882 payload = xstrcat(payload, (char *)"\",\"alias\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
883 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
884 payload = xstrcat(payload, (char *)"\",");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
885 }
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
886
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
887 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
888 * Product (beer) loaded information.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
889 */
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
890 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
891 (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
892 (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
893 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
894 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
895 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
896 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
897 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
898 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
899 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
900 }
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
901 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
902 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
903 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
904 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
905 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
906 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
907 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
908 }
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
909 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
910 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
911 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
912 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
913 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
914 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
915 }
579
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
916 sprintf(buf, "%.1f", unit->yeast_lo);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
917 payload = xstrcat(payload, (char *)",\"yeast_lo\":");
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
918 payload = xstrcat(payload, buf);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
919 sprintf(buf, "%.1f", unit->yeast_hi);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
920 payload = xstrcat(payload, (char *)",\"yeast_hi\":");
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
921 payload = xstrcat(payload, buf);
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
922 payload = xstrcat(payload, (char *)"}");
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
923 }
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
924
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
925 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
926 * Air temperature sensor
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
927 */
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
928 if (unit->air_address) {
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
929 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
930 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
931 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
932 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
933 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
934 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
935 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
936 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
937 } else {
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
938 payload = xstrcat(payload, (char *)",\"air\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
939 }
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
940
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
941 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
942 * Beer temperature sensor
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
943 */
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
944 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
945 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
946 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
947 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
948 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
949 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
950 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
951 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
952 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
953 } 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
954 payload = xstrcat(payload, (char *)",\"beer\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
955 }
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
956
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
957 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
958 * External chiller temperature sensor
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
959 */
518
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
960 if (unit->chiller_address) {
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
961 payload = xstrcat(payload, (char *)",\"chiller\":{\"address\":\"");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
962 payload = xstrcat(payload, unit->chiller_address);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
963 payload = xstrcat(payload, (char *)"\",\"state\":\"");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
964 payload = xstrcat(payload, (char *)TEMPSTATE[unit->chiller_state]);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
965 payload = xstrcat(payload, (char *)"\",\"temperature\":");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
966 sprintf(buf, "%.3f", unit->chiller_temperature / 1000.0);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
967 payload = xstrcat(payload, buf);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
968 payload = xstrcat(payload, (char *)"}");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
969 } else {
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
970 payload = xstrcat(payload, (char *)",\"chiller\":null");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
971 }
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
972
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
973 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
974 * 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
975 */
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
976 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
977 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
978 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
979 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
980 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
981 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
982 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
983 sprintf(buf, "%d", unit->heater_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
984 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
985 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
986 } 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
987 payload = xstrcat(payload, (char *)",\"heater\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
988 }
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
989
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
990 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
991 * 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
992 */
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
993 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
994 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
995 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
996 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
997 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
998 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
999 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1000 sprintf(buf, "%d", unit->cooler_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1001 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
1002 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
1003 } 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
1004 payload = xstrcat(payload, (char *)",\"cooler\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1005 }
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
1006
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1007 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1008 * Fan control, 0..100% and usage counter.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1009 */
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
1010 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
1011 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
1012 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
1013 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
1014 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
1015 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1016 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1017 sprintf(buf, "%d", unit->fan_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1018 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
1019 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
1020 } 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
1021 payload = xstrcat(payload, (char *)",\"fan\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1022 }
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
1023
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1024 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1025 * 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
1026 */
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1027 if (unit->light_address) {
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1028 payload = xstrcat(payload, (char *)",\"light\":{\"address\":\"");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1029 payload = xstrcat(payload, unit->light_address);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1030 payload = xstrcat(payload, (char *)"\",\"state\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1031 sprintf(buf, "%d", unit->light_state);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1032 payload = xstrcat(payload, buf);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1033 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1034 sprintf(buf, "%d", unit->light_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1035 payload = xstrcat(payload, buf);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1036 payload = xstrcat(payload, (char *)"}");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1037 } else {
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1038 payload = xstrcat(payload, (char *)",\"light\":null");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1039 }
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1040
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1041 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1042 * Door sensor.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1043 */
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
1044 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
1045 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
1046 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
1047 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
1048 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
1049 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
1050 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
1051 } 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
1052 payload = xstrcat(payload, (char *)",\"door\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1053 }
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
1054
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1055 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1056 * PSU status
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1057 */
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
1058 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
1059 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
1060 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
1061 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
1062 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
1063 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
1064 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
1065 } 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
1066 payload = xstrcat(payload, (char *)",\"psu\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1067 }
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
1068
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1069 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1070 * Working mode and setpoints
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1071 */
564
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1072 payload = xstrcat(payload, (char *)",\"stage\":\"");
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1073 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
1074 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
1075 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
1076 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
1077 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
1078 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
1079 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
1080 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
1081 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1082 payload = xstrcat(payload, (char *)"},\"alarm\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1083 sprintf(buf, "%d", unit->alarm_flag);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1084 payload = xstrcat(payload, buf);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1085
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1086 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1087 * Loaded profile and state
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1088 */
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
1089 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
1090 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
1091 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
1092 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
1093 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
1094 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
1095 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
1096 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
1097 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
1098 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
1099 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
1100 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
1101 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
1102 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
1103 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
1104 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
1105 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
1106 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
1107 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
1108 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
1109 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
1110 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
1111 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
1112 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
1113 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
1114 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
1115 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
1116 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
1117 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
1118 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
1119 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
1120 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
1121 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
1122 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
1123 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
1124 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
1125 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
1126 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
1127 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
1128 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
1129 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
1130 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
1131 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
1132 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
1133 }
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
1134 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
1135 comma = true;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1136 }
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
1137 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
1138 } 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
1139 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
1140 }
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
1141 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
1142 } 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
1143 payload = xstrcat(payload, (char *)",\"profile\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1144 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1145 payload = xstrcat(payload, (char *)"}");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1146
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1147 return payload;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1148 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1149
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1150
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1151
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
1152 /**
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
1153 * @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
1154 * 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
1155 */
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
1156 void publishDBirthAll(void)
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1157 {
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
1158 char *topic = NULL, *payload = NULL, *payloadu = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1159 units_list *unit;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1160 int comma = FALSE;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1161
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1162 payload = payload_header();
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1163 payload = xstrcat(payload, (char *)"{\"units\":[");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1164 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
1165 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
1166 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
1167 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
1168 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
1169 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
1170 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
1171 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
1172 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
1173 }
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1174 }
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
1175 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
1176 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
1177 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
1178 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
1179 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
1180 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
1181 }
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1182 free(payload);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1183 payload = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1184 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1185
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
1186
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
1187
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1188 void publishDData(units_list *unit)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1189 {
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
1190 char *payload = NULL, *payloadu = NULL, *topic = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1191
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1192 if (mqtt_use) {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1193 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
1194 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
1195 payload = xstrcat(payload, payloadu);
506
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 topic = xstrcat(topic_base((char *)"DDATA"), (char *)"/");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1198 topic = xstrcat(topic, unit->alias);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1199 publisher(mosq, topic, payload, false);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1200 free(payload);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1201 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
1202 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
1203 payloadu = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1204 free(topic);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1205 topic = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1206 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1207 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1208
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1209
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1210
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
1211 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
1212 {
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
1213 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
1214
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
1215 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
1216 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
1217 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
1218 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
1219 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
1220 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
1221 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
1222 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
1223 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
1224 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
1225 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
1226 }
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
1227 }
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
1228
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
1229
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
1230
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
1231 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
1232 {
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
1233 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
1234
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
1235 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
1236 // 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
1237 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
1238 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
1239 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
1240 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
1241 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
1242 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
1243 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
1244 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
1245 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
1246 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
1247 }
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
1248 }
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
1249
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
1250
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
1251
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
1252 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
1253 {
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
1254 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
1255 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
1256
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
1257 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
1258 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
1259 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
1260
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
1261 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
1262 (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
1263 (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
1264 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
1265 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
1266 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
1267 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
1268 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
1269 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
1270 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
1271 }
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
1272 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
1273 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
1274 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
1275 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
1276 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
1277 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
1278 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
1279 }
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
1280 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
1281 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
1282 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
1283 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
1284 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
1285 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
1286 }
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
1287 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
1288 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
1289 }
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
1290
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
1291 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
1292 payload = xstrcat(payload, (char *)",");
564
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1293 payload = xstrcat(payload, (char *)"\"stage\":\"");
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1294 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
1295 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
1296 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
1297 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
1298 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
1299 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
1300 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
1301 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
1302 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
1303 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
1304 }
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
1305 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
1306 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
1307 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
1308 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
1309 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
1310 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
1311 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
1312 }
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
1313 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
1314 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
1315 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
1316 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
1317 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
1318 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
1319 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
1320 }
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
1321 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
1322 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
1323 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
1324 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
1325 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
1326 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
1327 }
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
1328 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
1329 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
1330 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
1331 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
1332 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
1333 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
1334 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
1335 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
1336 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
1337 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
1338 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
1339 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
1340 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
1341 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
1342 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
1343 }
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
1344 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
1345 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
1346 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
1347 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
1348 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
1349 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
1350 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
1351 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
1352 }
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
1353 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
1354 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
1355 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
1356 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
1357 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
1358 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
1359 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
1360 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
1361 }
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
1362 // 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
1363 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
1364 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
1365 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
1366 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
1367 }
555
c6f04bfcec2c Add fermenter uuid to the DLOG message
Michiel Broek <mbroek@mbse.eu>
parents: 554
diff changeset
1368 payload = xstrcat(payload, (char *)",\"fermenter_uuid\":\"");
c6f04bfcec2c Add fermenter uuid to the DLOG message
Michiel Broek <mbroek@mbse.eu>
parents: 554
diff changeset
1369 payload = xstrcat(payload, unit->uuid);
c6f04bfcec2c Add fermenter uuid to the DLOG message
Michiel Broek <mbroek@mbse.eu>
parents: 554
diff changeset
1370 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
1371
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
1372 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
1373 topic = xstrcat(topic, unit->alias);
577
7a29f835e20a DLOG messages are no longer retained.
Michiel Broek <mbroek@mbse.eu>
parents: 575
diff changeset
1374 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
1375 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
1376 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
1377 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
1378 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
1379 }
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
1380 }
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
1381
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
1382
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
1383
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1384 void publishNData(bool birth, int flag)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1385 {
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
1386 char *topic = NULL, *payload = NULL, sidx[10], buf[64];
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1387 struct utsname ubuf;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1388 bool comma = false;
598
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1389 int model, rev, mem, maker, warranty;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1390
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1391 payload = payload_header();
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1392 payload = xstrcat(payload, (char *)"{");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1393
540
5a26429abbf8 Versie 0.6.7. Globale uuid toegevoegd voor de NBIRTH payload.
Michiel Broek <mbroek@mbse.eu>
parents: 535
diff changeset
1394 if (birth) {
5a26429abbf8 Versie 0.6.7. Globale uuid toegevoegd voor de NBIRTH payload.
Michiel Broek <mbroek@mbse.eu>
parents: 535
diff changeset
1395 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
1396 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
1397 payload = xstrcat(payload, (char *)"\",");
508
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1398 #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
1399 /*
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1400 * 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
1401 */
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1402 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
1403 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
1404 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
1405 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
1406 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
1407 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
1408 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
1409 payload = xstrcat(payload, (char *)"\"");
508
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1410 #else
598
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1411 /*
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1412 * Get the info from the internal function
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1413 */
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1414 piBoardId (&model, &rev, &mem, &maker, &warranty);
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1415 if (model != -1) {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1416 payload = xstrcat(payload, (char *)"\"properties\":{\"hardwaremake\":\"Raspberry Pi ");
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1417 payload = xstrcat(payload, (char *)piMakerNames[maker]);
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1418 payload = xstrcat(payload, (char *)"\",\"hardwaremodel\":\"");
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1419 payload = xstrcat(payload, (char *)piModelNames[model]);
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1420 payload = xstrcat(payload, (char *)" rev ");
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1421 payload = xstrcat(payload, (char *)piRevisionNames[rev]);
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1422 payload = xstrcat(payload, (char *)"\"");
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1423 } else if (uname(&ubuf) == 0) {
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
1424 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
1425 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
1426 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
1427 } 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
1428 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
1429 }
508
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1430 #endif
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1431 if (uname(&ubuf) == 0) {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1432 payload = xstrcat(payload, (char *)",\"os\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1433 payload = xstrcat(payload, ubuf.sysname);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1434 payload = xstrcat(payload, (char *)"\",\"os_version\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1435 payload = xstrcat(payload, ubuf.release);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1436 payload = xstrcat(payload, (char *)"\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1437 } else {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1438 payload = xstrcat(payload, (char *)",\"os\":\"Unknown\",\"os_version\":\"Unknown\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1439 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1440
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1441 payload = xstrcat(payload, (char *)",\"FW\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1442 payload = xstrcat(payload, (char *)VERSION);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1443 payload = xstrcat(payload, (char *)"\"}");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1444 comma = true;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1445 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1446
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
1447 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
1448 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
1449 payload = xstrcat(payload, (char *)",");
541
a5530abb16dd Fixed spelling error
Michiel Broek <mbroek@mbse.eu>
parents: 540
diff changeset
1450 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
1451 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
1452 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
1453 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
1454 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
1455 }
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
1456 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
1457 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
1458 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
1459 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
1460 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
1461 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
1462 }
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
1463 payload = xstrcat(payload, (char *)"}");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1464 }
549
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1465
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1466 /*
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1467 * 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
1468 */
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1469 FILE *f;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1470 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
1471 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
1472 int family, s;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1473
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1474 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
1475 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
1476 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
1477 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
1478
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1479 // 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
1480 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
1481
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1482 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
1483 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
1484 goto neterr;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1485 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1486
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1487 //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
1488 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
1489 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
1490 continue;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1491 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1492
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1493 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
1494
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1495 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
1496 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
1497 if (s != 0) {
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1498 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
1499 goto neterr;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1500 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1501 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
1502 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
1503 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
1504 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
1505 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
1506 // 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
1507 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1508 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1509
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1510 freeifaddrs(ifaddr);
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1511 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1512 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1513 fclose(f);
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1514 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1515 neterr:
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1516
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1517 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
1518 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
1519 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
1520 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
1521 } 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
1522 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
1523 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
1524 }
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
1525 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
1526 topic = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1527 free(payload);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1528 payload = NULL;
513
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1529
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1530 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
1531 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
1532 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
1533
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1534 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
1535 payload = xstrcat(payload, sidx);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1536 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
1537 payload = xstrcat(payload, buf);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1538 payload = xstrcat(payload, (char *)"\"}");
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1539 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
1540 free(payload);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1541 payload = NULL;
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1542 }
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1543 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1544
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1545
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1546
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
1547 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
1548 {
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
1549 char *id = NULL, *topic;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1550 char err[1024];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1551 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
1552
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
1553 /*
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
1554 * 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
1555 */
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
1556 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
1557 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
1558 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
1559 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
1560 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
1561 /*
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
1562 * 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
1563 */
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
1564 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
1565 }
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
1566
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
1567 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
1568 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
1569 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
1570 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
1571 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
1572 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
1573 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
1574 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
1575 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
1576 }
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
1577 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
1578 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
1579 }
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
1580 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
1581 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
1582
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
1583 /*
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
1584 * 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
1585 */
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
1586 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
1587 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
1588 if (rc > MOSQ_ERR_SUCCESS)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1589 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
1590 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
1591 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
1592 }
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
1593 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
1594
509
b5ae9017194f Turn off MQTT debug
Michiel Broek <mbroek@mbse.eu>
parents: 508
diff changeset
1595 if (debug)
b5ae9017194f Turn off MQTT debug
Michiel Broek <mbroek@mbse.eu>
parents: 508
diff changeset
1596 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
1597 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
1598 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
1599 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
1600 mosquitto_publish_callback_set(mosq, my_publish_callback);
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1601 mosquitto_message_callback_set(mosq, my_message_callback);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1602 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
1603
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
1604 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
1605 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
1606 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
1607 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
1608 } 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
1609 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
1610 }
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
1611 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
1612 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
1613 } 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
1614 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
1615 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
1616
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
1617 /*
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
1618 * 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
1619 */
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
1620 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
1621 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
1622 }
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
1623 }
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
1624
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
1625
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
1626
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
1627 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
1628 {
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
1629 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
1630 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
1631
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
1632 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
1633 /*
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
1634 * 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
1635 * 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
1636 */
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
1637 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
1638 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
1639 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
1640 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
1641 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
1642 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
1643 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
1644 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
1645 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
1646 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
1647 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
1648 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
1649 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
1650 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
1651 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
1652 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
1653
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
1654 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
1655 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
1656 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
1657 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
1658 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
1659 }
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
1660 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
1661 }
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
1662 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
1663 } 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
1664
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
1665 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
1666 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
1667 mosquitto_lib_cleanup();
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1668 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
1669 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
1670 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
1671 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
1672 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
1673 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
1674 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
1675 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
1676 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
1677 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
1678 }
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
1679 }
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
1680
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
1681

mercurial