Librería para la gestión de eventos
Project description
habcatev
Libreria python orientada a eventos para habcat.
Quick start
Ejemplo simple 1
import habcatev,time
import random
class SimpleExample(habcatev.device.Device.Device):
"""Ejemplo simple en el que se produce y consume"""
def __init__(self):
super(SimpleExample, self).__init__()
# El dispositivo se subscribe a todos los topics
self.setSubscriptionArr(['#'])
def on_event(self,topic,data):
# Lanzamos este codigo cuando se produce un evento
self.log.logger.info("Ha llegado: Topic:" + topic + " Data: " + data)
def loop(self):
# Suponemos que leemos el valor de un sensor y lo escribimos
# en un topic
self.log.logger.info('Enviando un mensaje a mqtt ...')
self.send('mitopico1', random.uniform(10.5, 75.5))
time.sleep(5)
SimpleExample().run()
Ejemplo con configuración externa del dispositivo.
import habcatev,time
import random
class SimpleExample(habcatev.device.Device.Device):
def __init__(self):
super(SimpleExample, self).__init__(
description='Ejemplo simple en el que se produce y consume')
# Nos subscribimos a los topics del fichero de configuracion
self.setSubscriptionArr(self.config['ejemplo2']['subscribe'])
def on_event(self,topic,data):
# Lanzamos este codigo cuando se produce un evento
self.log.logger.info("Ha llegado: Topic:" + topic + " Data: " + data)
def loop(self):
# Suponemos que leemos el valor de un sensor y lo escribimos en un topic
self.log.logger.info('Enviando un mensaje a mqtt ...')
self.send(self.config['ejemplo2']['publish'], random.uniform(10.5, 75.5))
time.sleep(5)
SimpleExample()
python3 example2.py --help
python3 example2.py --config 'example2.yaml' --run
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
habcatev-0.0.3.tar.gz
(4.4 kB
view hashes)
Built Distributions
habcatev-0.0.3-py3.9.egg
(10.2 kB
view hashes)