1005 srv_send((char *)"HUM_VALUE,%.0f", Config.hum_value / 1000.0); |
1005 srv_send((char *)"HUM_VALUE,%.0f", Config.hum_value / 1000.0); |
1006 srv_send((char *)"TEMP_HUM_IDX,%d", Config.temp_hum_idx); |
1006 srv_send((char *)"TEMP_HUM_IDX,%d", Config.temp_hum_idx); |
1007 srv_send((char *)"LCD_COLS,%d", Config.lcd_cols); |
1007 srv_send((char *)"LCD_COLS,%d", Config.lcd_cols); |
1008 srv_send((char *)"LCD_ROWS,%d", Config.lcd_rows); |
1008 srv_send((char *)"LCD_ROWS,%d", Config.lcd_rows); |
1009 srv_send((char *)"NEXT_UNIT,%d", Config.next_unit); |
1009 srv_send((char *)"NEXT_UNIT,%d", Config.next_unit); |
1010 #ifdef HAVE_MOSQUITTO_H |
|
1011 srv_send((char *)"MQTT_HOST,%s", Config.mqtt_host); |
1010 srv_send((char *)"MQTT_HOST,%s", Config.mqtt_host); |
1012 srv_send((char *)"MQTT_PORT,%d", Config.mqtt_port); |
1011 srv_send((char *)"MQTT_PORT,%d", Config.mqtt_port); |
1013 #endif |
1012 srv_send((char *)"MQTT_USER,%s", Config.mqtt_username); |
|
1013 srv_send((char *)"MQTT_PASS,%s", Config.mqtt_password); |
1014 srv_send((char *)"."); |
1014 srv_send((char *)"."); |
1015 return 0; |
1015 return 0; |
1016 } |
1016 } |
1017 |
1017 |
1018 if (strcmp(opt, (char *)"PUT") == 0) { |
1018 if (strcmp(opt, (char *)"PUT") == 0) { |
|
1019 bool mqtt_reconnect = false; |
1019 while (1) { |
1020 while (1) { |
1020 rlen = srv_recv(ibuf); |
1021 rlen = srv_recv(ibuf); |
1021 if (rlen == -1) { |
1022 if (rlen == -1) { |
1022 return 0; |
1023 return 0; |
1023 } |
1024 } |
1024 if (strlen(ibuf)) { |
1025 if (strlen(ibuf)) { |
1025 if (strcmp(ibuf, (char *)".") == 0) { |
1026 if (strcmp(ibuf, (char *)".") == 0) { |
1026 srv_send((char *)"219 Accepted Global record"); |
1027 srv_send((char *)"219 Accepted Global record"); |
|
1028 if (mqtt_reconnect) |
|
1029 mqtt_connect(); |
1027 return 1; |
1030 return 1; |
1028 } |
1031 } |
1029 kwd = strtok(ibuf, ",\0"); |
1032 kwd = strtok(ibuf, ",\0"); |
1030 val = strtok(NULL, "\0"); |
1033 val = strtok(NULL, "\0"); |
1031 if (kwd) { |
1034 if (kwd) { |
1097 if (sscanf(val, "%d", &ival) == 1) { |
1100 if (sscanf(val, "%d", &ival) == 1) { |
1098 if (Config.lcd_rows != ival) |
1101 if (Config.lcd_rows != ival) |
1099 syslog(LOG_NOTICE, "Global LCD rows %d to %d", Config.lcd_rows, ival); |
1102 syslog(LOG_NOTICE, "Global LCD rows %d to %d", Config.lcd_rows, ival); |
1100 Config.lcd_rows = ival; |
1103 Config.lcd_rows = ival; |
1101 } |
1104 } |
|
1105 |
|
1106 } else if (strcmp(kwd, (char *)"MQTT_HOST") == 0) { |
|
1107 if (val && Config.mqtt_host && (strcmp(val, Config.mqtt_host))) |
|
1108 syslog(LOG_NOTICE, "Global MQTT host `%s' to `%s'", Config.mqtt_host, val); |
|
1109 mqtt_disconnect(); |
|
1110 mqtt_reconnect = true; |
|
1111 if (Config.mqtt_host) |
|
1112 free(Config.mqtt_host); |
|
1113 if (val) |
|
1114 Config.mqtt_host = xstrcpy(val); |
|
1115 else |
|
1116 Config.mqtt_host = NULL; |
|
1117 |
|
1118 } else if (val && (strcmp(kwd, (char *)"MQTT_PORT") == 0)) { |
|
1119 if (sscanf(val, "%d", &ival) == 1) { |
|
1120 if (Config.mqtt_port != ival) { |
|
1121 syslog(LOG_NOTICE, "Global MQTT port %d to %d", Config.mqtt_port, ival); |
|
1122 mqtt_disconnect(); |
|
1123 mqtt_reconnect = true; |
|
1124 Config.mqtt_port = ival; |
|
1125 } |
|
1126 } |
|
1127 |
|
1128 } else if (strcmp(kwd, (char *)"MQTT_USER") == 0) { |
|
1129 if (val && Config.mqtt_username && (strcmp(val, Config.mqtt_username))) |
|
1130 syslog(LOG_NOTICE, "Global MQTT username `%s' to `%s'", Config.mqtt_username, val); |
|
1131 mqtt_disconnect(); |
|
1132 mqtt_reconnect = true; |
|
1133 if (Config.mqtt_username) |
|
1134 free(Config.mqtt_username); |
|
1135 if (val) |
|
1136 Config.mqtt_username = xstrcpy(val); |
|
1137 else |
|
1138 Config.mqtt_username = NULL; |
|
1139 |
|
1140 } else if (strcmp(kwd, (char *)"MQTT_PASS") == 0) { |
|
1141 if (val && Config.mqtt_password && (strcmp(val, Config.mqtt_password))) |
|
1142 syslog(LOG_NOTICE, "Global MQTT password `%s' to `%s'", Config.mqtt_password, val); |
|
1143 mqtt_disconnect(); |
|
1144 mqtt_reconnect = true; |
|
1145 if (Config.mqtt_password) |
|
1146 free(Config.mqtt_password); |
|
1147 if (val) |
|
1148 Config.mqtt_password = xstrcpy(val); |
|
1149 else |
|
1150 Config.mqtt_password = NULL; |
|
1151 |
1102 } |
1152 } |
1103 } |
1153 } |
1104 } |
1154 } |
1105 } |
1155 } |
1106 } |
1156 } |