Skip to content

Commit a273e51

Browse files
CR1000X Datalogger Implementation (#5)
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.
1 parent 7d69d75 commit a273e51

33 files changed

+2156
-1003
lines changed

.github/workflows/doc-deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
pip install .[docs]
5555
- name: Build Docs
5656
run: |
57-
python -c "import iotdevicesimulator; print(iotdevicesimulator.__version__)"
57+
python -c "import iotswarm; print(iotswarm.__version__)"
5858
pushd docs
5959
. ./make.sh build
6060
- name: Upload artifact

.github/workflows/doc-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ jobs:
2525
pip install .[docs]
2626
- name: Build Docs
2727
run: |
28-
python -c "import iotdevicesimulator; print(iotdevicesimulator.__version__)"
28+
python -c "import iotswarm; print(iotswarm.__version__)"
2929
pushd docs
3030
. ./make.sh build

docs/Makefile

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
path = os.path.abspath("../src")
1212
sys.path.append(path)
1313
print(path)
14-
import iotdevicesimulator
14+
import iotswarm
1515

16-
project = "IoT Thing Swarm"
16+
project = "IoT Swarm"
1717
copyright = "2024, Lewis Chambers"
1818
author = "Lewis Chambers"
19-
release = iotdevicesimulator.__version__
19+
release = iotswarm.__version__
2020
version = release
2121
# -- General configuration ---------------------------------------------------
2222
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

docs/index.rst

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Install this package via pip:
4444
4545
pip install git+https://github.com/NERC-CEH/iot-swarm.git
4646
47-
This installs the package :python:`iotdevicesimulator` into your python environment.
47+
This installs the package :python:`iotswarm` into your python environment.
4848

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

9595
.. code-block:: python
9696
97-
from iotdevicesimulator.queries import CosmosQuery
98-
from iotdevicesimulator.swarm import CosmosSwarm
99-
from iotdevicesimulator.mqtt.aws import IotCoreMQTTConnection
97+
from iotswarm.queries import CosmosQuery, CosmosSiteQuery
98+
from iotswarm.swarm import Swarm
99+
from iotswarm import devices
100+
from iotswarm.messaging.aws import IotCoreMQTTConnection
101+
from iotswarm import db
100102
import asyncio
101103
import config
102104
from pathlib import Path
@@ -118,23 +120,31 @@ To create an IoT Swarm you must write a script such as the following:
118120
iot_config = app_config["iot_core"]
119121
oracle_config = app_config["oracle"]
120122
123+
data_source = await db.Oracle.create(
124+
oracle_config["dsn"], oracle_config["user"], oracle_config["password"]
125+
)
126+
127+
site_query = CosmosSiteQuery.LEVEL_1_SOILMET_30MIN
128+
query = CosmosQuery[site_query.name]
129+
130+
device_ids = await data_source.query_site_ids(site_query, max_sites=5)
131+
121132
mqtt_connection = IotCoreMQTTConnection(
122133
endpoint=iot_config["endpoint"],
123134
cert_path=iot_config["cert_path"],
124135
key_path=iot_config["key_path"],
125136
ca_cert_path=iot_config["ca_cert_path"],
126137
client_id="fdri_swarm",
127138
)
128-
swarm = await CosmosSwarm.create(
129-
CosmosQuery.LEVEL_1_SOILMET_30MIN,
130-
mqtt_connection,
131-
swarm_name="soilmet",
132-
delay_start=True,
133-
max_cycles=5,
134-
max_sites=5,
135-
sleep_time=30,
136-
credentials=oracle_config,
137-
)
139+
140+
device_objs = [
141+
devices.CR1000XDevice(
142+
site, data_source, mqtt_connection, query=query, sleep_time=5
143+
)
144+
for site in device_ids
145+
]
146+
147+
swarm = Swarm(device_objs, name="soilmet")
138148
await swarm.run()
139149
140150
@@ -144,6 +154,7 @@ To create an IoT Swarm you must write a script such as the following:
144154
asyncio.run(main(config_path))
145155
146156
157+
147158
This instantiates and runs a swarm of 5 sites from the COSMOS database that
148159
each run for 5 cycles of queries and wait for 30 seconds between queries.
149160

docs/make.bat

Lines changed: 0 additions & 36 deletions
This file was deleted.

docs/make.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function apidoc() {
1515
args="--module-first --force"
1616
fi
1717

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

2121
function build() {
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
iotdevicesimulator.messaging package
1+
iotswarm.messaging package
22
====================================
33

4-
.. automodule:: iotdevicesimulator.messaging
4+
.. automodule:: iotswarm.messaging
55
:members:
66
:undoc-members:
77
:show-inheritance:
88

99
Submodules
1010
----------
1111

12-
iotdevicesimulator.messaging.aws module
12+
iotswarm.messaging.aws module
1313
---------------------------------------
1414

15-
.. automodule:: iotdevicesimulator.messaging.aws
15+
.. automodule:: iotswarm.messaging.aws
1616
:members:
1717
:undoc-members:
1818
:show-inheritance:
1919

20-
iotdevicesimulator.messaging.core module
20+
iotswarm.messaging.core module
2121
----------------------------------------
2222

23-
.. automodule:: iotdevicesimulator.messaging.core
23+
.. automodule:: iotswarm.messaging.core
2424
:members:
2525
:undoc-members:
2626
:show-inheritance:
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
iotdevicesimulator package
1+
iotswarm package
22
==========================
33

4-
.. automodule:: iotdevicesimulator
4+
.. automodule:: iotswarm
55
:members:
66
:undoc-members:
77
:show-inheritance:
@@ -12,56 +12,56 @@ Subpackages
1212
.. toctree::
1313
:maxdepth: 4
1414

15-
iotdevicesimulator.messaging
16-
iotdevicesimulator.scripts
15+
iotswarm.messaging
16+
iotswarm.scripts
1717

1818
Submodules
1919
----------
2020

21-
iotdevicesimulator.db module
21+
iotswarm.db module
2222
----------------------------
2323

24-
.. automodule:: iotdevicesimulator.db
24+
.. automodule:: iotswarm.db
2525
:members:
2626
:undoc-members:
2727
:show-inheritance:
2828

29-
iotdevicesimulator.devices module
29+
iotswarm.devices module
3030
---------------------------------
3131

32-
.. automodule:: iotdevicesimulator.devices
32+
.. automodule:: iotswarm.devices
3333
:members:
3434
:undoc-members:
3535
:show-inheritance:
3636

37-
iotdevicesimulator.example module
37+
iotswarm.example module
3838
---------------------------------
3939

40-
.. automodule:: iotdevicesimulator.example
40+
.. automodule:: iotswarm.example
4141
:members:
4242
:undoc-members:
4343
:show-inheritance:
4444

45-
iotdevicesimulator.loggers module
45+
iotswarm.loggers module
4646
---------------------------------
4747

48-
.. automodule:: iotdevicesimulator.loggers
48+
.. automodule:: iotswarm.loggers
4949
:members:
5050
:undoc-members:
5151
:show-inheritance:
5252

53-
iotdevicesimulator.queries module
53+
iotswarm.queries module
5454
---------------------------------
5555

56-
.. automodule:: iotdevicesimulator.queries
56+
.. automodule:: iotswarm.queries
5757
:members:
5858
:undoc-members:
5959
:show-inheritance:
6060

61-
iotdevicesimulator.swarm module
61+
iotswarm.swarm module
6262
-------------------------------
6363

64-
.. automodule:: iotdevicesimulator.swarm
64+
.. automodule:: iotswarm.swarm
6565
:members:
6666
:undoc-members:
6767
:show-inheritance:
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
iotdevicesimulator.scripts package
1+
iotswarm.scripts package
22
==================================
33

44
Submodules
55
----------
66

7-
iotdevicesimulator.scripts.cli module
7+
iotswarm.scripts.cli module
88
-------------------------------------
99

10-
.. click:: iotdevicesimulator.scripts.cli:main
10+
.. click:: iotswarm.scripts.cli:main
1111
:prog: iot-swarm
1212
:nested: full
1313

1414
Module contents
1515
---------------
1616

17-
.. automodule:: iotdevicesimulator.scripts
17+
.. automodule:: iotswarm.scripts
1818
:members:
1919
:undoc-members:
2020
:show-inheritance:

docs/source/modules.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
iotdevicesimulator
2-
==================
1+
iotswarm
2+
========
33

44
.. toctree::
55
:maxdepth: 4
66

7-
iotdevicesimulator
7+
iotswarm

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies = [
1414
"oracledb",
1515
"backoff",
1616
]
17-
name = "iot-device-simulator"
17+
name = "iot-swarm"
1818
dynamic = ["version"]
1919
authors = [{ name = "Lewis Chambers", email = "lewcha@ceh.ac.uk" }]
2020
description = "Package for simulating a net of IoT devices for stress testing."
@@ -24,9 +24,9 @@ test = ["pytest", "pytest-cov", "pytest-asyncio", "parameterized"]
2424
docs = ["sphinx", "sphinx-copybutton", "sphinx-rtd-theme", "sphinx-click"]
2525

2626
[project.scripts]
27-
iot-swarm = "iotdevicesimulator.scripts.cli:main"
27+
iot-swarm = "iotswarm.scripts.cli:main"
2828
[tool.setuptools.dynamic]
29-
version = { attr = "iotdevicesimulator.__version__" }
29+
version = { attr = "iotswarm.__version__" }
3030

3131
[tool.setuptools.packages.find]
3232
where = ["src"]
@@ -40,12 +40,12 @@ filterwarnings = [
4040
"ignore::DeprecationWarning:autosemver.*:",
4141
"ignore::DeprecationWarning:pkg_resources.*:",
4242
]
43-
addopts = "--cov=iotdevicesimulator"
43+
addopts = "--cov=iotswarm"
4444
markers = [
4545
"asyncio: Tests asynchronous functions.",
4646
"oracle: Requires oracle connection and required config credentials",
4747
"slow: Marks slow tests",
4848
]
4949

5050
[tool.coverage.run]
51-
omit = ["*example.py", "*__init__.py", "queries.py", "loggers.py"]
51+
omit = ["*example.py", "*__init__.py", "queries.py", "loggers.py", "cli.py"]

0 commit comments

Comments
 (0)