Skip to content

Commit

Permalink
CR1000X Datalogger Implementation (#5)
Browse files Browse the repository at this point in the history
This pull request includes the necessary changes to implement a CR1000X datalogger device type in the swarm. The difference between the base device and the CR1000X is mostly the output format of MQTT messages.

* NEW: Implemented CR1000X device. The device closely matches the messaging format of a real datalogger, its serial number is produced by converting the `device_id` into ASCII codes separated by dashes. e.g. "MORLY" becomes `77-79-82-76-89`. For each "field" of the logger, the most likely XML type is calculated from the data and the aggregation process is assumed based on the field name: "Temp_Std" will assume standard deviation aggregation.
* NEW: Refactored codebase for looser coupling between swarm classes and device classes. Swarm now just handles the orchestration of devices, not instantiation.
* NEW: CLI now allows for the selection of device type used with the argument `--device-type`.
* NEW: Expanded testing coverage.
  • Loading branch information
lewis-chambers authored Jun 11, 2024
1 parent 7d69d75 commit a273e51
Show file tree
Hide file tree
Showing 33 changed files with 2,156 additions and 1,003 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/doc-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
pip install .[docs]
- name: Build Docs
run: |
python -c "import iotdevicesimulator; print(iotdevicesimulator.__version__)"
python -c "import iotswarm; print(iotswarm.__version__)"
pushd docs
. ./make.sh build
- name: Upload artifact
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/doc-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ jobs:
pip install .[docs]
- name: Build Docs
run: |
python -c "import iotdevicesimulator; print(iotdevicesimulator.__version__)"
python -c "import iotswarm; print(iotswarm.__version__)"
pushd docs
. ./make.sh build
20 changes: 0 additions & 20 deletions docs/Makefile

This file was deleted.

6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
path = os.path.abspath("../src")
sys.path.append(path)
print(path)
import iotdevicesimulator
import iotswarm

project = "IoT Thing Swarm"
project = "IoT Swarm"
copyright = "2024, Lewis Chambers"
author = "Lewis Chambers"
release = iotdevicesimulator.__version__
release = iotswarm.__version__
version = release
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
39 changes: 25 additions & 14 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Install this package via pip:
pip install git+https://github.com/NERC-CEH/iot-swarm.git
This installs the package :python:`iotdevicesimulator` into your python environment.
This installs the package :python:`iotswarm` into your python environment.

-------------
Using The CLI
Expand Down Expand Up @@ -94,9 +94,11 @@ To create an IoT Swarm you must write a script such as the following:

.. code-block:: python
from iotdevicesimulator.queries import CosmosQuery
from iotdevicesimulator.swarm import CosmosSwarm
from iotdevicesimulator.mqtt.aws import IotCoreMQTTConnection
from iotswarm.queries import CosmosQuery, CosmosSiteQuery
from iotswarm.swarm import Swarm
from iotswarm import devices
from iotswarm.messaging.aws import IotCoreMQTTConnection
from iotswarm import db
import asyncio
import config
from pathlib import Path
Expand All @@ -118,23 +120,31 @@ To create an IoT Swarm you must write a script such as the following:
iot_config = app_config["iot_core"]
oracle_config = app_config["oracle"]
data_source = await db.Oracle.create(
oracle_config["dsn"], oracle_config["user"], oracle_config["password"]
)
site_query = CosmosSiteQuery.LEVEL_1_SOILMET_30MIN
query = CosmosQuery[site_query.name]
device_ids = await data_source.query_site_ids(site_query, max_sites=5)
mqtt_connection = IotCoreMQTTConnection(
endpoint=iot_config["endpoint"],
cert_path=iot_config["cert_path"],
key_path=iot_config["key_path"],
ca_cert_path=iot_config["ca_cert_path"],
client_id="fdri_swarm",
)
swarm = await CosmosSwarm.create(
CosmosQuery.LEVEL_1_SOILMET_30MIN,
mqtt_connection,
swarm_name="soilmet",
delay_start=True,
max_cycles=5,
max_sites=5,
sleep_time=30,
credentials=oracle_config,
)
device_objs = [
devices.CR1000XDevice(
site, data_source, mqtt_connection, query=query, sleep_time=5
)
for site in device_ids
]
swarm = Swarm(device_objs, name="soilmet")
await swarm.run()
Expand All @@ -144,6 +154,7 @@ To create an IoT Swarm you must write a script such as the following:
asyncio.run(main(config_path))
This instantiates and runs a swarm of 5 sites from the COSMOS database that
each run for 5 cycles of queries and wait for 30 seconds between queries.

Expand Down
36 changes: 0 additions & 36 deletions docs/make.bat

This file was deleted.

2 changes: 1 addition & 1 deletion docs/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function apidoc() {
args="--module-first --force"
fi

sphinx-apidoc $(echo $args) -o source ../src/iotdevicesimulator '../src/iotdevicesimulator/scripts/*'
sphinx-apidoc $(echo $args) -o source ../src/iotswarm '../src/iotswarm/scripts/*'
}

function build() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
iotdevicesimulator.messaging package
iotswarm.messaging package
====================================

.. automodule:: iotdevicesimulator.messaging
.. automodule:: iotswarm.messaging
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

iotdevicesimulator.messaging.aws module
iotswarm.messaging.aws module
---------------------------------------

.. automodule:: iotdevicesimulator.messaging.aws
.. automodule:: iotswarm.messaging.aws
:members:
:undoc-members:
:show-inheritance:

iotdevicesimulator.messaging.core module
iotswarm.messaging.core module
----------------------------------------

.. automodule:: iotdevicesimulator.messaging.core
.. automodule:: iotswarm.messaging.core
:members:
:undoc-members:
:show-inheritance:
32 changes: 16 additions & 16 deletions docs/source/iotdevicesimulator.rst → docs/source/iotswarm.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
iotdevicesimulator package
iotswarm package
==========================

.. automodule:: iotdevicesimulator
.. automodule:: iotswarm
:members:
:undoc-members:
:show-inheritance:
Expand All @@ -12,56 +12,56 @@ Subpackages
.. toctree::
:maxdepth: 4

iotdevicesimulator.messaging
iotdevicesimulator.scripts
iotswarm.messaging
iotswarm.scripts

Submodules
----------

iotdevicesimulator.db module
iotswarm.db module
----------------------------

.. automodule:: iotdevicesimulator.db
.. automodule:: iotswarm.db
:members:
:undoc-members:
:show-inheritance:

iotdevicesimulator.devices module
iotswarm.devices module
---------------------------------

.. automodule:: iotdevicesimulator.devices
.. automodule:: iotswarm.devices
:members:
:undoc-members:
:show-inheritance:

iotdevicesimulator.example module
iotswarm.example module
---------------------------------

.. automodule:: iotdevicesimulator.example
.. automodule:: iotswarm.example
:members:
:undoc-members:
:show-inheritance:

iotdevicesimulator.loggers module
iotswarm.loggers module
---------------------------------

.. automodule:: iotdevicesimulator.loggers
.. automodule:: iotswarm.loggers
:members:
:undoc-members:
:show-inheritance:

iotdevicesimulator.queries module
iotswarm.queries module
---------------------------------

.. automodule:: iotdevicesimulator.queries
.. automodule:: iotswarm.queries
:members:
:undoc-members:
:show-inheritance:

iotdevicesimulator.swarm module
iotswarm.swarm module
-------------------------------

.. automodule:: iotdevicesimulator.swarm
.. automodule:: iotswarm.swarm
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
iotdevicesimulator.scripts package
iotswarm.scripts package
==================================

Submodules
----------

iotdevicesimulator.scripts.cli module
iotswarm.scripts.cli module
-------------------------------------

.. click:: iotdevicesimulator.scripts.cli:main
.. click:: iotswarm.scripts.cli:main
:prog: iot-swarm
:nested: full

Module contents
---------------

.. automodule:: iotdevicesimulator.scripts
.. automodule:: iotswarm.scripts
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/source/modules.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
iotdevicesimulator
==================
iotswarm
========

.. toctree::
:maxdepth: 4

iotdevicesimulator
iotswarm
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies = [
"oracledb",
"backoff",
]
name = "iot-device-simulator"
name = "iot-swarm"
dynamic = ["version"]
authors = [{ name = "Lewis Chambers", email = "[email protected]" }]
description = "Package for simulating a net of IoT devices for stress testing."
Expand All @@ -24,9 +24,9 @@ test = ["pytest", "pytest-cov", "pytest-asyncio", "parameterized"]
docs = ["sphinx", "sphinx-copybutton", "sphinx-rtd-theme", "sphinx-click"]

[project.scripts]
iot-swarm = "iotdevicesimulator.scripts.cli:main"
iot-swarm = "iotswarm.scripts.cli:main"
[tool.setuptools.dynamic]
version = { attr = "iotdevicesimulator.__version__" }
version = { attr = "iotswarm.__version__" }

[tool.setuptools.packages.find]
where = ["src"]
Expand All @@ -40,12 +40,12 @@ filterwarnings = [
"ignore::DeprecationWarning:autosemver.*:",
"ignore::DeprecationWarning:pkg_resources.*:",
]
addopts = "--cov=iotdevicesimulator"
addopts = "--cov=iotswarm"
markers = [
"asyncio: Tests asynchronous functions.",
"oracle: Requires oracle connection and required config credentials",
"slow: Marks slow tests",
]

[tool.coverage.run]
omit = ["*example.py", "*__init__.py", "queries.py", "loggers.py"]
omit = ["*example.py", "*__init__.py", "queries.py", "loggers.py", "cli.py"]
Loading

0 comments on commit a273e51

Please sign in to comment.