Example #1
0
File: app.py Project: PavelPu/PyIOT
def iothub_client_sample_run():
    try:
        global client, sensor, relays, logger, remoteRelay, MESSAGE_COUNT
        client = iothub_client_init()

        logger = Logging()
        sensor = ReadData()
        relays = Relays()
        remoteRelay = RemoteRelay()

        if client.protocol == IoTHubTransportProvider.MQTT:
            print("IoTHubClient is reporting state")
            #reported_state = "{\"newState\":\"standBy\",\"relaysState\":{\"dining\":\"off\"}}"
            #client.send_reported_state(reported_state, len(reported_state), send_reported_state_callback, SEND_REPORTED_STATE_CONTEXT)
            reportState(relays)
        message = composeStartMessage()
        client.send_event_async(message, send_confirmation_callback,
                                MESSAGE_COUNT)
        print(
            "IoTHubClient.send_event_async accepted message [%d] for transmission to IoT Hub."
            % MESSAGE_COUNT)

        status = client.get_send_status()
        print("Send status: %s" % status)
        MESSAGE_COUNT += 1

        #telemetry.send_telemetry_data(parse_iot_hub_name(), EVENT_SUCCESS, "IoT hub connection is established")
        while True:
            global MESSAGE_SWITCH
            if MESSAGE_SWITCH:
                # send a few messages every minute
                print("IoTHubClient sending %d messages" % MESSAGE_COUNT)

                message = composeMessage(sensor, relays)
                client.send_event_async(message, send_confirmation_callback,
                                        MESSAGE_COUNT)
                print(
                    "IoTHubClient.send_event_async accepted message [%d] for transmission to IoT Hub."
                    % MESSAGE_COUNT)

                status = client.get_send_status()
                print("Send status: %s" % status)
                MESSAGE_COUNT += 1

            #log current state
            statusText = readDeviceData(sensor, relays, remoteRelay, logger)

            if AUTO_CONTROL:
                autoControl()
            time.sleep(config.MESSAGE_TIMESPAN / 1000.0)

    except IoTHubError as iothub_error:
        print("Unexpected error %s from IoTHub" % iothub_error)
        #telemetry.send_telemetry_data(parse_iot_hub_name(), EVENT_FAILED, "Unexpected error %s from IoTHub" % iothub_error)
        return
    except KeyboardInterrupt:
        print("IoTHubClient sample stopped")

    print_last_message_time(client)
Example #2
0
  def __init__(self):

    self.motionDetected = False;
    self.relay = Relays(7);
    self.relay.setAllOff();
    self.motion = Motion(0, 3, self);
    self.light = Light(3, 1000, self);
    self.temp = Temp(1, 85, self);

    self.start = time.time();

    while True:
      print('********** Switch Module Starting **********');
      time.sleep(5);
Example #3
0
config.CONFIG['output_root'] defined in config.py

Default output directory: ./www
'''

import os
import sys
from shutil import copytree
import config
from relays import Relays

ABS_PATH = os.path.dirname(os.path.abspath(__file__))

if __name__ == '__main__':
    try:
        RELAY_SET = Relays()
    except Exception as err:
        print(
            'error creating relays object from onionoo response, aborting...')
        print(err)
        sys.exit()

    # generate relay HTML documents
    RELAY_SET.create_output_dir()
    RELAY_SET.write_unsorted('index.html', is_index=True)
    RELAY_SET.write_unsorted('all.html', is_index=False)
    RELAY_SET.write_effective_family()
    RELAY_SET.write_pages_by_key('as')
    RELAY_SET.write_pages_by_key('country')
    RELAY_SET.write_pages_by_key('platform')
    RELAY_SET.write_pages_by_flag()
Example #4
0
from relays import Relays
import tracker
import os
import json
import logging

logger = logging.getLogger('State')

relays = Relays()
rooms = {}
tmpHold = False
settings = {}
weather = {}

# First, load defaults (or newly added settings
try:
    with open('settings.default.json') as df:
        settings = json.load(df)
except:
    logger.error('Could not load default settings file!')

# Now try and load settings from a saved settings file
try:
    with open('settings.json') as f:
        settings = {**settings, **json.load(f)}
        logger.info('Loaded settings from file:')
        logger.info(settings)
except:
    logger.warning('Settings file not found. Using default file!')

# Set the current avgTmp to the current setTmp