Example #1
0
def main():
    # Initial check for update; exit if there is an update
    if git_utils.git_pull() != 'Already up-to-date.\n':
        # TO-DO: This currently logs an update even when there is a git pull error
        utils.log_error('update')
        return 0

    if not os.path.isdir(LOG_DIR):
        os.mkdir(LOG_DIR)
    
    utils.log_error('bootup', data=git_utils.git_tag())

    global DRIVE_AUTH
    DRIVE_AUTH = utils.google_auth()

    global OPEN_DOOR_DISTANCE_CM
    OPEN_DOOR_DISTANCE_CM = set_threshold()
    print('Threshold set to {} cm'.format(OPEN_DOOR_DISTANCE_CM))

    global RASPI_SERIAL_NUM
    RASPI_SERIAL_NUM = utils.get_serial()

    setup_gpio()
    firebase_connection = firebase_utils.get_firebase_connection(FIREBASE_URL)
    
    previous_door_state = get_door_state_from_str(firebase_utils.get_status(firebase_connection, RASPI_SERIAL_NUM))
    if not previous_door_state:
        previous_door_state = DoorState.unknown

    while True:
        # Upload log file at 01:00-01:01
        if datetime.datetime.now().hour == 1 and datetime.datetime.now().minute < 2:
            utils.upload_log_files(DRIVE_AUTH)

        command = firebase_utils.get_command(firebase_connection, RASPI_SERIAL_NUM)
        if command:
            process_command(firebase_connection, command)

        current_door_state = check_door_status()
        if current_door_state != previous_door_state:
            # Double check this new reading in case it was faulty
            time.sleep(1)
            door_state_verification = check_door_status()
            if current_door_state == door_state_verification:
                previous_door_state = current_door_state
                firebase_utils.update_status(firebase_connection, utils.get_serial(), current_door_state.name)
                firebase_utils.notify_users(firebase_connection, RASPI_SERIAL_NUM, API_KEY, current_door_state.name)

        # Exit if there is an update.
        git_pull_result = git_utils.git_pull()
        if git_pull_result:
            if git_pull_result != 'Already up-to-date.\n':
                utils.log_error('update')
                return 0

        time.sleep(0.5)
Example #2
0
    def __init__(self):
        self.mesh = MeshNet(master=True)
        self.api = Api()
        self.id = get_serial()

        self.node_addresses = {}
        self.node_info = NodeInfo()
Example #3
0
def process_command(firebase_connection, command):
    utils.print_with_timestamp('Processing command: {}'.format(command))
    if command == ValidCommands.checkDoorStatus.name:
        utils.print_with_timestamp('checkDoorStatus command')
        status = check_door_status()
        firebase_utils.update_status(firebase_connection, utils.get_serial(), status.name)
        print('Door is {}'.format(status.name))
    elif command == ValidCommands.openDoor.name:
        utils.print_with_timestamp('openDoor command')
        open_door()
    elif command == ValidCommands.closeDoor.name:
        utils.print_with_timestamp('closeDoor command')
        close_door()
    elif command == ValidCommands.calibrate.name:
        utils.print_with_timestamp('calibrate command')
        calibrate(firebase_connection)
    elif command.split('-')[0] == ValidCommands.updateLogFile.name:
        # Proper structure of this firebase command is "udateLogFile-YYY_MM_DD"
        # If the date poriton is omittied ("updateLogFile"), today's file will be uploaded
        # as was previously the case
        if len(command.split('-')) > 1:
            date = command.split('-')[1]
        else:
            # Create today's date
            date = datetime.datetime.strftime(datetime.datetime.now(), '%Y_%m_%d')
        utils.print_with_timestamp('updateLogFile command')
        utils.upload_log_files(DRIVE_AUTH, desired_date=date)
    else:
        utils.print_with_timestamp('invalid command')
        utils.log_error('processed-invalid-command', data=command)
def get_firebase_connection(url):
    # Get password from secrets.txt (created manually on each device)
    # This is located in firebase under settings>Service accounts> Database secrets
    # You must be logged in as admin, not as rasmcfall
    with open('secrets.txt', 'r') as f:
        password = f.readline().strip()

    authentication = firebase.FirebaseAuthentication(password, '*****@*****.**',
        extra={'id': utils.get_serial()})
    return firebase.FirebaseApplication(url, authentication=authentication)
Example #5
0
    def __init__(self, temperature_sensor):
        self.temperature_sensor = temperature_sensor
        self.rotary_encoder = RotaryEncoder(self)
        self.power = Power(POWER_PIN)
        self.model = ServerModel(get_serial())

        self.boil_temps = [60, 65, 70, 75, 80, 85, 90, 95, 100]
        self.boil_volumes = [0.50, 0.75, 1.00, 1.25, 1.50, 1.75]

        self.menu = RpiLCDMenu()
        self.init_menu()
Example #6
0
debug_flag = 0
mqtt_flag = 0
file_flag = 0

# Edge parameters, environment variable based
DEFAULT_LAT = '0.0001'
DEFAULT_LON = '0.0001'
DEFAULT_CONTRACT_ADDR = '0x0000000000000000000000000000000000000000'

## Get edge device env var's for WIoTP publish
# Check primary env vars first
hzn_organization = utils.check_env_var(
    'HZN_ORGANIZATION')  # automatically passed in by Horizon
#wiotp_device_auth_token = utils.check_env_var('WIOTP_DEVICE_AUTH_TOKEN')  # note: this is no longer needed because we can now send msgs an an app to edge-connector unauthenticated, as long as we are local.
hzn_device_id = utils.check_env_var(
    'HZN_DEVICE_ID', utils.get_serial()
)  # automatically passed in by Horizon. Wiotp automatically gives this a value of: g@mygwtype@mygw

# When the Workload is deployed by WIoTP-Horizon; HZN_DEVICE_ID ~= 'g@mygwtype@mygw'.
ids = hzn_device_id.split('@')
if len(ids) == 3:
    class_id, device_type, device_id = ids  # the class id is not actually used anymore
else:
    utils.print_("Error: HZN_DEVICE_ID must have the format: g@mygwtype@mygw")

#utils.print_("Workload config.py: Optional override environment variables:")
#utils.print_("Workload config.py:   WIOTP_CLASS_ID=" + utils.check_env_var('WIOTP_CLASS_ID', '', False))
#utils.print_("Workload config.py:   WIOTP_DEVICE_TYPE=" + utils.check_env_var('WIOTP_DEVICE_TYPE', '', False))
#utils.print_("Workload config.py:   WIOTP_DEVICE_ID=" + utils.check_env_var('WIOTP_DEVICE_ID', '', False))
utils.print_("Workload config.py: Derived variables:")
#utils.print_("Workload config.py:   CLASS_ID=" + class_id)
Example #7
0
def print_trajectory():
    coord_by_axis = tuple(zip(*trajectory))
    print("\n".join(map(repr, trajectory)))
    print("\nRange: [{}, {}], [{}, {}], [{}, {}]".format(
        min(coord_by_axis[0]),
        max(coord_by_axis[0]),
        min(coord_by_axis[1]),
        max(coord_by_axis[1]),
        min(coord_by_axis[2]),
        max(coord_by_axis[2]),
        ))
# Uncomment the statement below to print the double integration results
# when the program exits.
#atexit.register(print_trajectory)

ser = get_serial(None, 115200)
sample_period = 1.0 / 200
ma = mg.MadgwickAHRS(sampleperiod=sample_period)
count = 0

x_bias = 29.69433
y_bias = 3.20569
z_bias = -22.26908

l = 0.5
verticies = [[l, -l, -l],[l, l, -l],[-l, l, -l],[-l, -l, -l],[l, -l, l],[l, l, l],[-l, -l, l],[-l, l, l]]
# ini_qua = Quaternion(0.05, -0.116, 0.984, 0.001)
# for i in range(len(verticies)):
#     verticies[i] = ini_qua.rotate(verticies[i])
final_verticies = [[1, -1, -1],[1, 1, -1],[-1, 1, -1],[-1, -1, -1],[1, -1, 1],[1, 1, 1],[-1, -1, 1],[-1, 1, 1]]
edges = [[0,1],[0,3],[0,4],[2,1],[2,3],[2,7],[6,3],[6,4],[6,7],[5,1],[5,4],[5,7]]
Example #8
0
 def __init__(self):
     self.mesh = MeshNet(master=False)
     self.id = get_serial()
     self.functionality = None
     self.is_init = False