from datetime import datetime, timedelta from db_helpers import db_execute from logging_setup import create_logger import config import sql_templates """ Setup to record device info from Sonoff S31 outlets running Espurna. """ logger = create_logger('Modules.DevInfo') """Command to create the database, this is run every time the database is opened. So you need the [IF NOT EXISTS] part.""" CREATE_TABLES = [sql_templates.Hosts] # Topics to accept and sub topics to ignore ACCEPTED_TOPIC_PREFIXES = [ "espurna", ] """ The topics for all the SQL table columns, same order as the table creation command above. datetime datetime host str ip str desc str ssid str mac str rssi int """
from db_helpers import db_execute from datetime import datetime from main import Message from logging_setup import create_logger from math import isnan from mqtt_helpers import publish import mqtt_helpers as mqtt import sql_templates """ Receives things in epsurna MQTT root topic and forwards them to the correct areas. Currently forwarding temperature values as the MQTT structure i wan't isn't achievable in Espurna. """ logger = create_logger('Modules.TempFwrd') """Topics to accept, # means everything.""" ACCEPTED_TOPIC_PREFIXES = [ "espurna", ] def init(): pass def redirect_temperature(dt, msg): host_name = msg.topic.split('/')[1] value = float(msg.payload) logger.debug(f"Redirecting temperature message from {host_name}")
from db_helpers import db_execute from datetime import datetime from main import Message from logging_setup import create_logger from math import isnan """ Logs any MQTT messages specified here that match these criteria: - Dedicated table in mqtt_logger database with the structure outlined below. - MQTT root topic is the same as the table name. - 2nd part of the MQTT topic is the host name. (temperatures/<host_name>) - Message payload is a float. """ logger = create_logger('Modules.NameHostValue') # SQL table names, MQTT root topics, and column name inside respective table. TABLE_NAMES = [ 'temperatures', 'relative_humidities', 'total_volatile_organic_compounds' ] """Commands to create the database, this is run every time the database is opened. So you need the [IF NOT EXISTS] part. These are some example commands.""" CREATE_TABLES = [ """CREATE TABLE IF NOT EXISTS {} ( datetime DATETIME NOT NULL, host_name VARCHAR(128) NOT NULL, value DECIMAL(30,15), PRIMARY KEY (datetime, host_name) )""".format(t) for t in TABLE_NAMES ] ACCEPTED_TOPIC_PREFIXES = TABLE_NAMES
from datetime import datetime, timedelta from multiprocessing import Queue from db_helpers import db_execute from logging_setup import create_logger from functools import cache import config import mysql import sql_templates """ Setup to record stats from Sonoff S31 outlets running Espurna. Does some things to lump together power, voltage, current values into a single SQL table row. """ logger = create_logger('Modules.Outlet') """Command to create the database, this is run every time the database is opened. So you need the [IF NOT EXISTS] part.""" CREATE_TABLES = [ """CREATE TABLE IF NOT EXISTS outlet_stats( datetime DATETIME NOT NULL, host_name VARCHAR(128) NOT NULL, state BOOLEAN, current DECIMAL(30,15), voltage DECIMAL(30,15), power DECIMAL(30,15), energy DECIMAL(30,15), FOREIGN KEY (host_name) REFERENCES hosts(name), PRIMARY KEY (datetime, host_name) )""" ]
from multiprocessing import Queue import modules as __modules__ import json from pathlib import Path import config from datetime import datetime from db_helpers import * import mqtt_helpers as mqtt from logging_setup import create_logger logger = create_logger('Main') def modules(): """ Returns the module for each module imported in modules/__init__. Assumes everything that doesn't start with __ is a logging module. """ for m in dir(__modules__): if not m.startswith("__"): yield __modules__.__dict__[m] def on_connect(client, userdata, flags, rc): if rc != 0: logger.warning(f"Connection failed: {rc}") else: logger.info("Connected") client.subscribe("#") logger.debug("Subscribed to '#'") return rc