Git Product home page Git Product logo

pysensor1's Introduction

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

pysensor1's People

Contributors

codeswallow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.