Skip to main content

A Python package for sensor simulations

Project description

logo
workflow status coverage

Pysor is a Python library for the simulation of various sensors. It is designed to be used with an MQTT broker of your choice, providing an easy and flexible way to simulate sensor data for IoT applications.

Installation

Pysor is available on PyPi. You can install it via pip:

pip install pysor

Quickstart

Here's a quick example showing how to simulate a temperature sensor using Pysor:

from sensor_simulation import MqttClient, SensorManager
from sensor_simulation.sensors import TemperatureSensor


if __name__ == '__main__':
    mqtt_client = MqttClient('your.broker.org')

    temperature_sensor = TemperatureSensor(mqtt_client, 'sensor/temperature')

    sensor_manager = SensorManager()
    sensor_manager.add_sensor(temperature_sensor)

    try:
        sensor_manager.run()
    except KeyboardInterrupt:
        sensor_manager.stop_all()

Available Sensors

Pysor comes with a variety of pre-built sensor simulations:

  • TemperatureSensor
  • HumiditySensor
  • LightIntensitySensor
  • WaterLevelSensor
  • PhSensor

All sensors have parameters to set the mqtt client, the topic and the interval at which the sensor should publish messages.

Example of parameters for HumiditySensor

class HumiditySensor(BaseSensor):
    """
    Humidity sensor class.
    Min and max humidity values are in percentage.
    """

    def __init__(self,
                 mqtt_client: MqttClient,
                 topic: str,
                 interval: float = 120.0,
                 min_humidity: int = 30,
                 max_humidity: int = 80,
                 humidity_change: float = 1.0,
                 current_humidity: float = None
                 ) -> None:
        ...

Custom Sensors

Extend the BaseSensor class and implement the 'generate_data' method. This method should return the data to be published.

class MyCustomSensor(BaseSensor):
    
    def generate_data(self) -> Any:
        # Your custom data generation logic here
        ...

SensorManager

The SensorManager class is used to run the sensors. It has a method to add sensors and a method to run the sensors.

sensor_manager = SensorManager()

sensor_manager.add_sensor(temperature_sensor)
sensor_manager.add_sensor(humidity_sensor)
sensor_manager.add_sensor(water_level_sensor)
sensor_manager.add_sensor(light_intensity_sensor)

try:
    sensor_manager.run()
except KeyboardInterrupt:
    sensor_manager.stop_all()

MqttClient

The MqttClient class is used to publish messages to the broker. It uses the Paho MQTT library to communicate with the broker.

mqtt_client = MqttClient('your.broker.org')

License

Pysor is licensed under the MIT License. See the LICENSE file for more details

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

pysor-0.1.2.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

pysor-0.1.2-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file pysor-0.1.2.tar.gz.

File metadata

  • Download URL: pysor-0.1.2.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for pysor-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e0b70dd0e4909b540c46f388690fed313a9fbe19220b9a8d71ef778f986082fe
MD5 edfa34eb365d3e7a9325415e536cc4f3
BLAKE2b-256 c36edc298280475cf69fe85a13c6d495ce57e121d050f90815083833f5e1d28d

See more details on using hashes here.

File details

Details for the file pysor-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pysor-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for pysor-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1b91e3011a662c71ae0d2e9926e0277b598255e8d9d7755a04577cfdc0fe8168
MD5 e2f03b900c12635242108db2f44a42bf
BLAKE2b-256 fdf6ce6334d7c3db73922d0c3e0d6f4d9c00e592e5deccd719cabeaf5b99033c

See more details on using hashes here.

Supported by

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