conditional build of mqtt code
This commit is contained in:
parent
b49073877d
commit
13a0cdbe4c
63
Kconfig
63
Kconfig
|
|
@ -168,6 +168,22 @@ menu "WebGuiApp configuration"
|
|||
bool "Default Ethernet switched on"
|
||||
default y
|
||||
|
||||
config WEBGUIAPP_ETH_IP_DEFAULT
|
||||
string "Default IP address"
|
||||
default "192.168.1.150"
|
||||
|
||||
config WEBGUIAPP_ETH_MASK_DEFAULT
|
||||
string "Default network mask"
|
||||
default "255.255.255.0"
|
||||
|
||||
config WEBGUIAPP_ETH_GATEWAY_DEFAULT
|
||||
string "Default gateway"
|
||||
default "192.168.1.150"
|
||||
|
||||
config WEBGUIAPP_ETHERNET_DHCP_DEFAULT
|
||||
bool "Default Ethernet DHCP client on"
|
||||
default n
|
||||
|
||||
config GPIO_RANGE_MIN
|
||||
int
|
||||
default 0
|
||||
|
|
@ -529,6 +545,53 @@ menu "WebGuiApp configuration"
|
|||
endif
|
||||
endmenu
|
||||
|
||||
menu "MQTT settings"
|
||||
config WEBGUIAPP_MQTT_ENABLE
|
||||
bool "Enabled MQTT transport"
|
||||
default y
|
||||
|
||||
if WEBGUIAPP_MQTT_ENABLE
|
||||
config MQTT_CLIENTS_NUM
|
||||
int "Number of MQTT clients"
|
||||
range 1 2
|
||||
default 2
|
||||
|
||||
config MQTT_ON
|
||||
bool "Enable MQTT client"
|
||||
default y
|
||||
|
||||
config MQTT_SERVER_URL
|
||||
string "MQTT server URL"
|
||||
default "myfirstmqttserver.com"
|
||||
|
||||
config MQTT_SERVER_PORT
|
||||
int "MQTT server port"
|
||||
range 1 65535
|
||||
default 1883
|
||||
|
||||
config MQTT_CLIENT_ID_1
|
||||
string "MQTT_1 client ID"
|
||||
default "DEVID1"
|
||||
|
||||
if MQTT_CLIENTS_NUM > 1
|
||||
config MQTT_CLIENT_ID_2
|
||||
string "MQTT_2 client ID"
|
||||
default "DEVID2"
|
||||
endif
|
||||
|
||||
config MQTT_ROOT_TOPIC
|
||||
string "MQTT root topic"
|
||||
default "ROOTTOPIC"
|
||||
|
||||
config MQTT_USERNAME
|
||||
string "MQTT user name"
|
||||
default "username"
|
||||
|
||||
config MQTT_PASSWORD
|
||||
string "MQTT user password"
|
||||
default "password"
|
||||
|
||||
endif
|
||||
endmenu
|
||||
|
||||
endmenu
|
||||
|
|
@ -29,8 +29,6 @@
|
|||
#include "esp_netif.h"
|
||||
#include <sdkconfig.h>
|
||||
|
||||
#define MQTT_CLIENTS_NUM 2
|
||||
|
||||
#define DEFAULT_HOST_NAME "DEVICE_HOSTNAME" ///<Default host name of device
|
||||
|
||||
#define SYSTEM_DEFAULT_USERNAME "user"
|
||||
|
|
@ -131,7 +129,7 @@
|
|||
} Flags1;
|
||||
} sntpClient;
|
||||
|
||||
|
||||
#if CONFIG_WEBGUIAPP_MQTT_ENABLE
|
||||
struct
|
||||
{
|
||||
char ServerAddr[32];
|
||||
|
|
@ -151,7 +149,8 @@
|
|||
char b6 :1;
|
||||
char bIsGlobalEnabled :1;
|
||||
} Flags1;
|
||||
} mqttStation[MQTT_CLIENTS_NUM];
|
||||
} mqttStation[CONFIG_MQTT_CLIENTS_NUM];
|
||||
#endif
|
||||
|
||||
#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE
|
||||
struct
|
||||
|
|
|
|||
|
|
@ -400,6 +400,7 @@ static HTTP_IO_RESULT HTTPPostIndex32(httpd_req_t *req, char *PostData)
|
|||
|
||||
static HTTP_IO_RESULT HTTPPostIndex31(httpd_req_t *req, char *PostData)
|
||||
{
|
||||
#if CONFIG_WEBGUIAPP_MQTT_ENABLE
|
||||
char tmp[33];
|
||||
bool TempIsMQTT1Enabled = false;
|
||||
bool TempIsMQTT2Enabled = false;
|
||||
|
|
@ -469,6 +470,7 @@ static HTTP_IO_RESULT HTTPPostIndex31(httpd_req_t *req, char *PostData)
|
|||
return HTTP_IO_REDIRECT;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return HTTP_IO_DONE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,6 @@ static void PrintCheckbox(char *VarData, void *arg, bool checked)
|
|||
snprintf(VarData, MAX_DYNVAR_LENGTH, " ");
|
||||
}
|
||||
|
||||
|
||||
static void HTTPPrint_status_fail(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "none");
|
||||
|
|
@ -129,15 +128,12 @@ static void HTTPPrint_pass(char *VarData, void *arg)
|
|||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", "******");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Default string if not found handler
|
||||
static void HTTPPrint_DEF(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "#DEF");
|
||||
}
|
||||
|
||||
|
||||
#if CONFIG_WEBGUIAPP_WIFI_ENABLE
|
||||
|
||||
static void HTTPPrint_wfen(char *VarData, void *arg)
|
||||
|
|
@ -381,6 +377,67 @@ void HTTPPrint_gsmmac(char *VarData, void *arg)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_WEBGUIAPP_MQTT_ENABLE
|
||||
void HTTPPrint_mqtten1(char *VarData, void *arg)
|
||||
{
|
||||
PrintCheckbox(VarData, arg, GetSysConf()->mqttStation[0].Flags1.bIsGlobalEnabled);
|
||||
}
|
||||
void HTTPPrint_ipcld1(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetSysConf()->mqttStation[0].ServerAddr);
|
||||
}
|
||||
void HTTPPrint_mport1(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%d", GetSysConf()->mqttStation[0].ServerPort);
|
||||
}
|
||||
void HTTPPrint_idcld1(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetSysConf()->mqttStation[0].ClientID);
|
||||
}
|
||||
void HTTPPrint_topic1(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetSysConf()->mqttStation[0].RootTopic);
|
||||
}
|
||||
void HTTPPrint_clname1(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetSysConf()->mqttStation[0].UserName);
|
||||
}
|
||||
void HTTPPrint_clpass1(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", "******");
|
||||
}
|
||||
|
||||
#if CONFIG_MQTT_CLIENTS_NUM == 2
|
||||
void HTTPPrint_mqtten2(char *VarData, void *arg)
|
||||
{
|
||||
PrintCheckbox(VarData, arg, GetSysConf()->mqttStation[1].Flags1.bIsGlobalEnabled);
|
||||
}
|
||||
void HTTPPrint_ipcld2(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetSysConf()->mqttStation[1].ServerAddr);
|
||||
}
|
||||
void HTTPPrint_mport2(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%d", GetSysConf()->mqttStation[1].ServerPort);
|
||||
}
|
||||
void HTTPPrint_idcld2(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetSysConf()->mqttStation[1].ClientID);
|
||||
}
|
||||
void HTTPPrint_topic2(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetSysConf()->mqttStation[1].RootTopic);
|
||||
}
|
||||
void HTTPPrint_clname2(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetSysConf()->mqttStation[1].UserName);
|
||||
}
|
||||
void HTTPPrint_clpass2(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", "******");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
dyn_var_handler_t HANDLERS_ARRAY[] = {
|
||||
/*Ststem settings*/
|
||||
|
|
@ -441,12 +498,30 @@ dyn_var_handler_t HANDLERS_ARRAY[] = {
|
|||
{ "gsmmac", sizeof("gsmmac") - 1, &HTTPPrint_gsmmac },
|
||||
#endif
|
||||
|
||||
#if CONFIG_WEBGUIAPP_MQTT_ENABLE
|
||||
/*MQTT*/
|
||||
{ "mqtten1", sizeof("mqtten1") - 1, &HTTPPrint_mqtten1 },
|
||||
{ "ipcld1", sizeof("ipcld1") - 1, &HTTPPrint_ipcld1 },
|
||||
{ "mport1", sizeof("mport1") - 1, &HTTPPrint_mport1 },
|
||||
{ "idcld1", sizeof("idcld1") - 1, &HTTPPrint_idcld1 },
|
||||
{ "topic1", sizeof("topic1") - 1, &HTTPPrint_topic1 },
|
||||
{ "clname1", sizeof("clname1") - 1, &HTTPPrint_clname1 },
|
||||
{ "clpass1", sizeof("clpass1") - 1, &HTTPPrint_clpass1 },
|
||||
#if CONFIG_MQTT_CLIENTS_NUM == 2
|
||||
{ "mqtten2", sizeof("mqtten2") - 1, &HTTPPrint_mqtten2 },
|
||||
{ "ipcld2", sizeof("ipcld2") - 1, &HTTPPrint_ipcld2 },
|
||||
{ "mport2", sizeof("mport2") - 1, &HTTPPrint_mport2 },
|
||||
{ "idcld2", sizeof("idcld2") - 1, &HTTPPrint_idcld2 },
|
||||
{ "topic2", sizeof("topic2") - 1, &HTTPPrint_topic2 },
|
||||
{ "clname2", sizeof("clname2") - 1, &HTTPPrint_clname2 },
|
||||
{ "clpass2", sizeof("clpass2") - 1, &HTTPPrint_clpass2 },
|
||||
#endif
|
||||
#endif
|
||||
/*ERROR report*/
|
||||
{ "status_fail", sizeof("status_fail") - 1, &HTTPPrint_status_fail },
|
||||
|
||||
};
|
||||
|
||||
|
||||
int HTTPPrint(httpd_req_t *req, char *buf, char *var)
|
||||
{
|
||||
char VarData[MAX_DYNVAR_LENGTH];
|
||||
|
|
|
|||
22
src/MQTT.c
22
src/MQTT.c
|
|
@ -42,19 +42,16 @@
|
|||
#define MAX_POST_DATA_LENTH 512
|
||||
#define MQTT_RECONNECT_CHANGE_ADAPTER 3
|
||||
|
||||
#if CONFIG_WEBGUIAPP_MQTT_ENABLE
|
||||
|
||||
static SemaphoreHandle_t xSemaphoreMQTTHandle = NULL;
|
||||
static StaticSemaphore_t xSemaphoreMQTTBuf;
|
||||
|
||||
static const int MQTT1_WAIT_DELIVERY_BIT = BIT0;
|
||||
static const int MQTT2_WAIT_DELIVERY_BIT = BIT1;
|
||||
|
||||
static StaticQueue_t xStaticMQTT1MessagesQueue;
|
||||
static StaticQueue_t xStaticMQTT2MessagesQueue;
|
||||
uint8_t MQTT1MessagesQueueStorageArea[CH_MESSAGE_BUFER_LENTH * sizeof(DATA_SEND_STRUCT)];
|
||||
uint8_t MQTT2MessagesQueueStorageArea[CH_MESSAGE_BUFER_LENTH * sizeof(DATA_SEND_STRUCT)];
|
||||
|
||||
|
||||
mqtt_client_t mqtt[MQTT_CLIENTS_NUM] = { 0 };
|
||||
mqtt_client_t mqtt[CONFIG_MQTT_CLIENTS_NUM] = { 0 };
|
||||
|
||||
static const char topic_tx[] = "/UPLINK/"; //subtopic for transmit
|
||||
static const char topic_rx[] = "/DOWNLINK/"; //subtopic to receive
|
||||
|
|
@ -274,7 +271,7 @@ static void reconnect_MQTT_handler(void *arg, esp_event_base_t event_base,
|
|||
int32_t event_id,
|
||||
void *event_data)
|
||||
{
|
||||
for (int i = 0; i < MQTT_CLIENTS_NUM; ++i)
|
||||
for (int i = 0; i < CONFIG_MQTT_CLIENTS_NUM; ++i)
|
||||
{
|
||||
if (mqtt[i].mqtt)
|
||||
{
|
||||
|
|
@ -569,7 +566,7 @@ api_json_err:
|
|||
|
||||
void MQTTStart(void)
|
||||
{
|
||||
for (int i = 0; i < MQTT_CLIENTS_NUM; ++i)
|
||||
for (int i = 0; i < CONFIG_MQTT_CLIENTS_NUM; ++i)
|
||||
{
|
||||
if (mqtt[i].mqtt)
|
||||
esp_mqtt_client_reconnect(mqtt[i].mqtt);
|
||||
|
|
@ -578,7 +575,7 @@ void MQTTStart(void)
|
|||
|
||||
void MQTTStop(void)
|
||||
{
|
||||
for (int i = 0; i < MQTT_CLIENTS_NUM; ++i)
|
||||
for (int i = 0; i < CONFIG_MQTT_CLIENTS_NUM; ++i)
|
||||
{
|
||||
if (mqtt[i].mqtt)
|
||||
esp_mqtt_client_disconnect(mqtt[i].mqtt);
|
||||
|
|
@ -587,7 +584,7 @@ void MQTTStop(void)
|
|||
|
||||
void MQTTReconnect(void)
|
||||
{
|
||||
for (int i = 0; i < MQTT_CLIENTS_NUM; ++i)
|
||||
for (int i = 0; i < CONFIG_MQTT_CLIENTS_NUM; ++i)
|
||||
{
|
||||
if (mqtt[i].mqtt)
|
||||
{
|
||||
|
|
@ -677,7 +674,7 @@ static void start_mqtt()
|
|||
char url[40];
|
||||
char tmp[40];
|
||||
|
||||
for (int i = 0; i < MQTT_CLIENTS_NUM; ++i)
|
||||
for (int i = 0; i < CONFIG_MQTT_CLIENTS_NUM; ++i)
|
||||
{
|
||||
if (GetSysConf()->mqttStation[i].Flags1.bIsGlobalEnabled)
|
||||
{
|
||||
|
|
@ -729,12 +726,11 @@ void MQTTRun(void)
|
|||
&xStaticMQTT2MessagesQueue);
|
||||
|
||||
mqtt[0].mqtt_queue = MQTT1MessagesQueueHandle;
|
||||
mqtt[0].wait_delivery_bit = MQTT1_WAIT_DELIVERY_BIT;
|
||||
mqtt[1].mqtt_queue = MQTT2MessagesQueueHandle;
|
||||
mqtt[1].wait_delivery_bit = MQTT2_WAIT_DELIVERY_BIT;
|
||||
|
||||
|
||||
|
||||
start_mqtt();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
static SYS_CONFIG SysConfig;
|
||||
|
||||
|
||||
static void ResetSysConfig(SYS_CONFIG *Conf)
|
||||
{
|
||||
#if CONFIG_WEBGUIAPP_WIFI_ENABLE
|
||||
|
|
@ -49,6 +48,38 @@ static void ResetSysConfig(SYS_CONFIG *Conf)
|
|||
Conf->wifiSettings.Flags1.bIsDHCPEnabled = CONFIG_WEBGUIAPP_WIFI_DHCP_ON;
|
||||
#endif
|
||||
|
||||
#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE
|
||||
Conf->ethSettings.Flags1.bIsETHEnabled = CONFIG_WEBGUIAPP_ETHERNET_ON;
|
||||
esp_netif_str_to_ip4(CONFIG_WEBGUIAPP_ETH_IP_DEFAULT, (esp_ip4_addr_t*) &Conf->ethSettings.IPAddr);
|
||||
esp_netif_str_to_ip4(CONFIG_WEBGUIAPP_ETH_MASK_DEFAULT, (esp_ip4_addr_t*) &Conf->ethSettings.Mask);
|
||||
esp_netif_str_to_ip4(CONFIG_WEBGUIAPP_ETH_GATEWAY_DEFAULT, (esp_ip4_addr_t*) &Conf->ethSettings.Gateway);
|
||||
Conf->ethSettings.Flags1.bIsDHCPEnabled = CONFIG_WEBGUIAPP_ETHERNET_DHCP_ON ;
|
||||
#endif
|
||||
|
||||
#if CONFIG_WEBGUIAPP_GPRS_ENABLE
|
||||
Conf->gsmSettings.Flags1.bIsGSMEnabled = true;
|
||||
|
||||
#endif
|
||||
|
||||
#if CONFIG_WEBGUIAPP_MQTT_ENABLE
|
||||
Conf->mqttStation[0].Flags1.bIsGlobalEnabled = CONFIG_MQTT_ON;
|
||||
memcpy(Conf->mqttStation[0].ServerAddr, CONFIG_MQTT_SERVER_URL, sizeof(CONFIG_MQTT_SERVER_URL));
|
||||
Conf->mqttStation[0].ServerPort = CONFIG_MQTT_SERVER_PORT;
|
||||
memcpy(Conf->mqttStation[0].ClientID, CONFIG_MQTT_CLIENT_ID_1, sizeof(CONFIG_MQTT_CLIENT_ID_1));
|
||||
memcpy(Conf->mqttStation[0].RootTopic, CONFIG_MQTT_ROOT_TOPIC, sizeof(CONFIG_MQTT_ROOT_TOPIC));
|
||||
memcpy(Conf->mqttStation[0].UserName, CONFIG_MQTT_USERNAME, sizeof(CONFIG_MQTT_USERNAME));
|
||||
memcpy(Conf->mqttStation[0].UserPass, CONFIG_MQTT_PASSWORD, sizeof(CONFIG_MQTT_PASSWORD));
|
||||
#if CONFIG_MQTT_CLIENTS_NUM == 2
|
||||
Conf->mqttStation[1].Flags1.bIsGlobalEnabled = CONFIG_MQTT_ON;
|
||||
memcpy(Conf->mqttStation[1].ServerAddr, CONFIG_MQTT_SERVER_URL, sizeof(CONFIG_MQTT_SERVER_URL));
|
||||
Conf->mqttStation[1].ServerPort = CONFIG_MQTT_SERVER_PORT;
|
||||
memcpy(Conf->mqttStation[1].ClientID, CONFIG_MQTT_CLIENT_ID_2, sizeof(CONFIG_MQTT_CLIENT_ID_2));
|
||||
memcpy(Conf->mqttStation[1].RootTopic, CONFIG_MQTT_ROOT_TOPIC, sizeof(CONFIG_MQTT_ROOT_TOPIC));
|
||||
memcpy(Conf->mqttStation[1].UserName, CONFIG_MQTT_USERNAME, sizeof(CONFIG_MQTT_USERNAME));
|
||||
memcpy(Conf->mqttStation[1].UserPass, CONFIG_MQTT_PASSWORD, sizeof(CONFIG_MQTT_PASSWORD));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
esp_err_t ReadNVSSysConfig(SYS_CONFIG *SysConf)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user