1027 return 0; |
1027 return 0; |
1028 } |
1028 } |
1029 if (strlen(ibuf)) { |
1029 if (strlen(ibuf)) { |
1030 if (strcmp(ibuf, (char *)".") == 0) { |
1030 if (strcmp(ibuf, (char *)".") == 0) { |
1031 srv_send((char *)"219 Accepted Global record"); |
1031 srv_send((char *)"219 Accepted Global record"); |
1032 #ifdef HAVE_MOSQUITTO_H |
|
1033 if (mqtt_reconnect) |
1032 if (mqtt_reconnect) |
1034 mqtt_connect(); |
1033 mqtt_connect(); |
1035 #endif |
|
1036 return 1; |
1034 return 1; |
1037 } |
1035 } |
1038 kwd = strtok(ibuf, ",\0"); |
1036 kwd = strtok(ibuf, ",\0"); |
1039 val = strtok(NULL, "\0"); |
1037 val = strtok(NULL, "\0"); |
1040 if (kwd) { |
1038 if (kwd) { |
1110 } |
1108 } |
1111 |
1109 |
1112 } else if (strcmp(kwd, (char *)"MQTT_HOST") == 0) { |
1110 } else if (strcmp(kwd, (char *)"MQTT_HOST") == 0) { |
1113 if (val && Config.mqtt_host && (strcmp(val, Config.mqtt_host))) |
1111 if (val && Config.mqtt_host && (strcmp(val, Config.mqtt_host))) |
1114 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); |
1115 #ifdef HAVE_MOSQUITTO_H |
|
1116 mqtt_disconnect(); |
1113 mqtt_disconnect(); |
1117 #endif |
|
1118 mqtt_reconnect = 1; |
1114 mqtt_reconnect = 1; |
1119 if (Config.mqtt_host) |
1115 if (Config.mqtt_host) |
1120 free(Config.mqtt_host); |
1116 free(Config.mqtt_host); |
1121 if (val) |
1117 if (val) |
1122 Config.mqtt_host = xstrcpy(val); |
1118 Config.mqtt_host = xstrcpy(val); |
1125 |
1121 |
1126 } else if (val && (strcmp(kwd, (char *)"MQTT_PORT") == 0)) { |
1122 } else if (val && (strcmp(kwd, (char *)"MQTT_PORT") == 0)) { |
1127 if (sscanf(val, "%d", &ival) == 1) { |
1123 if (sscanf(val, "%d", &ival) == 1) { |
1128 if (Config.mqtt_port != ival) { |
1124 if (Config.mqtt_port != ival) { |
1129 syslog(LOG_NOTICE, "Global MQTT port %d to %d", Config.mqtt_port, ival); |
1125 syslog(LOG_NOTICE, "Global MQTT port %d to %d", Config.mqtt_port, ival); |
1130 #ifdef HAVE_MOSQUITTO_H |
|
1131 mqtt_disconnect(); |
1126 mqtt_disconnect(); |
1132 #endif |
|
1133 mqtt_reconnect = 1; |
1127 mqtt_reconnect = 1; |
1134 Config.mqtt_port = ival; |
1128 Config.mqtt_port = ival; |
1135 } |
1129 } |
1136 } |
1130 } |
1137 |
1131 |
1138 } else if (strcmp(kwd, (char *)"MQTT_USER") == 0) { |
1132 } else if (strcmp(kwd, (char *)"MQTT_USER") == 0) { |
1139 if (val && Config.mqtt_username && (strcmp(val, Config.mqtt_username))) |
1133 if (val && Config.mqtt_username && (strcmp(val, Config.mqtt_username))) |
1140 syslog(LOG_NOTICE, "Global MQTT username `%s' to `%s'", Config.mqtt_username, val); |
1134 syslog(LOG_NOTICE, "Global MQTT username `%s' to `%s'", Config.mqtt_username, val); |
1141 #ifdef HAVE_MOSQUITTO_H |
|
1142 mqtt_disconnect(); |
1135 mqtt_disconnect(); |
1143 #endif |
|
1144 mqtt_reconnect = 1; |
1136 mqtt_reconnect = 1; |
1145 if (Config.mqtt_username) |
1137 if (Config.mqtt_username) |
1146 free(Config.mqtt_username); |
1138 free(Config.mqtt_username); |
1147 if (val) |
1139 if (val) |
1148 Config.mqtt_username = xstrcpy(val); |
1140 Config.mqtt_username = xstrcpy(val); |
1150 Config.mqtt_username = NULL; |
1142 Config.mqtt_username = NULL; |
1151 |
1143 |
1152 } else if (strcmp(kwd, (char *)"MQTT_PASS") == 0) { |
1144 } else if (strcmp(kwd, (char *)"MQTT_PASS") == 0) { |
1153 if (val && Config.mqtt_password && (strcmp(val, Config.mqtt_password))) |
1145 if (val && Config.mqtt_password && (strcmp(val, Config.mqtt_password))) |
1154 syslog(LOG_NOTICE, "Global MQTT password `%s' to `%s'", Config.mqtt_password, val); |
1146 syslog(LOG_NOTICE, "Global MQTT password `%s' to `%s'", Config.mqtt_password, val); |
1155 #ifdef HAVE_MOSQUITTO_H |
|
1156 mqtt_disconnect(); |
1147 mqtt_disconnect(); |
1157 #endif |
|
1158 mqtt_reconnect = 1; |
1148 mqtt_reconnect = 1; |
1159 if (Config.mqtt_password) |
1149 if (Config.mqtt_password) |
1160 free(Config.mqtt_password); |
1150 free(Config.mqtt_password); |
1161 if (val) |
1151 if (val) |
1162 Config.mqtt_password = xstrcpy(val); |
1152 Config.mqtt_password = xstrcpy(val); |
2666 syslog(LOG_NOTICE, "Fermenter unit %s temperature set maximum %.1f to %.1f", unit->uuid, unit->temp_set_max, fval); |
2656 syslog(LOG_NOTICE, "Fermenter unit %s temperature set maximum %.1f to %.1f", unit->uuid, unit->temp_set_max, fval); |
2667 unit->temp_set_max = fval; |
2657 unit->temp_set_max = fval; |
2668 } |
2658 } |
2669 |
2659 |
2670 } |
2660 } |
2671 #ifdef HAVE_MOSQUITTO_H |
|
2672 if (unit->mqtt_flag) { |
2661 if (unit->mqtt_flag) { |
2673 if (debug) |
2662 if (debug) |
2674 fprintf(stdout, "flag value %d\n", unit->mqtt_flag); |
2663 fprintf(stdout, "flag value %d\n", unit->mqtt_flag); |
2675 if (unit->mqtt_flag & MQTT_FLAG_BIRTH) { |
2664 if (unit->mqtt_flag & MQTT_FLAG_BIRTH) { |
2676 publishDBirth(unit); |
2665 publishDBirth(unit); |