bmsd/mqtt.c

changeset 502
a8a6901b5a99
parent 501
9c41e865144a
child 567
6bf0afc33e70
equal deleted inserted replaced
501:9c41e865144a 502:a8a6901b5a99
1 /***************************************************************************** 1 /*****************************************************************************
2 * Copyright (C) 2017-2018 2 * Copyright (C) 2017-2019
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 *
23 #include "bms.h" 23 #include "bms.h"
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 29
29 30
30 extern sys_config Config; 31 extern sys_config Config;
31 extern int debug; 32 extern int debug;
32 33
96 mosquitto_subscribe(mosq, NULL, topic, 0); 97 mosquitto_subscribe(mosq, NULL, topic, 0);
97 free(topic); 98 free(topic);
98 topic = xstrcpy((char *)"mbv1.0/fermenters/#"); // Subscribe to fermenter messages. 99 topic = xstrcpy((char *)"mbv1.0/fermenters/#"); // Subscribe to fermenter messages.
99 mosquitto_subscribe(mosq, NULL, topic, 0); 100 mosquitto_subscribe(mosq, NULL, topic, 0);
100 free(topic); 101 free(topic);
101 topic = xstrcpy((char *)"mbv1.0/co2meter/#"); // Subscribe to co2meter messages. 102 topic = xstrcpy((char *)"mbv1.0/co2meters/#"); // Subscribe to co2meter messages.
102 mosquitto_subscribe(mosq, NULL, topic, 0); 103 mosquitto_subscribe(mosq, NULL, topic, 0);
103 free(topic); 104 free(topic);
104 topic = NULL; 105 topic = NULL;
105 mqtt_status = STATUS_CONNACK_RECVD; 106 mqtt_status = STATUS_CONNACK_RECVD;
106 } else { 107 } else {
168 } 169 }
169 if (strstr(message->topic, (char *)"fermenters") && strstr(message->topic, (char *)"DLOG")) { 170 if (strstr(message->topic, (char *)"fermenters") && strstr(message->topic, (char *)"DLOG")) {
170 fermenter_log(message->topic, (char *)message->payload); 171 fermenter_log(message->topic, (char *)message->payload);
171 return; 172 return;
172 } 173 }
174 if (strstr(message->topic, (char *)"co2meters") && strstr(message->topic, (char *)"DBIRTH")) {
175 co2meter_birth_data(message->topic, (char *)message->payload);
176 return;
177 }
178 if (strstr(message->topic, (char *)"co2meters") && strstr(message->topic, (char *)"DLOG")) {
179 co2meter_log(message->topic, (char *)message->payload);
180 return;
181 }
173 syslog(LOG_NOTICE, "MQTT: message callback %s :: %d", message->topic, message->payloadlen); 182 syslog(LOG_NOTICE, "MQTT: message callback %s :: %d", message->topic, message->payloadlen);
174 } else { 183 } else {
175 if (strstr(message->topic, (char *)"NBIRTH")) { 184 if (strstr(message->topic, (char *)"NBIRTH")) {
176 // Ignore ?? 185 // Ignore ??
177 fprintf(stdout, "MQTT: %s NULL\n", message->topic); 186 fprintf(stdout, "MQTT: %s NULL\n", message->topic);

mercurial