Python utilities for Tahu & Sparkplug B.
Project description
TahUtils
A small wrapper package for using Tahu for Sparkplug B in Python. Comes with an unmodified (barring import structure) Tahu included, hence the use of the Eclipse license.
Examples
See the examples directory in the project repository.
Current Support
- Generating Sparkplug B topics
- Generating birth, death, and data payloads for nodes and devices
- Managing aliases
- Using enums for metric names
- Using dataclasses to manage metric names and metric states
- Parsing sparkplug b messages
Changes to the tahu library
Updating compiled Protobuf files
Assuming no major refactoring to the tahu library, updating the included tahu consists of the following steps:
-
Download the latest release from the repository: https://github.com/eclipse/tahu/tags
-
Extract the source code.
-
Regenerate the
sparkplug_b_pb2.pyfile per the instructions intahu-<version>/python/core/README.md. Usetahu-<version>/python/coreas your working directory when executing the command, and you'll need the protobuf compiler. -
Copy the contents of the
tahu-<version>/python/coredirectory to thetahutils/tahudirectory. -
Overwrite the
tahutils/tahu/__init__.pyfile with the appropriate imports, typically:from . import sparkplug_b_pb2 from . import array_packer from . import sparkplug_b
-
Modify the imports in
tahutils/tahu/sparkplug_b.pyto include thetahupackage name:import tahutils.tahu.sparkplug_b_pb2 as sparkplug_b_pb2 import time from tahutils.tahu.sparkplug_b_pb2 import Payload from tahutils.tahu.array_packer import *
Fixing metric timestamps
As of this version, there is a bug in the tahu library relating to metric timestamps. See this pull request for more details.
This is patched by updating sparkplug_b.py.
def addMetric(container, name, alias, type, value, timestamp=None):
if timestamp is None:
timestamp = int(round(time.time() * 1000))
...
def addNullMetric(container, name, alias, type, timestamp=None):
if timestamp is None:
timestamp = int(round(time.time() * 1000))
metric = container.metrics.add()
if name is not None:
metric.name = name
if alias is not None:
metric.alias = alias
metric.timestamp = timestamp
metric.is_null = True
...
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 tahutils-0.1.11.tar.gz.
File metadata
- Download URL: tahutils-0.1.11.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.1 Linux/6.8.0-1014-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb8017dd78a846ce5d10d5fb89ee38413337d2fa9a745c1111db05edbbd43e5a
|
|
| MD5 |
9f70b820944dd2ad18cfbf39b69236ef
|
|
| BLAKE2b-256 |
9fbf410d2411621f5d62474ec639ee5a39b332dd95354c2b53822d25d71329ee
|
File details
Details for the file tahutils-0.1.11-py3-none-any.whl.
File metadata
- Download URL: tahutils-0.1.11-py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.1 Linux/6.8.0-1014-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14e711c4b39c9a113bd57dad9d81425a0b58a1f7ac8242016a76c48fc72a8a45
|
|
| MD5 |
92e3ee9186728d5c5aed22f1f5422bfd
|
|
| BLAKE2b-256 |
4e989c4d9c537e1a8882dc0091ce241f816dd9fc82bdeaf71f24df48caa03843
|