Skip to content

Commit

Permalink
Merge pull request #527 from bakerstu/openmrnlite
Browse files Browse the repository at this point in the history
Upintegrate the openmrn-lite changes to master
  • Loading branch information
balazsracz authored Apr 5, 2021
2 parents c09a153 + 7e7a509 commit 90a9d59
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion arduino/examples/ESP32IOBoard/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ using AllProducers = RepeatedGroup<ProducerConfig, NUM_INPUTS>;

/// 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.
Expand Down
2 changes: 1 addition & 1 deletion arduino/examples/ESP32WifiCanBridge/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion arduino/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion arduino/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=OpenMRNLite
version=1.0.2
version=1.0.3
author=Stuart Baker, Mike Dunston, Balazs Racz
maintainer=Mike Dunston <[email protected]>, Balazs Racz <[email protected]>
includes=OpenMRNLite.h
Expand Down
29 changes: 18 additions & 11 deletions src/freertos_drivers/esp32/Esp32WiFiConfiguration.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.";

/// <map> of possible keys and descriptive values to show to the user for
/// the connection_mode fields.
static constexpr const char *CONN_MODE_MAP =
"<relation><property>1</property><value>Uplink Only</value></relation>"
"<relation><property>2</property><value>Hub Only</value></relation>"
"<relation><property>3</property><value>Hub+Uplink</value></relation>";

/// Visible name for the hub_listener_port field.
static constexpr const char *HUB_LISTENER_PORT_NAME = "Hub Listener Port";

Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -135,4 +142,4 @@ CDI_GROUP_END();

using openmrn_arduino::WiFiConfiguration;

#endif // _FREERTOS_DRIVERS_ESP32_ESP32WIFICONFIG_HXX_
#endif // _FREERTOS_DRIVERS_ESP32_ESP32WIFICONFIG_HXX_
30 changes: 21 additions & 9 deletions src/freertos_drivers/esp32/Esp32WiFiManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,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);
Expand Down Expand Up @@ -533,10 +533,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
Expand Down Expand Up @@ -983,13 +980,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;
}

Expand Down Expand Up @@ -1153,7 +1165,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
Expand Down

0 comments on commit 90a9d59

Please sign in to comment.