コード例 #1
0
    def __init__(self):
        # Configure logger
        self.logger = new_logger(name=RPI_CLIENT_NAME)

        self.client = mqtt.Client(RPI_CLIENT_NAME)
        self.client.connect(BROKER_ADDRESS)
        self.client.subscribe(self.SUB_TOPICS)
        self.client.on_message = lambda client, userdata, msg: self.on_mqtt_message(
            client, userdata, msg)

        # Get all actuators and sensors
        self.actuator_workers = {
            name: cls(self.client, self.logger)
            for name, cls in inspect.getmembers(
                importlib.import_module(RPI_ACTUATORS_FILE), inspect.isclass)
            if not name.startswith('_')
        }
        self.sensor_workers = {
            name: cls(self.client, self.logger)
            for name, cls in inspect.getmembers(
                importlib.import_module(RPI_SENSORS_FILE), inspect.isclass)
            if not name.startswith('_')
        }
        self.logger.info(
            f'Found {len(self.actuator_workers)} RPI actuators and {len(self.sensor_workers)} RPI sensors'
        )

        atexit.register(self.on_exit)
コード例 #2
0
    def __init__(self, database=DATABASE_URL, logger=None):
        if not logger:
            self.logger = new_logger(name='SQL-CLIENT', extra_handlers=['sql_debug'])
        else:
            self.logger = logger
        self.logger.debug(database)
        up.uses_netloc.append("postgres")
        url = up.urlparse(database)

        self.connection = psycopg2.connect(
            database=url.path[1:],
            user=url.username,
            password=url.password,
            host=url.hostname,
            port=url.port
        )
        self.connection.autocommit = True

        self.table_models = {name: cls for name, cls in inspect.getmembers(importlib.import_module(TABLE_MODELS_FILE), inspect.isclass) if not name.startswith('_')}
コード例 #3
0
    def __init__(self):
        # Configure logger
        self.logger = new_logger(name=ARDUINO_CLIENT_NAME)

        self.client = mqtt.Client(ARDUINO_CLIENT_NAME)
        self.client.connect(BROKER_ADDRESS)
        self.client.subscribe(self.SUB_TOPICS)
        self.client.on_message = lambda client, userdata, msg: self.on_mqtt_message(client, userdata, msg)

        self.ser = serial.Serial(ARDUINO_USB_PORT, 115200, timeout=1)

        # Get all actuators and sensors
        self.actuator_workers = {name: cls(self.client, self.logger) for name, cls in inspect.getmembers(importlib.import_module(ARDUINO_ACTUATORS_FILE), inspect.isclass) if not name.startswith('_')}
        self.sensor_workers = {name: cls(self.client, self.logger) for name, cls in inspect.getmembers(importlib.import_module(ARDUINO_SENSORS_FILE), inspect.isclass) if not name.startswith('_')}
        self.logger.info(f'Found {len(self.actuator_workers)} arduino actuators and {len(self.sensor_workers)} arduino sensors')

        self.thread = threading.Thread(target=self.read_serial, args=())
        self.thread.start()

        atexit.register(self.on_exit)
コード例 #4
0
ファイル: core.py プロジェクト: franciscoaze/plantie-plantie
    def __init__(self):
        self.logger = new_logger(name=CORE_CLIENT_NAME, extra_handlers=['apscheduler', 'SQL-CLIENT'])

        self.mqtt_client = MQTTClient(CORE_CLIENT_NAME)

        try:
            self.db_client = ElephantSQL()
            self.db_client.delete_table('Jobs')
            self.db_client.create_tables_if('Jobs')

        except Exception as exc:
            self.logger.warning(exc)

        self.job_defs = {cls.id: cls() for name, cls in inspect.getmembers(importlib.import_module(JOBS_DEF_FILE), inspect.isclass) if not name.startswith('_')}

        self.add_jobs()

        watcher = self.scheduler.add_job(
            self.update_jobs_from_db,
            trigger="cron",
            id='db_watcher',
            args=[self, self.db_client, self.logger],
            minute=f'*/{DB_WATCHER_MIN}',
        )
コード例 #5
0
import paho.mqtt.client as mqtt
import json

from pyplantie.workers.arduino_actuators import GrowLed, Pump1, Pump2, Servo
from pyplantie.workers.raspberry_actuators import WhiteLED
from pyplantie.workers.raspberry_sensors import InternalTemp
from pyplantie.workers.arduino_sensors import BME208
from pyplantie.utils.mylogger import new_logger
from pyplantie.utils.sql_client import ElephantSQL

import logging

SUB_TOPICS = [('sensors/#', 1)]

logging.getLogger('BlynkLog').setLevel(logging.DEBUG)
logger = new_logger(name=BLYNK_CLIENT_NAME, extra_handlers=["BlynkLog"])

blynk = BlynkLib.Blynk(BLYNK_AUTH)
pump_seconds = 1

menu_labels =[]

@blynk.VIRTUAL_WRITE(1)
def control_led(value):
    """
    Controls the white camera led
    """
    logger.info('Valor de V1: {}'.format(value[0]))

    if value[0] >= "1":
        msg = {"value": "ON"}