checked mqtt client, fixed some issues
This commit is contained in:
parent
cabc2904ea
commit
4b8b8a36d3
|
|
@ -46,6 +46,8 @@
|
|||
#define MAX_DYNVAR_LENGTH 64
|
||||
#define MAX_INCFILE_LENGTH 1024
|
||||
|
||||
#define HTTP_SERVER_DEBUG_LEVEL 1
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HTTP_IO_DONE = 0u, // Finished with procedure
|
||||
|
|
|
|||
|
|
@ -246,6 +246,7 @@
|
|||
SYS_CONFIG* GetSysConf(void);
|
||||
|
||||
esp_err_t WebGuiAppInit(void);
|
||||
void DelayedRestart(void);
|
||||
|
||||
|
||||
#endif /* COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_SYSTEMCONFIGURATION_H_ */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*! Copyright 2022 Bogdan Pilyugin
|
||||
/*! Copyright 2022 Bogdan Pilyugin
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -66,7 +66,6 @@ void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler)(httpd_req_t *req,
|
|||
AfterPostHandlerCust = post_handler;
|
||||
}
|
||||
|
||||
|
||||
HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostData)
|
||||
{
|
||||
const char *pt = filename + 1;
|
||||
|
|
@ -122,7 +121,6 @@ static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, c
|
|||
if (!memcmp(filename, pg_34, sizeof(pg_34)))
|
||||
return HTTPPostIndex34(req, PostData);
|
||||
|
||||
|
||||
if (!memcmp(filename, pg_reboot, sizeof(pg_reboot)))
|
||||
return HTTPPostReboot(req, PostData);
|
||||
|
||||
|
|
@ -132,8 +130,8 @@ static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, c
|
|||
if (!memcmp(filename, pg_mm, sizeof(pg_mm)))
|
||||
return HTTPPostMemJson(req, PostData);
|
||||
|
||||
if (AfterPostHandlerCust != NULL)
|
||||
AfterPostHandler(req, filename, PostData);
|
||||
if (AfterPostHandlerCust != NULL)
|
||||
AfterPostHandlerCust(req, filename, PostData);
|
||||
|
||||
|
||||
return HTTP_IO_DONE;
|
||||
|
|
@ -409,6 +407,26 @@ static HTTP_IO_RESULT HTTPPostIndex31(httpd_req_t *req, char *PostData)
|
|||
httpd_query_key_value(PostData, "clnm1", GetSysConf()->mqttStation[0].UserName,
|
||||
sizeof(GetSysConf()->mqttStation[0].UserName));
|
||||
|
||||
if (httpd_query_key_value(PostData, "mqttenb1", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
if (!strcmp((const char*) tmp, (const char*) "1"))
|
||||
TempIsMQTT1Enabled = true;
|
||||
}
|
||||
if (httpd_query_key_value(PostData, "mprt1", tmp, sizeof(tmp)) == ESP_OK)
|
||||
if (httpd_query_key_value(PostData, "mprt1", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
uint16_t tp = atoi((const char*) tmp);
|
||||
if (tp < 65535 && tp >= 1000)
|
||||
GetSysConf()->mqttStation[0].ServerPort = tp;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "clps1", tmp, sizeof(tmp)) == ESP_OK &&
|
||||
strcmp(tmp, (const char*) "******"))
|
||||
{
|
||||
strcpy(GetSysConf()->mqttStation[0].UserPass, tmp);
|
||||
}
|
||||
|
||||
#if CONFIG_MQTT_CLIENTS_NUM == 2
|
||||
httpd_query_key_value(PostData, "cld2", GetSysConf()->mqttStation[1].ServerAddr,
|
||||
sizeof(GetSysConf()->mqttStation[1].ServerAddr));
|
||||
httpd_query_key_value(PostData, "idd2", GetSysConf()->mqttStation[1].ClientID,
|
||||
|
|
@ -418,24 +436,13 @@ static HTTP_IO_RESULT HTTPPostIndex31(httpd_req_t *req, char *PostData)
|
|||
httpd_query_key_value(PostData, "clnm2", GetSysConf()->mqttStation[1].UserName,
|
||||
sizeof(GetSysConf()->mqttStation[1].UserName));
|
||||
|
||||
if (httpd_query_key_value(PostData, "mqttenb1", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
if (!strcmp((const char*) tmp, (const char*) "1"))
|
||||
TempIsMQTT1Enabled = true;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "mqttenb2", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
if (!strcmp((const char*) tmp, (const char*) "1"))
|
||||
TempIsMQTT2Enabled = true;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "mprt1", tmp, sizeof(tmp)) == ESP_OK)
|
||||
if (httpd_query_key_value(PostData, "mprt1", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
uint16_t tp = atoi((const char*) tmp);
|
||||
if (tp < 65535 && tp >= 1000)
|
||||
GetSysConf()->mqttStation[0].ServerPort = tp;
|
||||
}
|
||||
if (httpd_query_key_value(PostData, "mprt2", tmp, sizeof(tmp)) == ESP_OK)
|
||||
if (httpd_query_key_value(PostData, "mprt2", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
|
|
@ -444,23 +451,22 @@ static HTTP_IO_RESULT HTTPPostIndex31(httpd_req_t *req, char *PostData)
|
|||
GetSysConf()->mqttStation[1].ServerPort = tp;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "clps1", tmp, sizeof(tmp)) == ESP_OK &&
|
||||
strcmp(tmp, (const char*) "******"))
|
||||
{
|
||||
strcpy(GetSysConf()->mqttStation[0].UserPass, tmp);
|
||||
}
|
||||
if (httpd_query_key_value(PostData, "clps2", tmp, sizeof(tmp)) == ESP_OK &&
|
||||
strcmp(tmp, (const char*) "******"))
|
||||
{
|
||||
strcpy(GetSysConf()->mqttStation[1].UserPass, tmp);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (httpd_query_key_value(PostData, "sav", tmp, 4) == ESP_OK)
|
||||
{
|
||||
if (!strcmp(tmp, (const char*) "prs"))
|
||||
{
|
||||
GetSysConf()->mqttStation[0].Flags1.bIsGlobalEnabled = TempIsMQTT1Enabled;
|
||||
#if CONFIG_MQTT_CLIENTS_NUM == 2
|
||||
GetSysConf()->mqttStation[1].Flags1.bIsGlobalEnabled = TempIsMQTT2Enabled;
|
||||
#endif
|
||||
WriteNVSSysConfig(GetSysConf());
|
||||
memcpy(PostData, "/reboot.html", sizeof "/reboot.html");
|
||||
return HTTP_IO_REDIRECT;
|
||||
|
|
@ -480,8 +486,6 @@ static HTTP_IO_RESULT HTTPPostIndex34(httpd_req_t *req, char *PostData)
|
|||
return HTTP_IO_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static HTTP_IO_RESULT HTTPPostReboot(httpd_req_t *req, char *PostData)
|
||||
{
|
||||
char tmp[33];
|
||||
|
|
@ -489,7 +493,7 @@ static HTTP_IO_RESULT HTTPPostReboot(httpd_req_t *req, char *PostData)
|
|||
{
|
||||
if (!strcmp(tmp, (const char*) "prs"))
|
||||
{
|
||||
//DelayedRestart();
|
||||
DelayedRestart();
|
||||
}
|
||||
}
|
||||
return HTTP_IO_DONE;
|
||||
|
|
|
|||
|
|
@ -581,6 +581,7 @@ int HTTPPrint(httpd_req_t *req, char *buf, char *var)
|
|||
HTTPPrintCust(req, buf, var);
|
||||
else
|
||||
HTTPPrint_DEF(VarData, NULL);
|
||||
|
||||
}
|
||||
int dLen = strlen(VarData);
|
||||
memcpy(buf, VarData, dLen);
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ static void ComposeTopic(char *topic, char *system_name, char *direct, char *cli
|
|||
BytesToStr((unsigned char*) tmp, (unsigned char*) dev_rom_id, 4);
|
||||
strcpy((char*) topic, system_name); // Global system name
|
||||
strcat((char*) topic, "/");
|
||||
strcpy((char*) topic, direct); // Data direction UPLINK or DOWNLINK
|
||||
strcat((char*) topic, direct); // Data direction UPLINK or DOWNLINK
|
||||
strcat((char*) topic, "/");
|
||||
strcat((char*) topic, (const char*) dev_rom_id); // Unique device ID (based on ROM chip id)
|
||||
strcat((char*) topic, "/");
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ esp_err_t WebGuiAppInit(void)
|
|||
esp_err_t err = nvs_flash_init();
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND || MANUAL_RESET == 1)
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND || MANUAL_RESET == 1 || gpio_get_level(GPIO_NUM_34) == 0)
|
||||
{
|
||||
// 1.OTA app partition table has a smaller NVS partition size than the non-OTA
|
||||
// partition table. This size mismatch may cause NVS initialization to fail.
|
||||
|
|
@ -126,7 +126,7 @@ if(GetSysConf()->wifiSettings.Flags1.bIsAP)
|
|||
if (GetSysConf()->mqttStation[0].Flags1.bIsGlobalEnabled
|
||||
|| GetSysConf()->mqttStation[1].Flags1.bIsGlobalEnabled)
|
||||
{
|
||||
// MQTTRun();
|
||||
MQTTRun();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -331,7 +331,7 @@ static void ResetSysConfig(SYS_CONFIG *Conf)
|
|||
memcpy(Conf->mqttStation[1].UserPass, CONFIG_MQTT_PASSWORD, sizeof(CONFIG_MQTT_PASSWORD));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
GetChipId(Conf->imei);
|
||||
}
|
||||
|
||||
esp_err_t ReadNVSSysConfig(SYS_CONFIG *SysConf)
|
||||
|
|
@ -410,3 +410,13 @@ esp_err_t ResetInitSysConfig(void)
|
|||
return WriteNVSSysConfig(&SysConfig);
|
||||
}
|
||||
|
||||
|
||||
void DelayedRestartTask(void *pvParameter)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
esp_restart();
|
||||
}
|
||||
void DelayedRestart(void)
|
||||
{
|
||||
xTaskCreate(DelayedRestartTask, "RestartTask", 1024 * 4, (void*) 0, 3, NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user