From a4f6abf0a634704f1e5173e4e42e504a148baf69 Mon Sep 17 00:00:00 2001 From: tubleronchik Date: Thu, 25 Apr 2024 13:06:08 +0300 Subject: [PATCH 1/2] add model field to the env box to support mobile option --- connectivity/src/sensors/environmental_box.py | 2 +- pyproject.toml | 1 + tests/gps_sensor_test.py | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/gps_sensor_test.py diff --git a/connectivity/src/sensors/environmental_box.py b/connectivity/src/sensors/environmental_box.py index d844506..8421640 100644 --- a/connectivity/src/sensors/environmental_box.py +++ b/connectivity/src/sensors/environmental_box.py @@ -20,7 +20,7 @@ def __post_init__(self) -> None: super().__post_init__() self.id = str(self.data["esp8266id"]) - self.model = SDS011_MODEL + self.model = self.data.get("model", SDS011_MODEL) self.public = self.generate_pubkey(str(self.id)) self.donated_by = str(self.data.get("donated_by", "")) sensors_data = self.data["sensordatavalues"] diff --git a/pyproject.toml b/pyproject.toml index f595fff..8356995 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,7 @@ test_environmental_box = "tests.environmental_box_test:main" test_mobile_lab = "tests.mobile_lab_test:main" test_many_sensors = "tests.many_environmental_boxes:main" test_lora_sensors = "tests.lora_sensor_test:main" +test_gps_sensor = "tests.gps_sensor_test:main" [build-system] requires = ["poetry_core>=1.0.0"] diff --git a/tests/gps_sensor_test.py b/tests/gps_sensor_test.py new file mode 100644 index 0000000..fc4e55e --- /dev/null +++ b/tests/gps_sensor_test.py @@ -0,0 +1,43 @@ +import json +import logging.config +import random +import time + +import requests + +from connectivity.config.logging import LOGGING_CONFIG + +logging.config.dictConfig(LOGGING_CONFIG) +logger = logging.getLogger(__name__) + +header = {"Content-type": "application/json"} + + +def main(): + lat = round(random.uniform(0.000000, 60.000000), 6) + lon = round(random.uniform(0.000000, 49.999999), 6) + humidity = round(random.uniform(0, 100)) + temperature = round(random.uniform(-50, 50), 3) + id = 666 + body = { + "esp8266id": id, + "software_version": "NRZ-2020-129", + "donated_by": "Robonomics", + "model": 3, + "sensordatavalues": [ + {"value_type": "temperature", "value": temperature}, + {"value_type": "humidity", "value": humidity}, + {"value_type": "samples", "value": "890618"}, + {"value_type": "min_micro", "value": "43"}, + {"value_type": "max_micro", "value": "21069"}, + {"value_type": "GPS_lat", "value": lat}, + {"value_type": "GPS_lon", "value": lon}, + {"value_type": "signal", "value": "-46"}, + ], + } + + try: + response = requests.post("http://127.0.0.1:31112/", data=json.dumps(body), headers=header) + except Exception as e: + logger.warning(e) + pass From 22aa47242e81750d84498da36b57211e5ffbe3e6 Mon Sep 17 00:00:00 2001 From: tubleronchik Date: Thu, 25 Apr 2024 13:06:43 +0300 Subject: [PATCH 2/2] bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8356995..4a60344 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sensors_connectivity" -version = "1.6.0" +version = "1.6.1" description = "Robonomics package to read data from sensors and publish to different output channels" authors = [ "Vadim Manaenko ",