From 37157c0571a5331c5bab7a962924007adf0a075b Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Sun, 4 Apr 2021 13:58:33 +0200 Subject: [PATCH 1/4] Fix incorrect test for IDF version. (#523) --- src/freertos_drivers/esp32/Esp32WiFiManager.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/freertos_drivers/esp32/Esp32WiFiManager.cxx b/src/freertos_drivers/esp32/Esp32WiFiManager.cxx index a7c36cc14..9818a4afd 100644 --- a/src/freertos_drivers/esp32/Esp32WiFiManager.cxx +++ b/src/freertos_drivers/esp32/Esp32WiFiManager.cxx @@ -50,7 +50,7 @@ // ESP-IDF v4+ has a slightly different directory structure to previous // versions. -#ifdef ESP_IDF_VERSION_MAJOR +#if ESP_IDF_VERSION_MAJOR >= 4 // ESP-IDF v4+ #include #include From 46596b6f385b77aa4a46f23ed90d7e99da69b693 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Sun, 4 Apr 2021 14:21:50 +0200 Subject: [PATCH 2/4] Fix os_thread_create_helper for arduino esp32 (#524) Fix code that runs for task creation when a freertos config that enables static allocation. The previous code was probably never compiled because it had an undeclared variable. --- src/os/os.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/os/os.c b/src/os/os.c index d4d04b6af..8b5541008 100644 --- a/src/os/os.c +++ b/src/os/os.c @@ -421,17 +421,15 @@ int __attribute__((weak)) os_thread_create_helper(os_thread_t *thread, void *priv) { HASSERT(thread); -#if (configSUPPORT_STATIC_ALLOCATION == 1) +#if (configSUPPORT_DYNAMIC_ALLOCATION == 1) + xTaskCreate(os_thread_start, (const char *const)name, + stack_size/sizeof(portSTACK_TYPE), priv, priority, thread); +#elif (configSUPPORT_STATIC_ALLOCATION == 1) *thread = xTaskCreateStatic(os_thread_start, (const char *const)name, stack_size/sizeof(portSTACK_TYPE), priv, priority, (StackType_t *)stack_malloc(stack_size), (StaticTask_t *) malloc(sizeof(StaticTask_t))); - task_new->task = *thread; - task_new->name = (char*)pcTaskGetTaskName(*thread); -#elif (configSUPPORT_DYNAMIC_ALLOCATION == 1) - xTaskCreate(os_thread_start, (const char *const)name, - stack_size/sizeof(portSTACK_TYPE), priv, priority, thread); #else #error FREERTOS version v9.0.0 or later required #endif From 9a1c99ec451fc8f0a7ccd28553b8ef049043c86c Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Sun, 4 Apr 2021 14:27:44 +0200 Subject: [PATCH 3/4] Bump openmrnlite version number. --- arduino/library.json | 2 +- arduino/library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arduino/library.json b/arduino/library.json index d5ee19e10..c6d1c12a6 100644 --- a/arduino/library.json +++ b/arduino/library.json @@ -21,7 +21,7 @@ "type": "git", "url": "https://github.com/openmrn/OpenMRNLite" }, - "version": "1.0.2", + "version": "1.0.3", "license": "BSD-2-Clause", "frameworks": "arduino", "platforms": "espressif32", diff --git a/arduino/library.properties b/arduino/library.properties index b53693432..26e825065 100644 --- a/arduino/library.properties +++ b/arduino/library.properties @@ -1,5 +1,5 @@ name=OpenMRNLite -version=1.0.2 +version=1.0.3 author=Stuart Baker, Mike Dunston, Balazs Racz maintainer=Mike Dunston , Balazs Racz includes=OpenMRNLite.h From 6f827513824a2fad95744b4ad39fce189f7ea3fd Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Mon, 5 Apr 2021 19:43:51 +0200 Subject: [PATCH 4/4] WiFi manager uplink disable (#526) * Makes the wifi manager operate in one of three modes: - uplink only - hub+uplink - hub only Previously the uplink could not be disabled, which causes massive problems in a hub-only application. * update version --- arduino/examples/ESP32IOBoard/config.h | 2 +- arduino/examples/ESP32WifiCanBridge/config.h | 2 +- .../esp32/Esp32WiFiConfiguration.hxx | 29 +++++++++++------- .../esp32/Esp32WiFiManager.cxx | 30 +++++++++++++------ 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/arduino/examples/ESP32IOBoard/config.h b/arduino/examples/ESP32IOBoard/config.h index 6884c7fd4..a9ac639d9 100644 --- a/arduino/examples/ESP32IOBoard/config.h +++ b/arduino/examples/ESP32IOBoard/config.h @@ -56,7 +56,7 @@ using AllProducers = RepeatedGroup; /// Modify this value every time the EEPROM needs to be cleared on the node /// after an update. -static constexpr uint16_t CANONICAL_VERSION = 0x1000; +static constexpr uint16_t CANONICAL_VERSION = 0x1002; /// Defines the main segment in the configuration CDI. This is laid out at /// origin 128 to give space for the ACDI user data at the beginning. diff --git a/arduino/examples/ESP32WifiCanBridge/config.h b/arduino/examples/ESP32WifiCanBridge/config.h index 045980397..ea3e127a4 100644 --- a/arduino/examples/ESP32WifiCanBridge/config.h +++ b/arduino/examples/ESP32WifiCanBridge/config.h @@ -33,7 +33,7 @@ extern const SimpleNodeStaticValues SNIP_STATIC_DATA = { /// Modify this value every time the EEPROM needs to be cleared on the node /// after an update. -static constexpr uint16_t CANONICAL_VERSION = 0x1000; +static constexpr uint16_t CANONICAL_VERSION = 0x1002; /// Defines the main segment in the configuration CDI. This is laid out at /// origin 128 to give space for the ACDI user data at the beginning. diff --git a/src/freertos_drivers/esp32/Esp32WiFiConfiguration.hxx b/src/freertos_drivers/esp32/Esp32WiFiConfiguration.hxx index 4ef873840..72a4ba10d 100644 --- a/src/freertos_drivers/esp32/Esp32WiFiConfiguration.hxx +++ b/src/freertos_drivers/esp32/Esp32WiFiConfiguration.hxx @@ -69,13 +69,20 @@ public: static constexpr const char *HUB_DESC = "Configuration settings for an OpenLCB Hub"; - /// Visible name for the hub enable field. - static constexpr const char *HUB_ENABLE_NAME = "Enable Hub Mode"; + /// Visible name for the hub/uplink enable field. + static constexpr const char *CONN_MODE_NAME = "Connection Mode"; - /// Visible description for the hub enable field. - static constexpr const char *HUB_ENABLE_DESC = - "Defines this node as a hub which can accept connections"; + /// Visible description for the hub/uplink enable field. + static constexpr const char *CONN_MODE_DESC = + "Defines whether to allow accepting connections (according to the Hub configuration), making a connection (according to the Uplink configuration), or both."; + /// of possible keys and descriptive values to show to the user for + /// the connection_mode fields. + static constexpr const char *CONN_MODE_MAP = + "1Uplink Only" + "2Hub Only" + "3Hub+Uplink"; + /// Visible name for the hub_listener_port field. static constexpr const char *HUB_LISTENER_PORT_NAME = "Hub Listener Port"; @@ -94,11 +101,6 @@ public: /// CDI Configuration for an @ref Esp32WiFiManager managed hub. CDI_GROUP(HubConfiguration); -/// Allows the node to become a Grid Connect Hub. -CDI_GROUP_ENTRY(enable, openlcb::Uint8ConfigEntry, - Name(Esp32WiFiConfigurationParams::HUB_ENABLE_NAME), - Description(Esp32WiFiConfigurationParams::HUB_ENABLE_DESC), Min(0), Max(1), - Default(0), MapValues(Esp32WiFiConfigurationParams::BOOLEAN_MAP)); /// Specifies the port which should be used by the hub. CDI_GROUP_ENTRY(port, openlcb::Uint16ConfigEntry, Name(Esp32WiFiConfigurationParams::HUB_LISTENER_PORT_NAME), @@ -120,6 +122,11 @@ CDI_GROUP_ENTRY(sleep, openlcb::Uint8ConfigEntry, Name(Esp32WiFiConfigurationParams::WIFI_POWER_SAVE_NAME), Description(Esp32WiFiConfigurationParams::WIFI_POWER_SAVE_DESC), Min(0), Max(1), Default(0), MapValues(Esp32WiFiConfigurationParams::BOOLEAN_MAP)); +/// Defines configuration of hub or uplink +CDI_GROUP_ENTRY(connection_mode, openlcb::Uint8ConfigEntry, + Name(Esp32WiFiConfigurationParams::CONN_MODE_NAME), + Description(Esp32WiFiConfigurationParams::CONN_MODE_DESC), Min(1), Max(3), + Default(1), MapValues(Esp32WiFiConfigurationParams::CONN_MODE_MAP)); /// CDI Configuration to enable this node to be a hub. CDI_GROUP_ENTRY(hub, HubConfiguration, Name(Esp32WiFiConfigurationParams::HUB_NAME), @@ -135,4 +142,4 @@ CDI_GROUP_END(); using openmrn_arduino::WiFiConfiguration; -#endif // _FREERTOS_DRIVERS_ESP32_ESP32WIFICONFIG_HXX_ \ No newline at end of file +#endif // _FREERTOS_DRIVERS_ESP32_ESP32WIFICONFIG_HXX_ diff --git a/src/freertos_drivers/esp32/Esp32WiFiManager.cxx b/src/freertos_drivers/esp32/Esp32WiFiManager.cxx index 9818a4afd..4c9a915d8 100644 --- a/src/freertos_drivers/esp32/Esp32WiFiManager.cxx +++ b/src/freertos_drivers/esp32/Esp32WiFiManager.cxx @@ -403,9 +403,9 @@ void Esp32WiFiManager::factory_reset(int fd) // General WiFi configuration settings. CDI_FACTORY_RESET(cfg_.sleep); + CDI_FACTORY_RESET(cfg_.connection_mode); // Hub specific configuration settings. - CDI_FACTORY_RESET(cfg_.hub().enable); CDI_FACTORY_RESET(cfg_.hub().port); cfg_.hub().service_name().write( fd, TcpDefs::MDNS_SERVICE_NAME_GRIDCONNECT_CAN_TCP); @@ -508,10 +508,7 @@ void Esp32WiFiManager::process_wifi_event(system_event_t *event) // Retrieve the configured IP address from the TCP/IP stack. tcpip_adapter_ip_info_t ip_info; tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info); - LOG(INFO, - "[WiFi] IP address is " IPSTR ", starting hub (if enabled) and " - "uplink.", - IP2STR(&ip_info.ip)); + LOG(INFO, "[WiFi] IP address is " IPSTR ".", IP2STR(&ip_info.ip)); // Start the mDNS system since we have an IP address, the mDNS system // on the ESP32 requires that the IP address be assigned otherwise it @@ -958,13 +955,28 @@ void *Esp32WiFiManager::wifi_manager_task(void *param) ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE)); } - if (CDI_READ_TRIMMED(wifi->cfg_.hub().enable, wifi->configFd_)) + bool have_hub = false; + uint8_t conn_cfg = CDI_READ_TRIMMED(wifi->cfg_.connection_mode, + wifi->configFd_); + if (conn_cfg & 2) { + LOG(INFO, "[WiFi] Starting hub."); // Since hub mode is enabled start the HUB creation process. wifi->start_hub(); + have_hub = true; + } else { + LOG(INFO, "[WiFi] Hub disabled by configuration."); + } + if (conn_cfg & 1) { + LOG(INFO, "[WiFi] Starting uplink."); + wifi->start_uplink(); + } else if (!have_hub) { + LOG(INFO, "[WiFi] Starting uplink, because hub is disabled."); + wifi->start_uplink(); + } else { + LOG(INFO, "[WiFi] Uplink disabled by configuration."); } - // Start the uplink connection process in the background. - wifi->start_uplink(); + wifi->configReloadRequested_ = false; } @@ -1128,7 +1140,7 @@ void Esp32WiFiManager::mdns_publish(string service, const uint16_t port) split_mdns_service_name(&service_name, &protocol_name); esp_err_t res = mdns_service_add( NULL, service_name.c_str(), protocol_name.c_str(), port, NULL, 0); - LOG(VERBOSE, "[mDNS] mdns_service_add(%s.%s:%d): %s." + LOG(INFO, "[mDNS] mdns_service_add(%s.%s:%d): %s." , service_name.c_str(), protocol_name.c_str(), port , esp_err_to_name(res)); // ESP_FAIL will be triggered if there is a timeout during publish of