bmsd/mqtt.c

branch
stable
changeset 665
4d01937ae7af
parent 590
a43b8b85d8b3
child 679
48f8f3fce7c0
equal deleted inserted replaced
521:9d1aa6f3a4da 665:4d01937ae7af
1 /***************************************************************************** 1 /*****************************************************************************
2 * Copyright (C) 2017-2019 2 * Copyright (C) 2017-2020
3 * 3 *
4 * Michiel Broek <mbroek at mbse dot eu> 4 * Michiel Broek <mbroek at mbse dot eu>
5 * 5 *
6 * This file is part of the bms (Brewery Management System) 6 * This file is part of the bms (Brewery Management System)
7 * 7 *
24 #include "xutil.h" 24 #include "xutil.h"
25 #include "mqtt.h" 25 #include "mqtt.h"
26 #include "nodes.h" 26 #include "nodes.h"
27 #include "fermenters.h" 27 #include "fermenters.h"
28 #include "co2meters.h" 28 #include "co2meters.h"
29 #include "ispindels.h"
29 30
30 31
31 extern sys_config Config; 32 extern sys_config Config;
32 extern int debug; 33 extern int debug;
33 34
100 mosquitto_subscribe(mosq, NULL, topic, 0); 101 mosquitto_subscribe(mosq, NULL, topic, 0);
101 free(topic); 102 free(topic);
102 topic = xstrcpy((char *)"mbv1.0/co2meters/#"); // Subscribe to co2meter messages. 103 topic = xstrcpy((char *)"mbv1.0/co2meters/#"); // Subscribe to co2meter messages.
103 mosquitto_subscribe(mosq, NULL, topic, 0); 104 mosquitto_subscribe(mosq, NULL, topic, 0);
104 free(topic); 105 free(topic);
106 topic = xstrcpy((char *)"mbv1.0/ispindels/#"); // Subscribe to ispindel messages.
107 mosquitto_subscribe(mosq, NULL, topic, 0);
108 free(topic);
105 topic = NULL; 109 topic = NULL;
106 mqtt_status = STATUS_CONNACK_RECVD; 110 mqtt_status = STATUS_CONNACK_RECVD;
107 } else { 111 } else {
108 syslog(LOG_NOTICE, "MQTT: my_connect_callback: %s\n", mosquitto_connack_string(result)); 112 syslog(LOG_NOTICE, "MQTT: my_connect_callback: %s\n", mosquitto_connack_string(result));
109 } 113 }
169 } 173 }
170 if (strstr(message->topic, (char *)"fermenters") && strstr(message->topic, (char *)"DLOG")) { 174 if (strstr(message->topic, (char *)"fermenters") && strstr(message->topic, (char *)"DLOG")) {
171 fermenter_log(message->topic, (char *)message->payload); 175 fermenter_log(message->topic, (char *)message->payload);
172 return; 176 return;
173 } 177 }
178 if (strstr(message->topic, (char *)"fermenters") && strstr(message->topic, (char *)"DCMD")) {
179 return; // just ignore our own commands.
180 }
174 if (strstr(message->topic, (char *)"co2meters") && strstr(message->topic, (char *)"DBIRTH")) { 181 if (strstr(message->topic, (char *)"co2meters") && strstr(message->topic, (char *)"DBIRTH")) {
175 co2meter_birth_data(message->topic, (char *)message->payload); 182 co2meter_birth_data(message->topic, (char *)message->payload);
176 return; 183 return;
177 } 184 }
178 if (strstr(message->topic, (char *)"co2meters") && strstr(message->topic, (char *)"DLOG")) { 185 if (strstr(message->topic, (char *)"co2meters") && strstr(message->topic, (char *)"DLOG")) {
179 co2meter_log(message->topic, (char *)message->payload); 186 co2meter_log(message->topic, (char *)message->payload);
180 return; 187 return;
181 } 188 }
189 if (strstr(message->topic, (char *)"ispindels") && strstr(message->topic, (char *)"DBIRTH")) {
190 ispindel_birth_data(message->topic, (char *)message->payload);
191 return;
192 }
182 syslog(LOG_NOTICE, "MQTT: message callback %s :: %d", message->topic, message->payloadlen); 193 syslog(LOG_NOTICE, "MQTT: message callback %s :: %d", message->topic, message->payloadlen);
183 } else { 194 } else {
184 if (strstr(message->topic, (char *)"NBIRTH")) { 195 if (strstr(message->topic, (char *)"NBIRTH")) {
185 // Ignore ?? 196 // Ignore ??
186 fprintf(stdout, "MQTT: %s NULL\n", message->topic); 197 fprintf(stdout, "MQTT: %s NULL\n", message->topic);

mercurial