diff --git a/Kconfig b/Kconfig index fae58ea..4804e26 100644 --- a/Kconfig +++ b/Kconfig @@ -762,6 +762,26 @@ menu "WebGUIApp" endif endmenu + menu "Modbus settings" + config WEBGUIAPP_MBTCP_ENABLED + bool "Enabled modbus TCP" + default n + help + Set enabled Modbus TCP + + if WEBGUIAPP_MBTCP_ENABLED + config WEBGUIAPP_MBTCP_ON + bool "Default modbus TCP switched on" + default y + + config WEBGUIAPP_MBTCP_SERVER_PORT + int "Modbus TCP server port" + range 1 65535 + default 502 + endif + endmenu + + menu "MQTT settings" config WEBGUIAPP_MQTT_ENABLE diff --git a/include/SysConfiguration.h b/include/SysConfiguration.h index 81a6598..55dcee3 100644 --- a/include/SysConfiguration.h +++ b/include/SysConfiguration.h @@ -201,6 +201,13 @@ typedef struct } lorawanSettings; + struct + { + bool IsModbusTCPEnabled; + int ModbusTCPPort; + + } modbusSettings; + } SYS_CONFIG; diff --git a/src/RestApiHandler.c b/src/RestApiHandler.c index 9103724..7dec6bf 100644 --- a/src/RestApiHandler.c +++ b/src/RestApiHandler.c @@ -425,8 +425,16 @@ const rest_var_t SystemVariables[] = { 0, "lora_visible", (bool*) (&VAR_FALSE), VAR_BOOL, RW, 0, 1 }, #endif +#ifdef CONFIG_WEBGUIAPP_MBTCP_ENABLED + { 0, "mbtcp_enab", &SysConfig.modbusSettings.IsModbusTCPEnabled, VAR_BOOL, RW, 0, 1 }, + { 0, "mbtcp_port", &SysConfig.modbusSettings.ModbusTCPPort, VAR_INT, RW, 1, 65534 }, + { 0, "mbtcp_visible", (bool*) (&VAR_TRUE), VAR_BOOL, RW, 0, 1 }, +#else + { 0, "mbtcp_visible", (bool*) (&VAR_FALSE), VAR_BOOL, RW, 0, 1 }, +#endif }; + esp_err_t SetConfVar(char *name, char *val, rest_var_types *tp) { rest_var_t *V = NULL; diff --git a/src/SysConfiguration.c b/src/SysConfiguration.c index 10aac47..c35e96e 100644 --- a/src/SysConfiguration.c +++ b/src/SysConfiguration.c @@ -385,6 +385,14 @@ esp_netif_str_to_ip4(CONFIG_WEBGUIAPP_DNS3_ADDRESS_DEFAULT, (esp_ip4_addr_t*) &C memcpy(Conf->lorawanSettings.AppEui, temp, 8); #endif +#ifdef CONFIG_WEBGUIAPP_MBTCP_ENABLED + Conf->modbusSettings.IsModbusTCPEnabled = false; +#if CONFIG_WEBGUIAPP_MBTCP_ON == 1 + Conf->modbusSettings.IsModbusTCPEnabled = true; +#endif + Conf->modbusSettings.ModbusTCPPort = CONFIG_WEBGUIAPP_MBTCP_SERVER_PORT; +#endif + } esp_err_t ReadNVSSysConfig(SYS_CONFIG *SysConf)