Skip to main content

Python package for Environmental NeTworked Sensor (ENTS)

Project description

Soil Power Sensor Python Protobuf Bindings

The soil power sensor protobuf protocol is implemented as a Python package that allows for Measurement messages to be decoded into a dictionary and Response messages to be encoded. The generated files from protobuf are also accessible for more complex use cases.

Installation

Use the following to install the ents package with gui via pip:

pip install ents[gui]

You can also install the package from source with the following:

# install package
pip install .[gui]

If you are planning to develop the package we recommend you install the package in editable mode with development dependencies. This allows you to make changes to the source code and have them reflected in the package without needing to reinstall it.

# install development dependencies
pip install -e .[gui,dev]

Usage

The following example code demonstrates decoding the measurement message and encoding a response.

from ents import encode, decode

# get data encoded by the soil power sensor
data = ...

meas_dict = decode(data)

# process data
...

# send response
resp_str = encode(success=True)

The formatting of the dictionary depends on the type of measurement sent. The key type is included on all measurement types and can be used to determine the type of message. See the source *.proto files to get the full list of types to get the full list of types and keys. A list is provided in Message Types. The Python protobuf API uses camel case when naming keys. The key ts is in ISO 8601 format as a string.

Message Types

Type power

meas_dict = {
  "type": "power",
  "loggerId": ...,
  "cellId": ...,
  "ts": ...,
  "data": {
    "voltage": ...,
    "current": ...
  },
  "data_type": {
    "voltage": float,
    "voltage": float
  }
}

Type teros12

meas_dict = {
  "type": "teros12",
  "loggerId": ...,
  "cellId": ...,
  "ts": ...,
  "data": {
    "vwcRaw": ...,
    "vwcAdj": ...,
    "temp": ...,
    "ec": ...
  },
  "data_type": {
    "vwcRaw": float,
    "vwcAdj": float,
    "temp": float,
    "ec": int
  }
}

Type bme280 with raw=True (default)

meas_dict = {
  "type": "bme280",
  "loggerId": ...,
  "cellId": ...,
  "ts": ...,
  "data": {
    "pressure": ...,
    "temperature": ...,
    "humidity": ...,
  },
  "data_type": {
    "pressure": int,
    "temperature": int,
    "humidity": int, 
  }
}

Type bme280 with raw=False

meas_dict = {
  "type": "bme280",
  "loggerId": ...,
  "cellId": ...,
  "ts": ...,
  "data": {
    "pressure": ...,
    "temperature": ...,
    "humidity": ...,
  },
  "data_type": {
    "pressure": float,
    "temperature": float,
    "humidity": float, 
  }
}

Simulator

Simulate WiFi sensor uploads without requiring ENTS hardware.

Examples

The examples below can be tested standalone (without ents-backend), by running the http server in tools/http_server.py to see the request format.

Upload a days worth of power measurements on a 60 second interval

ents sim --url http://localhost:3000/api/sensor/ --mode batch --sensor power --cell 200 --logger 200 --start 2025-05-01 --end 2025-05-02 --freq 60
...
total: 1437, failed: 0, avg (ms): 0.10716012526096033, last (ms): 0.0896
total: 1438, failed: 0, avg (ms): 0.10714290681502087, last (ms): 0.0824
total: 1439, failed: 0, avg (ms): 0.10712599027102154, last (ms): 0.0828
total: 1440, failed: 0, avg (ms): 0.10710909722222223, last (ms): 0.0828
total: 1441, failed: 0, avg (ms): 0.10709035392088828, last (ms): 0.08009999999999999
Done!

Upload measurements every 10 seconds

ents sim --url http://localhost:3000/api/sensor/ --mode stream --sensor power --cell 200 --logger 200 --freq 10
Use CTRL+C to stop the simulation
total: 1, failed: 1, avg (ms): 23.386100000000003, last (ms): 23.386100000000003
total: 2, failed: 2, avg (ms): 13.668950000000002, last (ms): 3.9517999999999995
total: 3, failed: 3, avg (ms): 10.795566666666668, last (ms): 5.0488
total: 4, failed: 4, avg (ms): 8.97235, last (ms): 3.5027000000000004

Testing

To run the package tests, create a virtual environment, install as an editable package (if you haven't done so already), and run unittest.

cd python/
python -m unittest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ents-2.3.2.tar.gz (32.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ents-2.3.2-py3-none-any.whl (34.9 kB view details)

Uploaded Python 3

File details

Details for the file ents-2.3.2.tar.gz.

File metadata

  • Download URL: ents-2.3.2.tar.gz
  • Upload date:
  • Size: 32.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ents-2.3.2.tar.gz
Algorithm Hash digest
SHA256 9758113931cd4ec6f3a053df2f7044a5e40d72d097230300297665e1fb3b4c67
MD5 567d523dc3d4b3b4e0e6c097f837d1df
BLAKE2b-256 51ffcf2265a776ca8d14a5de14b5f7b0f6c6d0363dcfbe82a62dc4ffc9864902

See more details on using hashes here.

Provenance

The following attestation bundles were made for ents-2.3.2.tar.gz:

Publisher: publish-python.yaml on jlab-sensing/ENTS-node-firmware

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ents-2.3.2-py3-none-any.whl.

File metadata

  • Download URL: ents-2.3.2-py3-none-any.whl
  • Upload date:
  • Size: 34.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ents-2.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 05ccc34cbd6b6324dd98c20db0ea57c167780cad62c5d357f7f71d335170f734
MD5 230bd9ae2012c6479de46c5884f84f06
BLAKE2b-256 4431f4cd5b9cda031d556004a3ad4a16ef4ec2940dae40eda7f23426a4c1725a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ents-2.3.2-py3-none-any.whl:

Publisher: publish-python.yaml on jlab-sensing/ENTS-node-firmware

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page