def on_message(client, userdata, msg): """ Defines action what to do if event receives """ #Subscriber.on_message(client, userdata, msg) logging.info((msg.topic + " " + str(msg.payload))) from config.Configuration import Configuration config = Configuration() influxdb_client = InfluxDbClient( str(config.read_config("influxdb", "host")), int(config.read_config("influxdb", "port")), str(config.read_config("influxdb", "username")), str(config.read_config("influxdb", "password")), str(config.read_config("influxdb", "database"))) influxdb_client.write_entry("postbox", { "value": msg.payload, "topic": msg.topic })
def on_message(client, userdata, msg): """ Defines action what to do if event receives """ #Subscriber.on_message(client, userdata, msg) logging.info((msg.topic + " " + str(msg.payload))) from config.Configuration import Configuration config = Configuration() mail = EmailMessage() mail['Subject'] = "Sie haben Post ..." mail['From'] = config.read_config("mail", "sender") mail['To'] = config.read_config("mail", "recipient") if config.read_config("mail", "ssl_ca") is not None: server = smtplib.SMTP_SSL( host=str(config.read_config("mail", "host")), port=int(config.read_config("mail", "port")), certfile=str(config.read_config("mail", "ssl_ca"))) else: server = smtplib.SMTP_SSL(host=str( config.read_config("mail", "host")), port=config.read_config("mail", "port")) try: server.ehlo() server.login(str(config.read_config("mail", "username")), str(config.read_config("mail", "password"))) server.send_message(mail, str(config.read_config("mail", "sender")), str(config.read_config("mail", "recipient"))) finally: server.quit()
event_handler.publish("postbox_open") logging.info("Published event to queue") publish_signal() logging.basicConfig( filename='postbox.log', level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S', format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', ) config = Configuration() rf_client = RfClient(config.read_config("rf", "pin")) event_handler = Publisher(str(config.read_config("mqtt", "host")), int(config.read_config("mqtt", "port")), str(config.read_config("mqtt", "topic")), str(config.read_config("mqtt", "user")), str(config.read_config("mqtt", "password")), str(config.read_config("mqtt", "ssl_ca"))) while True: result = rf_client.read() if result is not None: logging.info("Received event '%s'" % result) if config.read_config("rf", "filter") is None or result == int( config.read_config("rf", "filter")): has_signal = True time.sleep(1) # wait one second until next check
from config.Configuration import Configuration import logging from influx_db.subscriber import InfluxDBSubscriber logging.basicConfig(filename='postbox_influxdb.log', level=logging.DEBUG, datefmt='%Y-%m-%d %H:%M:%S', format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', ) config = Configuration() event_handler = InfluxDBSubscriber( str(config.read_config("mqtt", "host")), int(config.read_config("mqtt", "port")), str(config.read_config("mqtt", "topic")), str(config.read_config("mqtt", "user")), str(config.read_config("mqtt", "password")), str(config.read_config("mqtt", "ssl_ca"))) event_handler.subscribe()
from config.Configuration import Configuration import logging from mail.subscriber import MailSubscriber logging.basicConfig( filename='postbox_mail.log', level=logging.DEBUG, datefmt='%Y-%m-%d %H:%M:%S', format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', ) config = Configuration() event_handler = MailSubscriber(str(config.read_config("mqtt", "host")), int(config.read_config("mqtt", "port")), str(config.read_config("mqtt", "topic")), str(config.read_config("mqtt", "user")), str(config.read_config("mqtt", "password")), str(config.read_config("mqtt", "ssl_ca"))) event_handler.subscribe()