thermferm/mqtt.c

Mon, 18 May 2020 11:03:40 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 18 May 2020 11:03:40 +0200
changeset 606
798dd0c4fd00
parent 602
ca795b871158
child 608
a69b5d92fd72
permissions
-rw-r--r--

Version 0.9.9 Don't flag fermenter death if the unit is turned off. Fix a wrong log message. Send unit data even if the unit is turned off.

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 /*****************************************************************************
606
798dd0c4fd00 Version 0.9.9 Don't flag fermenter death if the unit is turned off. Fix a wrong log message. Send unit data even if the unit is turned off.
Michiel Broek <mbroek@mbse.eu>
parents: 602
diff changeset
2 * Copyright (C) 2016-2020
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 }
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
459 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
460 /* 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
461 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
462 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
463 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
464 }
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 }
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 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
467 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
468 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
469 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
470 /* 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
471 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
472 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
473 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
474 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
475 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
476 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
477 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
478 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
479 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
480 /*
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 * 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
482 * 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
483 */
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
484 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
485 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
486 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
487 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
488 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
489 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
490 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
491 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 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
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 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
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
496
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
497 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
498 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
499 /*
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
500 * 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
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 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
503 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
504 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
505 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
506 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
507 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
508 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
509 } 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
510 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
511 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
512 }
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
513 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
514 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
515 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
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
517
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
518 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
519 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
520 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
521 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
522 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
523 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
524 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
525 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
526 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
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
529
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
530 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
531 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
532 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
533 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
534 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
535 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
536 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
537 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
538 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
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
541
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
542 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
543 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
544 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
545 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
546 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
547 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
548 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
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
551
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
552 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
553 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
554 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
555 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
556 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
557 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
558 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
559 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
560 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
561 }
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
562 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in fridge mode without idle range offset, that was an old leftover setting that was obsolete.
Michiel Broek <mbroek@mbse.eu>
parents: 566
diff changeset
563 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
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
565
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
566 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
567 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
568 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
569 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
570 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
571 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
572 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
573 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 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
576 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
577 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
578 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
579 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
580 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
581 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
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
583 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
584 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
585 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
586 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
587 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
588 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
589 }
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 }
579
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
591 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
592 unit->yeast_lo = json_object_get_double(val);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
593 unit->mqtt_flag |= MQTT_FLAG_DATA;
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
594 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
595 }
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
596 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
597 unit->yeast_hi = json_object_get_double(val);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
598 unit->mqtt_flag |= MQTT_FLAG_DATA;
606
798dd0c4fd00 Version 0.9.9 Don't flag fermenter death if the unit is turned off. Fix a wrong log message. Send unit data even if the unit is turned off.
Michiel Broek <mbroek@mbse.eu>
parents: 602
diff changeset
599 syslog(LOG_NOTICE, "DCMD change fermenter %s: yeast_hi to `%.1f'", message_alias, unit->yeast_hi);
579
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
600 }
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
601 }
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
602
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none has been triggered in five years, Removed several obsolete upgrade functions. Updated the web liveview.
Michiel Broek <mbroek@mbse.eu>
parents: 569
diff changeset
603 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
604 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
605 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
606 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
607 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
608 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
609 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
610 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
611 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
612 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
613 }
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 } 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
615 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
616 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
617 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
618 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
619 } 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
620 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
621 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
622 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
623 }
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 } 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
625 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
626 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
627 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
628 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
629 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
630 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
631 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
632 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
633 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
634 }
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
635 } 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
636 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
637 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
638 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
639 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
640 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
641 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
642 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
643 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
644 }
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
645 } 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
646 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
647 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
648 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
649 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
650 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
651 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
652 }
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 }
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 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
655 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
656 }
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
657 } 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
658 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
659 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
660 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
661 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
662 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
663 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
664 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
665 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
666 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
667 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
668 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
669 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
672 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
673 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
674 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
675 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
676 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
678 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
679 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
680 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
682 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
683 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
686 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
687 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
688 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
689 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
691 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
692 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
693 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
694 /*
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 * 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
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 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
698 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
699
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
701 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
702 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
703 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
704 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
705
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
707 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
708 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
710 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
711 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
712 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
714 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
715 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
716 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
718 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
719 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
720 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
721 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
723 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
724 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
726 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
727 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
730 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
731 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
732 } 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
733 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
734 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
735 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
736 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
737 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
743 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
744 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
745 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 } 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
747 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
748 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
749 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
750 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
751 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
752 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
753 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
754 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
755 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
756 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
757 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
758 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
759 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
760 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 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
763 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
764 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
765 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
766 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
767 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
768 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
769 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
770 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
771 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 }
1e0192b295b9 Removed useless version marks from the xml configuration. Added DCMD profile configuration to install and delete profiles in a fermenter. Removed the old profiles configuration. Removed useless xml configuration error check because none 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 }
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
774 }
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
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 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
777 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
778 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
779 } 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
780 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
781 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 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
783 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
784 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 }
9c69d43bfb06 Version 0.9.0. Implemented DCMD via mqtt to set stage, mode, setpoint low and high. Implemeted DCMD via mqtt to set heater, cooler, fan and light state. Implemented DCMD via mqtt to set product code and name. Set the PID's in 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 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
788 }
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
789 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
790 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
791 }
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 } 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
793 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
794 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
795 }
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 }
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
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
798 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
799 } else {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
800 syslog(LOG_NOTICE, "MQTT: message callback %s (null)", message->topic);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
801 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
802 }
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 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
807 // publish the data
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
808 if (payload)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
809 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
810 else
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
811 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
812 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
813
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
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
816 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
817 char *dload = NULL;
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
818 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
819
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
820 if (idx == 0)
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
821 return;
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
822
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
823 sprintf(sidx, "%d", idx);
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
824 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
825
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
826 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
827 dload = xstrcat(dload, sidx);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
828 dload = xstrcat(dload, (char *)",\"nvalue\":0,\"svalue\":\"");
515
7ab5cf2afc0c Only send domoticz changed values
Michiel Broek <mbroek@mbse.eu>
parents: 514
diff changeset
829 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
830 dload = xstrcat(dload, (char *)"\"}");
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
831 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
832 free(dload);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
833 dload = NULL;
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
834 }
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
835
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
514
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
838 void pub_domoticz_output(int idx, int value) {
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
839 char *dload = NULL;
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
840 char sidx[10], sval[10];
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
841
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
842 if (idx == 0)
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
843 return;
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
844
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
845 sprintf(sidx, "%d", idx);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
846 sprintf(sval, "%d", value);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
847
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
848 dload = xstrcpy((char *)"{\"command\":\"udevice\",\"idx\":");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
849 dload = xstrcat(dload, sidx);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
850 dload = xstrcat(dload, (char *)",\"nvalue\":");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
851 if (value >= 50)
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
852 dload = xstrcat(dload, (char *)"1");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
853 else
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
854 dload = xstrcat(dload, (char *)"0");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
855 dload = xstrcat(dload, (char *)",\"svalue\":\"");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
856 dload = xstrcat(dload, sval);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
857 dload = xstrcat(dload, (char *)"\"}");
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
858 publisher(mosq, (char *)"domoticz/in", dload, false);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
859 free(dload);
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
860 dload = NULL;
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
861 }
f5a00ad53329 Changed state messages to domoticz
Michiel Broek <mbroek@mbse.eu>
parents: 513
diff changeset
862
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
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
865 char *unit_data(units_list *unit, bool birth)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
866 {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
867 char *payload = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
868 char buf[128];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
869 bool comma = false;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
870 prof_step *pstep;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
871
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
872 payload = xstrcpy((char *)"{");
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
873
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
874 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
875 * Fixed unit values, never change these!
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
876 */
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
877 if (birth) {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
878 payload = xstrcat(payload, (char *)"\"uuid\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
879 payload = xstrcat(payload, unit->uuid);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
880 payload = xstrcat(payload, (char *)"\",\"alias\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
881 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
882 payload = xstrcat(payload, (char *)"\",");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
883 }
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
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
885 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
886 * Product (beer) loaded information.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
887 */
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
888 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
889 (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
890 (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
891 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
892 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
893 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
894 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
895 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
896 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
897 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
898 }
ab9f22ab57b5 Versie 0.8.5. 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 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
900 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
901 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
902 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
903 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
904 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
905 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
906 }
ab9f22ab57b5 Versie 0.8.5. 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 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
908 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
909 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
910 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
911 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
912 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
913 }
579
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
914 sprintf(buf, "%.1f", unit->yeast_lo);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
915 payload = xstrcat(payload, (char *)",\"yeast_lo\":");
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
916 payload = xstrcat(payload, buf);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
917 sprintf(buf, "%.1f", unit->yeast_hi);
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
918 payload = xstrcat(payload, (char *)",\"yeast_hi\":");
7032693272f1 Concept for yeast limits settings.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
919 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
920 payload = xstrcat(payload, (char *)"}");
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
921 }
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
922
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 * Air temperature sensor
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
925 */
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
926 if (unit->air_address) {
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
927 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
928 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
929 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
930 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
931 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
932 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
933 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
934 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
935 } else {
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
936 payload = xstrcat(payload, (char *)",\"air\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
937 }
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
938
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
939 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
940 * Beer temperature sensor
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
941 */
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
942 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
943 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
944 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
945 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
946 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
947 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
948 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
949 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
950 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
951 } 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
952 payload = xstrcat(payload, (char *)",\"beer\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
953 }
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
954
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
955 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
956 * External chiller temperature sensor
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
957 */
518
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
958 if (unit->chiller_address) {
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
959 payload = xstrcat(payload, (char *)",\"chiller\":{\"address\":\"");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
960 payload = xstrcat(payload, unit->chiller_address);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
961 payload = xstrcat(payload, (char *)"\",\"state\":\"");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
962 payload = xstrcat(payload, (char *)TEMPSTATE[unit->chiller_state]);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
963 payload = xstrcat(payload, (char *)"\",\"temperature\":");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
964 sprintf(buf, "%.3f", unit->chiller_temperature / 1000.0);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
965 payload = xstrcat(payload, buf);
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
966 payload = xstrcat(payload, (char *)"}");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
967 } else {
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
968 payload = xstrcat(payload, (char *)",\"chiller\":null");
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
969 }
fd36bedab944 Added chiller configuration items
Michiel Broek <mbroek@mbse.eu>
parents: 515
diff changeset
970
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
971 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
972 * 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
973 */
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
974 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
975 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
976 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
977 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
978 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
979 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
980 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
981 sprintf(buf, "%d", unit->heater_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
982 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
983 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
984 } 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
985 payload = xstrcat(payload, (char *)",\"heater\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
986 }
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
987
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
988 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
989 * 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
990 */
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
991 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
992 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
993 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
994 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
995 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
996 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
997 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
998 sprintf(buf, "%d", unit->cooler_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
999 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
1000 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
1001 } 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
1002 payload = xstrcat(payload, (char *)",\"cooler\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1003 }
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
1004
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1005 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1006 * Fan control, 0..100% and usage counter.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1007 */
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
1008 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
1009 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
1010 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
1011 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
1012 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
1013 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1014 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1015 sprintf(buf, "%d", unit->fan_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1016 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
1017 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
1018 } 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
1019 payload = xstrcat(payload, (char *)",\"fan\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1020 }
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
1021
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1022 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1023 * 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
1024 */
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1025 if (unit->light_address) {
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1026 payload = xstrcat(payload, (char *)",\"light\":{\"address\":\"");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1027 payload = xstrcat(payload, 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 *)"\",\"state\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1029 sprintf(buf, "%d", unit->light_state);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1030 payload = xstrcat(payload, buf);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1031 payload = xstrcat(payload, (char *)",\"usage\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1032 sprintf(buf, "%d", unit->light_usage);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1033 payload = xstrcat(payload, buf);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1034 payload = xstrcat(payload, (char *)"}");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1035 } else {
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1036 payload = xstrcat(payload, (char *)",\"light\":null");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1037 }
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1038
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 * Door sensor.
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1041 */
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
1042 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
1043 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
1044 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
1045 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
1046 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
1047 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
1048 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
1049 } 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
1050 payload = xstrcat(payload, (char *)",\"door\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1051 }
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
1052
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1053 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1054 * PSU status
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1055 */
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
1056 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
1057 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
1058 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
1059 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
1060 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
1061 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
1062 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
1063 } 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
1064 payload = xstrcat(payload, (char *)",\"psu\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1065 }
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
1066
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1067 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1068 * Working mode and setpoints
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1069 */
564
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1070 payload = xstrcat(payload, (char *)",\"stage\":\"");
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1071 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
1072 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
1073 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
1074 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
1075 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
1076 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
1077 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
1078 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
1079 payload = xstrcat(payload, buf);
546
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1080 payload = xstrcat(payload, (char *)"},\"alarm\":");
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1081 sprintf(buf, "%d", unit->alarm_flag);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1082 payload = xstrcat(payload, buf);
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1083
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1084 /*
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1085 * Loaded profile and state
d2e8626e7118 Changed alarm message and mqtt message order
Michiel Broek <mbroek@mbse.eu>
parents: 545
diff changeset
1086 */
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
1087 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
1088 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
1089 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
1090 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
1091 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
1092 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
1093 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
1094 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
1095 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
1096 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
1097 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
1098 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
1099 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
1100 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
1101 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
1102 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
1103 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
1104 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
1105 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
1106 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
1107 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
1108 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
1109 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
1110 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
1111 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
1112 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
1113 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
1114 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
1115 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
1116 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
1117 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
1118 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
1119 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
1120 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
1121 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
1122 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
1123 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
1124 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
1125 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
1126 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
1127 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
1128 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
1129 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
1130 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
1131 }
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
1132 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
1133 comma = true;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1134 }
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 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
1136 } 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
1137 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
1138 }
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
1139 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
1140 } 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
1141 payload = xstrcat(payload, (char *)",\"profile\":null");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1142 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1143 payload = xstrcat(payload, (char *)"}");
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 return payload;
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
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
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
1150 /**
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
1151 * @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
1152 * 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
1153 */
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 void publishDBirthAll(void)
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1155 {
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
1156 char *topic = NULL, *payload = NULL, *payloadu = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1157 units_list *unit;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1158 int comma = FALSE;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1159
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1160 payload = payload_header();
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1161 payload = xstrcat(payload, (char *)"{\"units\":[");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1162 for (unit = Config.units; unit; unit = unit->next) {
606
798dd0c4fd00 Version 0.9.9 Don't flag fermenter death if the unit is turned off. Fix a wrong log message. Send unit data even if the unit is turned off.
Michiel Broek <mbroek@mbse.eu>
parents: 602
diff changeset
1163 // if (unit->mode != UNITMODE_OFF) {
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
1164 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
1165 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
1166 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
1167 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
1168 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
1169 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
1170 payloadu = NULL;
606
798dd0c4fd00 Version 0.9.9 Don't flag fermenter death if the unit is turned off. Fix a wrong log message. Send unit data even if the unit is turned off.
Michiel Broek <mbroek@mbse.eu>
parents: 602
diff changeset
1171 // }
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1172 }
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 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
1174 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
1175 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
1176 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
1177 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
1178 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
1179 }
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1180 free(payload);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1181 payload = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1182 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1183
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
1184
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1185
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1186 void publishDData(units_list *unit)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1187 {
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
1188 char *payload = NULL, *payloadu = NULL, *topic = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1189
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1190 if (mqtt_use) {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1191 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
1192 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
1193 payload = xstrcat(payload, payloadu);
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1194 payload = xstrcat(payload, (char *)"}");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1195 topic = xstrcat(topic_base((char *)"DDATA"), (char *)"/");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1196 topic = xstrcat(topic, unit->alias);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1197 publisher(mosq, topic, payload, false);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1198 free(payload);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1199 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
1200 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
1201 payloadu = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1202 free(topic);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1203 topic = NULL;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1204 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1205 }
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
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
1209 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
1210 {
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 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
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 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
1214 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
1215 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
1216 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
1217 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
1218 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
1219 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
1220 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
1221 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
1222 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
1223 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
1224 }
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 }
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 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
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 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
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 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
1234 // 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
1235 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
1236 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
1237 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
1238 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
1239 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
1240 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
1241 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
1242 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
1243 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
1244 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
1245 }
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 }
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
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
1250 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
1251 {
ab9f22ab57b5 Versie 0.8.5. 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 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
1253 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
1254
ab9f22ab57b5 Versie 0.8.5. 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 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
1256 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
1257 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
1258
ab9f22ab57b5 Versie 0.8.5. 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 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
1260 (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
1261 (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
1262 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
1263 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
1264 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
1265 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
1266 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
1267 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
1268 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
1269 }
ab9f22ab57b5 Versie 0.8.5. 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 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
1271 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
1272 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
1273 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
1274 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
1275 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
1276 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
1277 }
ab9f22ab57b5 Versie 0.8.5. 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 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
1279 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
1280 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
1281 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
1282 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
1283 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
1284 }
ab9f22ab57b5 Versie 0.8.5. 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 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
1287 }
ab9f22ab57b5 Versie 0.8.5. 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
ab9f22ab57b5 Versie 0.8.5. 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 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
1290 payload = xstrcat(payload, (char *)",");
564
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1291 payload = xstrcat(payload, (char *)"\"stage\":\"");
3fc61dd28656 Versie 0.8.8 Fermentation stage implemented in units.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
1292 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
1293 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
1294 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
1295 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
1296 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
1297 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
1298 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
1299 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
1300 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
1301 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
1302 }
ab9f22ab57b5 Versie 0.8.5. 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 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
1304 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
1305 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
1306 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
1307 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
1308 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
1309 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
1310 }
ab9f22ab57b5 Versie 0.8.5. 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 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
1312 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
1313 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
1314 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
1315 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
1316 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
1317 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
1318 }
ab9f22ab57b5 Versie 0.8.5. 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 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
1320 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
1321 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
1322 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
1323 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
1324 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
1325 }
ab9f22ab57b5 Versie 0.8.5. 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, (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
1327 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
1328 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
1329 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
1330 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
1331 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
1332 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
1333 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
1334 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
1335 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
1336 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
1337 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
1338 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
1339 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
1340 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
1341 }
ab9f22ab57b5 Versie 0.8.5. 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 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
1343 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
1344 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
1345 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
1346 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
1347 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
1348 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
1349 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
1350 }
ab9f22ab57b5 Versie 0.8.5. 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 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
1352 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
1353 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
1354 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
1355 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
1356 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
1357 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
1358 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
1359 }
ab9f22ab57b5 Versie 0.8.5. 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 // 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
1361 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
1362 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
1363 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
1364 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
1365 }
555
c6f04bfcec2c Add fermenter uuid to the DLOG message
Michiel Broek <mbroek@mbse.eu>
parents: 554
diff changeset
1366 payload = xstrcat(payload, (char *)",\"fermenter_uuid\":\"");
c6f04bfcec2c Add fermenter uuid to the DLOG message
Michiel Broek <mbroek@mbse.eu>
parents: 554
diff changeset
1367 payload = xstrcat(payload, unit->uuid);
c6f04bfcec2c Add fermenter uuid to the DLOG message
Michiel Broek <mbroek@mbse.eu>
parents: 554
diff changeset
1368 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
1369
ab9f22ab57b5 Versie 0.8.5. Implementatie product code en product naam. Implementatie DLOG MQTT berichten. Verminderde server rotocol debug berichten.
Michiel Broek <mbroek@mbse.eu>
parents: 550
diff changeset
1370 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
1371 topic = xstrcat(topic, unit->alias);
577
7a29f835e20a DLOG messages are no longer retained.
Michiel Broek <mbroek@mbse.eu>
parents: 575
diff changeset
1372 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
1373 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
1374 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
1375 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
1376 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
1377 }
ab9f22ab57b5 Versie 0.8.5. 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 }
ab9f22ab57b5 Versie 0.8.5. 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
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1382 void publishNData(bool birth, int flag)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1383 {
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
1384 char *topic = NULL, *payload = NULL, sidx[10], buf[64];
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1385 struct utsname ubuf;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1386 bool comma = false;
598
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1387 int model, rev, mem, maker, warranty;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1388
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1389 payload = payload_header();
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1390 payload = xstrcat(payload, (char *)"{");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1391
540
5a26429abbf8 Versie 0.6.7. Globale uuid toegevoegd voor de NBIRTH payload.
Michiel Broek <mbroek@mbse.eu>
parents: 535
diff changeset
1392 if (birth) {
5a26429abbf8 Versie 0.6.7. Globale uuid toegevoegd voor de NBIRTH payload.
Michiel Broek <mbroek@mbse.eu>
parents: 535
diff changeset
1393 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
1394 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
1395 payload = xstrcat(payload, (char *)"\",");
508
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1396 #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
1397 /*
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1398 * 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
1399 */
ca2fafcf3294 On Raspberry with WiringPi better hardware info is sent with NBIRTH
Michiel Broek <mbroek@mbse.eu>
parents: 561
diff changeset
1400 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
1401 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
1402 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
1403 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
1404 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
1405 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
1406 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
1407 payload = xstrcat(payload, (char *)"\"");
508
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1408 #else
598
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1409 /*
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1410 * Get the info from the internal function
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 piBoardId (&model, &rev, &mem, &maker, &warranty);
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1413 if (model != -1) {
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1414 payload = xstrcat(payload, (char *)"\"properties\":{\"hardwaremake\":\"Raspberry Pi ");
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1415 payload = xstrcat(payload, (char *)piMakerNames[maker]);
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1416 payload = xstrcat(payload, (char *)"\",\"hardwaremodel\":\"");
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1417 payload = xstrcat(payload, (char *)piModelNames[model]);
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1418 payload = xstrcat(payload, (char *)" rev ");
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1419 payload = xstrcat(payload, (char *)piRevisionNames[rev]);
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1420 payload = xstrcat(payload, (char *)"\"");
363dc36d2450 Added wiringPi hardware detection code.
Michiel Broek <mbroek@mbse.eu>
parents: 591
diff changeset
1421 } 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
1422 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
1423 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
1424 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
1425 } 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
1426 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
1427 }
508
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1428 #endif
9e67c5f9c994 Add Raspberry support in MQTT init message
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
1429 if (uname(&ubuf) == 0) {
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1430 payload = xstrcat(payload, (char *)",\"os\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1431 payload = xstrcat(payload, ubuf.sysname);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1432 payload = xstrcat(payload, (char *)"\",\"os_version\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1433 payload = xstrcat(payload, ubuf.release);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1434 payload = xstrcat(payload, (char *)"\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1435 } else {
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1436 payload = xstrcat(payload, (char *)",\"os\":\"Unknown\",\"os_version\":\"Unknown\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1437 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1438
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1439 payload = xstrcat(payload, (char *)",\"FW\":\"");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1440 payload = xstrcat(payload, (char *)VERSION);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1441 payload = xstrcat(payload, (char *)"\"}");
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1442 comma = true;
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1443 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1444
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
1445 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
1446 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
1447 payload = xstrcat(payload, (char *)",");
541
a5530abb16dd Fixed spelling error
Michiel Broek <mbroek@mbse.eu>
parents: 540
diff changeset
1448 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
1449 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
1450 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
1451 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
1452 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
1453 }
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 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
1455 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
1456 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
1457 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
1458 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
1459 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
1460 }
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, (char *)"}");
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1462 }
549
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1463
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1464 /*
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1465 * 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
1466 */
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1467 FILE *f;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1468 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
1469 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
1470 int family, s;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1471
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1472 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
1473 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
1474 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
1475 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
1476
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1477 // 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
1478 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
1479
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1480 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
1481 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
1482 goto neterr;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1483 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1484
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1485 //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
1486 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
1487 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
1488 continue;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1489 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1490
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1491 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
1492
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1493 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
1494 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
1495 if (s != 0) {
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1496 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
1497 goto neterr;
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1498 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1499 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
1500 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
1501 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
1502 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
1503 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
1504 // 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
1505 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1506 }
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 freeifaddrs(ifaddr);
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 }
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1511 fclose(f);
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 neterr:
ee1bcad035f0 Versie 0.8.2. Node NBIRTH payload heeft nu netwerk informatie.
Michiel Broek <mbroek@mbse.eu>
parents: 548
diff changeset
1514
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1515 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
1516 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
1517 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
1518 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
1519 } 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
1520 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
1521 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
1522 }
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 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
1524 topic = NULL;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1525 free(payload);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1526 payload = NULL;
513
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1527
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1528 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
1529 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
1530 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
1531
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1532 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
1533 payload = xstrcat(payload, sidx);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1534 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
1535 payload = xstrcat(payload, buf);
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 *)"\"}");
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1537 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
1538 free(payload);
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1539 payload = NULL;
a2732027afb3 Version 0.6.1 added support for domoticz mqtt sensors.
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
1540 }
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1541 }
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1542
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
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
1545 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
1546 {
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
1547 char *id = NULL, *topic;
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1548 char err[1024];
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1549 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
1550
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1551 /*
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 * 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
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 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
1555 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
1556 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
1557 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
1558 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
1559 /*
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 * 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
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 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
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
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 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
1566 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
1567 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
1568 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
1569 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
1570 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
1571 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
1572 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
1573 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
1574 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 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
1576 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
1577 }
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
1578 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
1579 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
1580
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1581 /*
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 * 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
1583 */
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
1584 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
1585 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
1586 if (rc > MOSQ_ERR_SUCCESS)
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1587 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
1588 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
1589 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
1590 }
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
1591 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
1592
509
b5ae9017194f Turn off MQTT debug
Michiel Broek <mbroek@mbse.eu>
parents: 508
diff changeset
1593 if (debug)
b5ae9017194f Turn off MQTT debug
Michiel Broek <mbroek@mbse.eu>
parents: 508
diff changeset
1594 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
1595 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
1596 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
1597 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
1598 mosquitto_publish_callback_set(mosq, my_publish_callback);
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1599 mosquitto_message_callback_set(mosq, my_message_callback);
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1600 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
1601
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
1602 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
1603 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
1604 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
1605 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
1606 } 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
1607 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
1608 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 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
1610 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
1611 } 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
1612 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
1613 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
1614
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1615 /*
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 * 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
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 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
1619 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
1620 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1621 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 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
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 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
1628 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
1629
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1630 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
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 * 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
1633 * 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
1634 */
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does not know and does not care if MQTT messages will be sent. Version 0.5.5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1635 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
1636 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
1637 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
1638 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
1639 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
1640 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
1641 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
1642 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
1643 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
1644 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
1645 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
1646 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
1647 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
1648 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
1649 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
1650 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
1651
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 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
1653 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
1654 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
1655 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
1656 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
1657 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 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
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 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
1661 } 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
1662
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 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
1664 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
1665 mosquitto_lib_cleanup();
506
cdcd07bbee30 New MQTT protocol
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
1666 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
1667 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
1668 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
1669 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
1670 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
1671 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
1672 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
1673 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
1674 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
1675 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
1676 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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 }
602d9968960f Created mqtt sourcefiles. Use flags to trigger publish messages. The main source does 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

mercurial