Gridworks Uploader
Project description
Gridworks Uploader
This package provides a reliable upload service using the gridworks-protocol.
The upload services communicates upstream using MQTT. Clients deliver data to the service for reliable delivery using http. For example:
import random
import time
from typing import Literal
import httpx
from gwproto.messages import EventBase
class SomeData(EventBase):
TimestampUTC: float
Reading: float
TypeName: Literal["gridworks.event.some.data"] = "gridworks.event.some.data"
if __name__ == "__main__":
httpx.post(
"http://127.0.0.1:8080/events",
json=SomeData(
TimestampUTC=round(time.time(), 3),
Reading=round(random.random(), 3),
).model_dump(),
)
Experimentation
To experiment with this package you must run the upload service, and, if you want to watch your messages delivered to a stub ingester, you must also run an MQTT broker and the stub ingester.
To set up the MQTT broker, follow the gridworks-proactor instructions.
curl -LsSf https://astral.sh/uv/install.sh | sh
uv python install 3.12
uv tool install -p 3.12 poetry=1.8.5
git clone https://github.com/SmoothStoneComputing/gridworks-uploader.git
cd gridworks-uploader
Create a .env file at the location returned by:
gwup envfile
with these contents:
UPLOADER_APP_lONG_NAME = "test.uploader"
UPLOADER_APP_INGESTER_LONG_NAME = "test.ingester"
Create a second .env at the location returned by:
gwup stubs ingester envfile
with these contents:
STUB_INGESTER_APP_lONG_NAME = "test.ingester"
STUB_INGESTER_APP_UPLOADER_LONG_NAME = "test.uploader"
Create local test certificate authority:
poetry install --sync --with dev
poetry shell
gwcert ca create test-ca
Generate test certs for the uploader and the stub ingester:
gwup gen-test-certs
gwup stubs ingester gen-test-certs
Open 3 terminals. In each terminal, cd to the gridworks-uploader repo and run:
poetry shell
In the ingester terminal run:
gwup stubs ingester run --log-events
In the uploader terminal run:
gwup run --message-summary
In the client terminal run:
gwup stubs client run
Or:
python src/gwupload/stubs/client/client.py
Installation
You can install Gridworks Uploader via pip from PyPI:
uv tool install gridworks-uploader
or
pipx install gridworks-uploader
Service installation
Gridworks-Uploader can be installed as a systemd service,
for example on a Raspberry Pi, using gwup service command line interface.
The gwup service commands are mostly wrappers around systemctl and journalctl.
To see the systemctl and journalctl command without running them simply pass
--dry-run to any gwup service command.
Unit file generation
The configuration for the service is stored in a unit file. To generate a service file run:
gwup service generate
or, if the service will not run under default user, 'pi', but the user USER_NAME, run:
gwup service generate --user USER_NAME
The unit file can be also be written or edited by hand. The service file is
generated at $HOME/.config/gridworks/uploader/gridworks-uploader.service.
That path can be viewed any time with:
gwup service file
Once the service is installed changes to the unit file will not take effect
unless the unit file is reloaded into systemd with sudo systemctl daemon-reload
and the service is restarted. This can be accomplished with:
gwup service reload
gwup service restart
Installation
To install and run the service run:
gwup service install
To stop and uninstall the service run:
gwup service uninstall
The service can be re-installed without re-generating the unit file.
Starting and stopping
The service can be started, restarted and stopped:
gwup service start
gwup service restart
gwup service stop
A stopped service will restart when the device reboots. Use gwup service uninstall
to prevent the service from restarting when the device reboots.
Watching
The current state of the service can be seen with:
gwup service status
The log of the service can be followed with:
gwup service log
Usage
Please see the Command-line Reference for details.
Contributing
Contributions are very welcome. To learn more, see the Contributor Guide.
License
Distributed under the terms of the MIT license, Gridworks Uploader is free and open source software.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Credits
This project was generated from @cjolowicz's Hypermodern Python Cookiecutter template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gridworks_uploader-1.0.2.tar.gz.
File metadata
- Download URL: gridworks_uploader-1.0.2.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbcff1c7efcf5ec2af64839a554a0cbbe015c6f0551ac1cc77e5d63e43bc6a97
|
|
| MD5 |
845260beabf9d11d1bf4fcc33db705f6
|
|
| BLAKE2b-256 |
dd8d7df033437b8e14ffa1f8210e58af3637e79af305ceee022cc2d517147daf
|
File details
Details for the file gridworks_uploader-1.0.2-py3-none-any.whl.
File metadata
- Download URL: gridworks_uploader-1.0.2-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c72f01fdae3fce3e23af9e15c5d6900673d378d2c88ebf61afc04b44d4bb506
|
|
| MD5 |
99e1eb57eaf5488103609de8f9805fc5
|
|
| BLAKE2b-256 |
70a5e941a64dbfe330ba1a299c7298decda0cd056986828ac30ece6e0ad9bd3d
|