Skip to main content

naneos particle solutions gmbh python backend

Project description

naneos-devices

GitHub Issues GitHub Pull Requests Ruff License

Projektlogo

This repository contains a collection of Python scripts and utilities for our naneos particle solutions measurement devices. These scripts will provide various functionalities related to data acquisition, analysis, and visualization for your measurement devices.

Installation

You can install the naneos-devices package using pip. Make sure you have Python 3.10 or higher installed. Open a terminal and run the following command:

pip install naneos-devices

Usage

Naneos Device Manager

NaneosDeviceManager is a tiny, fire-and-forget thread that auto-manages Naneos devices over Serial and BLE, periodically gathers data, and (optionally) uploads it. You can enable/disable transports at construction time and at runtime, adjust the gathering interval, and/or pipe data into your own code via a user-provided queue.Queue. Clean start/stop APIs make integration trivial.

Highlights

  • ✅ Easy on/off switches for Serial and BLE (before or during runtime)
  • ⏱️ Configurable gathering interval (clamped to 10–600 s)
  • 📤 Optional auto-upload (enable/disable anytime)
  • 📦 Queue hand-off: receive dict[int, pandas.DataFrame] snapshots and process them in your app
  • 🧵 Daemon thread with graceful shutdown

Quick Start (fire and forget upload from all devices in reach to naneos IoT service)

import time

from naneos.manager import NaneosDeviceManager

manager = NaneosDeviceManager(
    use_serial=True,
    use_ble=True,
    upload_active=True,
    gathering_interval_seconds=30 # clamped to [10, 600]
)
manager.start()

try:
    while True:
        remaining = manager.get_seconds_until_next_upload()
        print(f"Next upload in: {remaining:.0f}s")
        time.sleep(remaining + 1)

        print("Serial:", manager.get_connected_serial_devices())
        print("BLE   :", manager.get_connected_ble_devices())
        print()
except KeyboardInterrupt:
    pass

manager.stop()
manager.join()
print("Stopped.")

Runtime Controls (toggle anytime during execution)

# Turn Serial on/off during runtime
manager.use_serial_connections(True)   # or False
print("Serial enabled:", manager.get_serial_connection_status())

# Turn BLE on/off during runtime
manager.use_ble_connections(False)     # or True
print("BLE enabled:", manager.get_ble_connection_status())

# Enable/disable uploads on the fly
manager.set_upload_status(False)       # keep gathering, but don't upload
print("Upload active:", manager.get_upload_status())

# Update the gathering interval at runtime (10–600 s)
manager.set_gathering_interval_seconds(45)
print("Interval (s):", manager.get_gathering_interval_seconds())

Queue-Based Data Handoff (use your own processing)

Register a queue to receive each gathered snapshot (no uploads required):

import queue

out_q: queue.Queue = queue.Queue()

manager = NaneosDeviceManager(
    upload_active=False,              # we'll handle data ourselves
    gathering_interval_seconds=15
)
manager.register_output_queue(out_q)
manager.start()

try:
    while True:
        # Wait until a snapshot is ready, then pull all pending ones
        time.sleep(manager.get_seconds_until_next_upload() + 1)

        while not out_q.empty():
            snapshot = out_q.get()
            # snapshot: dict[int, pandas.DataFrame] keyed by device serial
            print(f"Received snapshot for {len(snapshot)} device(s)")
            for serial, df in snapshot.items():
                print(f"  - {serial}: {len(df)} rows")
                # >>> Your processing here (store, analyze, forward, etc.)
except KeyboardInterrupt:
    pass

manager.stop()
manager.join()

Make sure to modify the code according to your specific requirements. Refer to the documentation and comments within the code for detailed explanations and usage instructions.

Documentation

The documentation for the naneos-devices package can be found in the package's documentation page.

Protobuf

Use this command to create a py and pyi file from the proto file

protoc -I=. --python_out=. --pyi_out=. ./protoV1.proto 

Testing

I recommend working with uv. Testing with the local python venv in vscode GUI or with:

uv run --env-file .env pytest

Testing every supported python version:

nox -s tests

Building executables

Sometimes you want to build an executable for a customer with you custom script. The build must happen on the same OS as the target OS. For example if you want to build an executable for windows you need to build it on Windows.

pyinstaller demo/p1UploadTool.py  --console --noconfirm --clean --onefile

Ideas for future development

  • P2 BLE implementation that integrates into the implementation of the serial P2
  • P2 Bidirectional Implementation that allows to send commands to the P2
  • Automatically activate Bluetooth or ask when BLE is used

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please submit an issue on the issue tracker.

Please make sure to adhere to the coding style and conventions used in the repository and provide appropriate tests and documentation for your changes.

License

This repository is licensed under the MIT License.

Contact

For any questions, suggestions, or collaborations, please feel free to contact the project maintainer:

Project details


Release history Release notifications | RSS feed

This version

1.1.4

Download files

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

Source Distribution

naneos_devices-1.1.4.tar.gz (122.2 kB view details)

Uploaded Source

Built Distribution

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

naneos_devices-1.1.4-py3-none-any.whl (52.2 kB view details)

Uploaded Python 3

File details

Details for the file naneos_devices-1.1.4.tar.gz.

File metadata

  • Download URL: naneos_devices-1.1.4.tar.gz
  • Upload date:
  • Size: 122.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for naneos_devices-1.1.4.tar.gz
Algorithm Hash digest
SHA256 3e6d256ca84aecbdb0f255d69d84f162674fb47380d096c1c52cbfa4efe76f9b
MD5 4dd33e5ab8e762d637b0134c6c0b83dc
BLAKE2b-256 122550c3b359aa1f1fdf35421679e5278ab3e562e1c107bebc8fac35288c18d6

See more details on using hashes here.

File details

Details for the file naneos_devices-1.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for naneos_devices-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f1fb496b3fc99d3a2e6e4b39d5eee9a85fddad1a6b5eef1dd51d891c18271384
MD5 81b4afa8ab8a61844ac7c1a63e4e3cbd
BLAKE2b-256 f09572a7c7e6c17997b003221e773d285b0469d3dd120095c3ddca0a4eba0e1d

See more details on using hashes here.

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