<div align="center">
<img src="artwork/Pysor.png" alt="logo"/>
</div>
<div align="center">
<img src="https://github.com/CodeSwallow/pysor/actions/workflows/python-package.yml/badge.svg" alt="workflow status"/>
<img src="artwork/coverage.svg" alt="coverage"/>
</div>
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:
```shell
pip install pysor
```
## Quickstart
Here's a quick example showing how to simulate a temperature sensor using Pysor:
```python
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
```python
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.
```python
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.
```python
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.
```python
mqtt_client = MqttClient('your.broker.org')
```
### License
Pysor is licensed under the MIT License. See the LICENSE file for more details
Raw data
{
"_id": null,
"home_page": "https://github.com/CodeSwallow/pysor",
"name": "Pysor",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9, <4",
"maintainer_email": "",
"keywords": "mqtt sensor simulation",
"author": "Isai Ramirez",
"author_email": "isai.ramirez.stamaria15@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f8/62/7e320923fec100912f74ae9ffdc5e6c2f41da87f3e2eaa76a7de84a2015c/pysor-0.1.1.tar.gz",
"platform": null,
"description": "<div align=\"center\">\r\n<img src=\"artwork/Pysor.png\" alt=\"logo\"/>\r\n</div>\r\n\r\n<div align=\"center\">\r\n<img src=\"https://github.com/CodeSwallow/pysor/actions/workflows/python-package.yml/badge.svg\" alt=\"workflow status\"/>\r\n<img src=\"artwork/coverage.svg\" alt=\"coverage\"/>\r\n</div>\r\n\r\nPysor 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. \r\n\r\n## Installation\r\nPysor is available on PyPi. You can install it via pip:\r\n\r\n```shell\r\npip install pysor\r\n```\r\n\r\n## Quickstart\r\nHere's a quick example showing how to simulate a temperature sensor using Pysor:\r\n\r\n```python\r\nfrom sensor_simulation import MqttClient, SensorManager\r\nfrom sensor_simulation.sensors import TemperatureSensor\r\n\r\n\r\nif __name__ == '__main__':\r\n mqtt_client = MqttClient('your.broker.org')\r\n\r\n temperature_sensor = TemperatureSensor(mqtt_client, 'sensor/temperature')\r\n\r\n sensor_manager = SensorManager()\r\n sensor_manager.add_sensor(temperature_sensor)\r\n\r\n try:\r\n sensor_manager.run()\r\n except KeyboardInterrupt:\r\n sensor_manager.stop_all()\r\n\r\n```\r\n\r\n## Available Sensors\r\nPysor comes with a variety of pre-built sensor simulations:\r\n\r\n- TemperatureSensor\r\n- HumiditySensor\r\n- LightIntensitySensor\r\n- WaterLevelSensor\r\n- PhSensor\r\n\r\nAll sensors have parameters to set the mqtt client, the topic and the interval at which the sensor should publish messages.\r\n\r\n### Example of parameters for HumiditySensor\r\n```python\r\nclass HumiditySensor(BaseSensor):\r\n \"\"\"\r\n Humidity sensor class.\r\n Min and max humidity values are in percentage.\r\n \"\"\"\r\n\r\n def __init__(self,\r\n mqtt_client: MqttClient,\r\n topic: str,\r\n interval: float = 120.0,\r\n min_humidity: int = 30,\r\n max_humidity: int = 80,\r\n humidity_change: float = 1.0,\r\n current_humidity: float = None\r\n ) -> None:\r\n ...\r\n```\r\n\r\n## Custom Sensors\r\nExtend the BaseSensor class and implement the 'generate_data' method. This method should return the data to be published.\r\n```python\r\nclass MyCustomSensor(BaseSensor):\r\n \r\n def generate_data(self) -> Any:\r\n # Your custom data generation logic here\r\n ...\r\n```\r\n\r\n## SensorManager\r\nThe SensorManager class is used to run the sensors. It has a method to add sensors and a method to run the sensors.\r\n```python\r\nsensor_manager = SensorManager()\r\n\r\nsensor_manager.add_sensor(temperature_sensor)\r\nsensor_manager.add_sensor(humidity_sensor)\r\nsensor_manager.add_sensor(water_level_sensor)\r\nsensor_manager.add_sensor(light_intensity_sensor)\r\n\r\ntry:\r\n sensor_manager.run()\r\nexcept KeyboardInterrupt:\r\n sensor_manager.stop_all()\r\n```\r\n\r\n## MqttClient\r\nThe MqttClient class is used to publish messages to the broker. It uses the Paho MQTT library to communicate with the broker.\r\n```python\r\nmqtt_client = MqttClient('your.broker.org')\r\n```\r\n\r\n### License\r\nPysor is licensed under the MIT License. See the LICENSE file for more details\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python package for sensor simulations",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/CodeSwallow/pysor"
},
"split_keywords": [
"mqtt",
"sensor",
"simulation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fe8b2ff06ba09bcae6273fd15ca94835d9e748e3081b5647316c1de5afcee14b",
"md5": "4c6b23c4f40f3b4a486de331b7d29157",
"sha256": "70663335844814c5da160f3532d6c8457a115ca68551e66ec90eebab82946f5c"
},
"downloads": -1,
"filename": "pysor-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4c6b23c4f40f3b4a486de331b7d29157",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9, <4",
"size": 17197,
"upload_time": "2023-07-10T14:56:14",
"upload_time_iso_8601": "2023-07-10T14:56:14.517969Z",
"url": "https://files.pythonhosted.org/packages/fe/8b/2ff06ba09bcae6273fd15ca94835d9e748e3081b5647316c1de5afcee14b/pysor-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f8627e320923fec100912f74ae9ffdc5e6c2f41da87f3e2eaa76a7de84a2015c",
"md5": "012b2b99a3e7d5477289f16ae93cdd57",
"sha256": "e5b80e2f93c31bfd725ed20726523872e57086aa6911a82df1bb2e58d0eb9c86"
},
"downloads": -1,
"filename": "pysor-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "012b2b99a3e7d5477289f16ae93cdd57",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9, <4",
"size": 9958,
"upload_time": "2023-07-10T14:56:16",
"upload_time_iso_8601": "2023-07-10T14:56:16.046714Z",
"url": "https://files.pythonhosted.org/packages/f8/62/7e320923fec100912f74ae9ffdc5e6c2f41da87f3e2eaa76a7de84a2015c/pysor-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-10 14:56:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "CodeSwallow",
"github_project": "pysor",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "pysor"
}