|
|
@ -38,34 +38,56 @@ int ICACHE_FLASH_ATTR cgiMqttGet(HttpdConnData *connData) { |
|
|
|
int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) { |
|
|
|
int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) { |
|
|
|
if (connData->conn==NULL) return HTTPD_CGI_DONE; |
|
|
|
if (connData->conn==NULL) return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
// handle MQTT server settings
|
|
|
|
// Handle tcp_enable flag
|
|
|
|
int mqtt_server = 0; // accumulator for changes/errors
|
|
|
|
char buff[128]; |
|
|
|
mqtt_server |= getStringArg(connData, "mqtt-host", |
|
|
|
int len = httpdFindArg(connData->getArgs, "tcp_enable", buff, sizeof(buff)); |
|
|
|
flashConfig.mqtt_hostname, sizeof(flashConfig.mqtt_hostname)); |
|
|
|
if (len <= 0) { |
|
|
|
if (mqtt_server < 0) return HTTPD_CGI_DONE; |
|
|
|
jsonHeader(connData, 400); |
|
|
|
mqtt_server |= getStringArg(connData, "mqtt-client-id", |
|
|
|
|
|
|
|
flashConfig.mqtt_client, sizeof(flashConfig.mqtt_client)); |
|
|
|
|
|
|
|
if (mqtt_server < 0) return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
mqtt_server |= getStringArg(connData, "mqtt-username", |
|
|
|
|
|
|
|
flashConfig.mqtt_username, sizeof(flashConfig.mqtt_username)); |
|
|
|
|
|
|
|
if (mqtt_server < 0) return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
mqtt_server |= getStringArg(connData, "mqtt-password", |
|
|
|
|
|
|
|
flashConfig.mqtt_password, sizeof(flashConfig.mqtt_password)); |
|
|
|
|
|
|
|
if (mqtt_server < 0) return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
mqtt_server |= getBoolArg(connData, "mqtt-enable", |
|
|
|
|
|
|
|
&flashConfig.mqtt_enable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// handle mqtt port
|
|
|
|
|
|
|
|
char buff[16]; |
|
|
|
|
|
|
|
if (httpdFindArg(connData->getArgs, "mqtt-port", buff, sizeof(buff)) > 0) { |
|
|
|
|
|
|
|
int32_t port = atoi(buff); |
|
|
|
|
|
|
|
if (port > 0 && port < 65536) { |
|
|
|
|
|
|
|
flashConfig.mqtt_port = port; |
|
|
|
|
|
|
|
mqtt_server |= 1; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
errorResponse(connData, 400, "Invalid MQTT port"); |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
} |
|
|
|
} |
|
|
|
flashConfig.tcp_enable = os_strcmp(buff, "true") == 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Handle rssi_enable flag
|
|
|
|
// if server setting changed, we need to "make it so"
|
|
|
|
len = httpdFindArg(connData->getArgs, "rssi_enable", buff, sizeof(buff)); |
|
|
|
if (mqtt_server) { |
|
|
|
if (len <= 0) { |
|
|
|
os_printf("MQTT server settings changed, enable=%d\n", flashConfig.mqtt_enable); |
|
|
|
jsonHeader(connData, 400); |
|
|
|
// TODO
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
flashConfig.rssi_enable = os_strcmp(buff, "true") == 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle api_key flag
|
|
|
|
// no action required if mqtt status settings change, they just get picked up at the
|
|
|
|
len = httpdFindArg(connData->getArgs, "api_key", buff, sizeof(buff)); |
|
|
|
// next status tick
|
|
|
|
if (len < 0) { |
|
|
|
if (getBoolArg(connData, "mqtt-status-enable", &flashConfig.mqtt_status_enable) < 0) |
|
|
|
jsonHeader(connData, 400); |
|
|
|
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
} |
|
|
|
if (getStringArg(connData, "mqtt-status-topic", |
|
|
|
buff[sizeof(flashConfig.api_key)-1] = 0; // ensure we don't get an overrun
|
|
|
|
flashConfig.mqtt_status_topic, sizeof(flashConfig.mqtt_status_topic)) < 0) |
|
|
|
os_strcpy(flashConfig.api_key, buff); |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
// if SLIP-enable is toggled it gets picked-up immediately by the parser
|
|
|
|
|
|
|
|
int slip_update = getBoolArg(connData, "slip-enable", &flashConfig.slip_enable); |
|
|
|
|
|
|
|
if (slip_update < 0) return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
if (slip_update > 0) os_printf("SLIP-enable changed: %d\n", flashConfig.slip_enable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os_printf("Saving config\n"); |
|
|
|
if (configSave()) { |
|
|
|
if (configSave()) { |
|
|
|
httpdStartResponse(connData, 200); |
|
|
|
httpdStartResponse(connData, 200); |
|
|
|
httpdEndHeaders(connData); |
|
|
|
httpdEndHeaders(connData); |
|
|
|