示例#1
0
def action(action):
    if action == 'on':
        if not redis.db.get('pihouse/sprinkler/status') == "True":
            mqtt.client.publish('pihouse/sprinkler/control', "True")
            monitor.run()

    if action == 'off':
        mqtt.client.publish('pihouse/sprinkler/control', "False")
        mqtt.client.publish('pihouse/sprinkler/schedule/last', "request")

    sleep(0.2)
    status = redis.db.get('pihouse/sprinkler/status')
    socketio.emit('statechange', {
        "status": convert.switch(status),
        "opposite": convert.convert(status)
    })
    return ('', 204)
    def test_monitor_end_to_end_with_config(self):
        parameters = app.monitor.read_config_yaml("config.yaml")

        monitor = app.monitor.Monitor(parameters)
        monitor.generate_components()
        monitor.run(50)

        with sqlite3.connect(parameters['database_location']) as conn:
            cur = conn.cursor()
            cur = cur.execute("SELECT * FROM data;")
            output_data = cur.fetchall()
            print("Data in database: ")
            for line in output_data:
                print(line)

        # Have we filled up the database with something?
        self.assertEqual(
            True,
            len(output_data) > 0,
            "No data was written to the database. Check that board is in debug mode."
        )
示例#3
0
def main(app_config, logging_config):
    """
    Main entry point for the bacon monitor.
    :return:
    """
    construct_loggers(logging_config)
    logger = logging.getLogger('logger')

    # Construct the bacon monitoring objects
    parameters = app.monitor.read_config_yaml(app_config)

    monitor = app.monitor.Monitor(parameters)
    logger.info("System running. Ctrl-c to exit program.")
    while True:
        try:
            monitor.generate_components()
            monitor.run()
        except Exception as e:
            logger.info("Encountered error:")
            logger.info(e)
            time.sleep(5)
    def test_create_monitor_and_serial_connection_and_data_writing(self):
        if connection_name is None:
            self.skipTest("No connection available. Skipping test.")

        parameters = app.test.test_monitor.generate_input_parameter_object_minus_inputs()
        parameters["connection_list"] = [connection_name]
        parameters["overwrite"] = True
        monitor = app.monitor.Monitor(parameters)
        monitor.generate_components()
        monitor.run(runs=5)

        with sqlite3.connect(parameters['database_location']) as conn:
            cur = conn.cursor()
            cur = cur.execute("SELECT * FROM data;")
            output_data = cur.fetchall()
            print("Data in database: {0}".format(output_data))

        self.assertEqual(
            True,
            len(output_data) > 0,
            "No data was written to the database. Check that board is in debug mode."
        )