From 141f10ef33454ffdd4fae1ab4f46b5e33fedf309 Mon Sep 17 00:00:00 2001 From: Nikolaos Ftylitakis Date: Wed, 29 Sep 2021 11:21:06 +0300 Subject: [PATCH] change the default values of WebUI fields minor refactoring on web server global variable reading --- .../demo_console/templ/lora_config_templ.py | 6 +++--- insighioNode/lib/device_info/__init__.py | 2 +- insighioNode/lib/gpio_handler/__init__.py | 2 -- insighioNode/web_server.py | 18 ++++++++++-------- insighioNode/www/step-3-config-cellular.pyhtml | 4 ++-- insighioNode/www/step-5-measurements.html | 2 +- insighioNode/www/step-6-timing.html | 6 +++--- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/insighioNode/apps/demo_console/templ/lora_config_templ.py b/insighioNode/apps/demo_console/templ/lora_config_templ.py index 042e4e3..0b663e8 100644 --- a/insighioNode/apps/demo_console/templ/lora_config_templ.py +++ b/insighioNode/apps/demo_console/templ/lora_config_templ.py @@ -8,9 +8,9 @@ _MAX_CONNECTION_ATTEMPT_TIME_SEC = 60 """ LoRa-related configuration options """ -_DEV_EUI = '' -_APP_EUI = '' -_APP_KEY = '' +_DEV_EUI = "" +_APP_EUI = "" +_APP_KEY = "" from network import LoRa _LORA_REGION = LoRa. diff --git a/insighioNode/lib/device_info/__init__.py b/insighioNode/lib/device_info/__init__.py index f611fe4..0cfb9cd 100644 --- a/insighioNode/lib/device_info/__init__.py +++ b/insighioNode/lib/device_info/__init__.py @@ -62,7 +62,7 @@ def _try_get_lora_mac_bytes(force_init_region=False): def get_lora_mac(): """ Returns a device id based on lora mac in readable format and in raw format """ # valid only for lora compatible devices - if sys.platform in _LORA_COMPATIBLE_PLATFORMS: + if not is_esp32() and sys.platform in _LORA_COMPATIBLE_PLATFORMS: mac = _try_get_lora_mac_bytes() if mac is None: diff --git a/insighioNode/lib/gpio_handler/__init__.py b/insighioNode/lib/gpio_handler/__init__.py index 4d3a4e5..298ebcd 100644 --- a/insighioNode/lib/gpio_handler/__init__.py +++ b/insighioNode/lib/gpio_handler/__init__.py @@ -52,8 +52,6 @@ def get_input_voltage(pin, voltage_divider=1, attn=ADC.ATTN_11DB, measurement_cy return round((tmp / measurement_cycles) * voltage_divider) # typical voltage_divider levels: 3.054 --> Exp Board 2.0, 2 --> Exp Board 3, 11 --> in-house implementation - # should we use round function since the following division returns millivolt? - def get_vin(pin='P16'): """ A simple wrapper to take Vin for pycom modules (relevant only when an expansion board is used) """ diff --git a/insighioNode/web_server.py b/insighioNode/web_server.py index c4ab7fc..52a433c 100644 --- a/insighioNode/web_server.py +++ b/insighioNode/web_server.py @@ -8,6 +8,7 @@ import utils import machine import logging +import ure class WebServer: @@ -51,11 +52,12 @@ def __init__(self): device_info.set_defaults() def saveGlobalVarIfFoundInLine(self, line, strToSearch, globalVarName, delimiter): - if line.startswith(strToSearch): + if ure.match(strToSearch, line): + #if line.startswith(strToSearch): elems = line.split(delimiter) - logging.info(strToSearch + ": " + str(elems)) if len(elems) > 1 and elems[1] != "": self.pyhtmlMod.SetGlobalVar(globalVarName, elems[1]) + logging.debug("var '{}' = {}".format(globalVarName, elems[1])) return True return False @@ -71,10 +73,10 @@ def extractInsighioIds(self): self.pyhtmlMod.SetGlobalVar("insighioDeviceToken", "") while i < linesCount: - if (self.saveGlobalVarIfFoundInLine(projectConfig[i], ' protocol_config.message_channel_id', "insighioChannelId", '"') or - self.saveGlobalVarIfFoundInLine(projectConfig[i], ' protocol_config.control_channel_id', "insighioControlChannel", '"') or - self.saveGlobalVarIfFoundInLine(projectConfig[i], ' protocol_config.thing_id', "insighioDeviceId", '"') or - self.saveGlobalVarIfFoundInLine(projectConfig[i], ' protocol_config.thing_token', "insighioDeviceToken", '"')): + if (self.saveGlobalVarIfFoundInLine(projectConfig[i], r'^(\s*\w+\.)?message_channel_id', "insighioChannelId", '"') or + self.saveGlobalVarIfFoundInLine(projectConfig[i], r'^(\s*\w+\.)?control_channel_id', "insighioControlChannel", '"') or + self.saveGlobalVarIfFoundInLine(projectConfig[i], r'^(\s*\w+\.)?thing_id', "insighioDeviceId", '"') or + self.saveGlobalVarIfFoundInLine(projectConfig[i], r'^(\s*\w+\.)?thing_token', "insighioDeviceToken", '"')): euisFilled = euisFilled + 1 if euisFilled == 4: @@ -101,8 +103,8 @@ def extractLoRaUIDS(self): self.pyhtmlMod.SetGlobalVar("loraAppKey", "") while i < linesCount: - if (self.saveGlobalVarIfFoundInLine(projectConfig[i], '_APP_EUI', "loraAppEUI", "'") or - self.saveGlobalVarIfFoundInLine(projectConfig[i], '_APP_KEY', "loraAppKey", "'")): + if (self.saveGlobalVarIfFoundInLine(projectConfig[i], '_APP_EUI', "loraAppEUI", '"') or + self.saveGlobalVarIfFoundInLine(projectConfig[i], '_APP_KEY', "loraAppKey", '"')): euisFilled = euisFilled + 1 if euisFilled == 3: diff --git a/insighioNode/www/step-3-config-cellular.pyhtml b/insighioNode/www/step-3-config-cellular.pyhtml index 3c9ed97..ab6dd1c 100644 --- a/insighioNode/www/step-3-config-cellular.pyhtml +++ b/insighioNode/www/step-3-config-cellular.pyhtml @@ -69,7 +69,7 @@
- +


@@ -79,9 +79,9 @@
diff --git a/insighioNode/www/step-5-measurements.html b/insighioNode/www/step-5-measurements.html index 3c4ba47..40e484a 100644 --- a/insighioNode/www/step-5-measurements.html +++ b/insighioNode/www/step-5-measurements.html @@ -114,7 +114,7 @@
diff --git a/insighioNode/www/step-6-timing.html b/insighioNode/www/step-6-timing.html index 5dc6fef..f29a7aa 100644 --- a/insighioNode/www/step-6-timing.html +++ b/insighioNode/www/step-6-timing.html @@ -70,7 +70,7 @@
- +
@@ -95,7 +95,7 @@
@@ -111,7 +111,7 @@
- +