1016 srv_send((char *)"."); |
1016 srv_send((char *)"."); |
1017 return 0; |
1017 return 0; |
1018 } |
1018 } |
1019 |
1019 |
1020 if (strcmp(opt, (char *)"PUT") == 0) { |
1020 if (strcmp(opt, (char *)"PUT") == 0) { |
1021 bool mqtt_reconnect = false; |
1021 int mqtt_reconnect = 0; |
1022 while (1) { |
1022 while (1) { |
1023 rlen = srv_recv(ibuf); |
1023 rlen = srv_recv(ibuf); |
1024 if (rlen == -1) { |
1024 if (rlen == -1) { |
1025 return 0; |
1025 return 0; |
1026 } |
1026 } |
1027 if (strlen(ibuf)) { |
1027 if (strlen(ibuf)) { |
1028 if (strcmp(ibuf, (char *)".") == 0) { |
1028 if (strcmp(ibuf, (char *)".") == 0) { |
1029 srv_send((char *)"219 Accepted Global record"); |
1029 srv_send((char *)"219 Accepted Global record"); |
|
1030 #ifdef HAVE_MOSQUITTO_H |
1030 if (mqtt_reconnect) |
1031 if (mqtt_reconnect) |
1031 mqtt_connect(); |
1032 mqtt_connect(); |
|
1033 #endif |
1032 return 1; |
1034 return 1; |
1033 } |
1035 } |
1034 kwd = strtok(ibuf, ",\0"); |
1036 kwd = strtok(ibuf, ",\0"); |
1035 val = strtok(NULL, "\0"); |
1037 val = strtok(NULL, "\0"); |
1036 if (kwd) { |
1038 if (kwd) { |
1106 } |
1108 } |
1107 |
1109 |
1108 } else if (strcmp(kwd, (char *)"MQTT_HOST") == 0) { |
1110 } else if (strcmp(kwd, (char *)"MQTT_HOST") == 0) { |
1109 if (val && Config.mqtt_host && (strcmp(val, Config.mqtt_host))) |
1111 if (val && Config.mqtt_host && (strcmp(val, Config.mqtt_host))) |
1110 syslog(LOG_NOTICE, "Global MQTT host `%s' to `%s'", Config.mqtt_host, val); |
1112 syslog(LOG_NOTICE, "Global MQTT host `%s' to `%s'", Config.mqtt_host, val); |
|
1113 #ifdef HAVE_MOSQUITTO_H |
1111 mqtt_disconnect(); |
1114 mqtt_disconnect(); |
1112 mqtt_reconnect = true; |
1115 #endif |
|
1116 mqtt_reconnect = 1; |
1113 if (Config.mqtt_host) |
1117 if (Config.mqtt_host) |
1114 free(Config.mqtt_host); |
1118 free(Config.mqtt_host); |
1115 if (val) |
1119 if (val) |
1116 Config.mqtt_host = xstrcpy(val); |
1120 Config.mqtt_host = xstrcpy(val); |
1117 else |
1121 else |
1119 |
1123 |
1120 } else if (val && (strcmp(kwd, (char *)"MQTT_PORT") == 0)) { |
1124 } else if (val && (strcmp(kwd, (char *)"MQTT_PORT") == 0)) { |
1121 if (sscanf(val, "%d", &ival) == 1) { |
1125 if (sscanf(val, "%d", &ival) == 1) { |
1122 if (Config.mqtt_port != ival) { |
1126 if (Config.mqtt_port != ival) { |
1123 syslog(LOG_NOTICE, "Global MQTT port %d to %d", Config.mqtt_port, ival); |
1127 syslog(LOG_NOTICE, "Global MQTT port %d to %d", Config.mqtt_port, ival); |
|
1128 #ifdef HAVE_MOSQUITTO_H |
1124 mqtt_disconnect(); |
1129 mqtt_disconnect(); |
1125 mqtt_reconnect = true; |
1130 #endif |
|
1131 mqtt_reconnect = 1; |
1126 Config.mqtt_port = ival; |
1132 Config.mqtt_port = ival; |
1127 } |
1133 } |
1128 } |
1134 } |
1129 |
1135 |
1130 } else if (strcmp(kwd, (char *)"MQTT_USER") == 0) { |
1136 } else if (strcmp(kwd, (char *)"MQTT_USER") == 0) { |
1131 if (val && Config.mqtt_username && (strcmp(val, Config.mqtt_username))) |
1137 if (val && Config.mqtt_username && (strcmp(val, Config.mqtt_username))) |
1132 syslog(LOG_NOTICE, "Global MQTT username `%s' to `%s'", Config.mqtt_username, val); |
1138 syslog(LOG_NOTICE, "Global MQTT username `%s' to `%s'", Config.mqtt_username, val); |
|
1139 #ifdef HAVE_MOSQUITTO_H |
1133 mqtt_disconnect(); |
1140 mqtt_disconnect(); |
1134 mqtt_reconnect = true; |
1141 #endif |
|
1142 mqtt_reconnect = 1; |
1135 if (Config.mqtt_username) |
1143 if (Config.mqtt_username) |
1136 free(Config.mqtt_username); |
1144 free(Config.mqtt_username); |
1137 if (val) |
1145 if (val) |
1138 Config.mqtt_username = xstrcpy(val); |
1146 Config.mqtt_username = xstrcpy(val); |
1139 else |
1147 else |
1140 Config.mqtt_username = NULL; |
1148 Config.mqtt_username = NULL; |
1141 |
1149 |
1142 } else if (strcmp(kwd, (char *)"MQTT_PASS") == 0) { |
1150 } else if (strcmp(kwd, (char *)"MQTT_PASS") == 0) { |
1143 if (val && Config.mqtt_password && (strcmp(val, Config.mqtt_password))) |
1151 if (val && Config.mqtt_password && (strcmp(val, Config.mqtt_password))) |
1144 syslog(LOG_NOTICE, "Global MQTT password `%s' to `%s'", Config.mqtt_password, val); |
1152 syslog(LOG_NOTICE, "Global MQTT password `%s' to `%s'", Config.mqtt_password, val); |
|
1153 #ifdef HAVE_MOSQUITTO_H |
1145 mqtt_disconnect(); |
1154 mqtt_disconnect(); |
1146 mqtt_reconnect = true; |
1155 #endif |
|
1156 mqtt_reconnect = 1; |
1147 if (Config.mqtt_password) |
1157 if (Config.mqtt_password) |
1148 free(Config.mqtt_password); |
1158 free(Config.mqtt_password); |
1149 if (val) |
1159 if (val) |
1150 Config.mqtt_password = xstrcpy(val); |
1160 Config.mqtt_password = xstrcpy(val); |
1151 else |
1161 else |
2609 syslog(LOG_NOTICE, "Fermenter unit %s temperature set maximum %.1f to %.1f", unit->uuid, unit->temp_set_max, fval); |
2619 syslog(LOG_NOTICE, "Fermenter unit %s temperature set maximum %.1f to %.1f", unit->uuid, unit->temp_set_max, fval); |
2610 unit->temp_set_max = fval; |
2620 unit->temp_set_max = fval; |
2611 } |
2621 } |
2612 |
2622 |
2613 } |
2623 } |
|
2624 #ifdef HAVE_MOSQUITTO_H |
2614 if (unit->mqtt_flag) { |
2625 if (unit->mqtt_flag) { |
2615 if (debug) |
2626 if (debug) |
2616 fprintf(stdout, "flag value %d\n", unit->mqtt_flag); |
2627 fprintf(stdout, "flag value %d\n", unit->mqtt_flag); |
2617 if (unit->mqtt_flag & MQTT_FLAG_BIRTH) { |
2628 if (unit->mqtt_flag & MQTT_FLAG_BIRTH) { |
2618 publishDBirth(unit); |
2629 publishDBirth(unit); |