Ejemplo n.º 1
0
def main(argv):
    #If True, data will print to shell as well as write to file
    #If False, data will only write to file
    verb = ''
    if len(sys.argv) == 2:
        if sys.argv[1] == '-v' or sys.argv[1] == '-verb' or sys.argv[
                1] == '-verbose':
            verb = True
        else:
            print("Invalid argument. Valid argument(s): -v[erbose]")
    else:
        verb = False

    #Initialize file path for readings
    fpath = "/home/pi/MSD-P21422-BSF/Readings/"

    #Initialize data variables
    in_temp_f, in_temp_c, out_temp_f, out_temp_c, in_hum, out_hum, co2 = 0, 0, 0, 0, 0, 0, 0
    today, now = '0', '0'

    dbx = 0
    db_connect = False

    #Check if connected to internet
    if check_connection():
        #If connected to internet, establish dropbox connection
        dbx, db_connect = db_access()

    while True:
        today, now = cur_date_time(today, now, verb)
        file_name = date.strftime(date.today(), '%Y%m%d.csv')
        full_path = fpath + file_name
        in_temp_f, in_temp_c, out_temp_f, out_temp_c, in_hum, out_hum, co2 = \
                    sensor.sensor(in_temp_f, in_temp_c, out_temp_f, out_temp_c, in_hum, out_hum, co2, verb)
        heat_stat, hum_stat, fan_stat, light_stat = relay.relay(
            in_temp_f, in_hum, co2, verb)
        write_to_csv(in_temp_f, in_temp_c, out_temp_f, out_temp_c, in_hum,
                     out_hum, co2, today, now, heat_stat, hum_stat, fan_stat,
                     light_stat, full_path)

        # Check the internet connection
        if check_connection():
            #If connected to internet but not dropbox
            if db_connect == False:
                #Establish dropbox connection
                dbx, db_connect = db_access()

            #If connected to internet and to dropbox
            if db_connect == True:
                #Upload file to dropbox
                print("Uploading the file...")
                upload('/' + file_name, full_path, dbx)
                print("Upload successful")
        #TO-DO:
        #If connection is down for more than a day, add a case to upload files that were missed

        #sleep in seconds. 60 = 1 minute, 300 = 5 minutes, 1800 = 30 minutes
        time.sleep(599.0)
    return
def main():
    if GPIO.input(Laser) == False:
        print("Laser Detected")
        time.sleep(3)
        measure1 = usonic.measure(Trig, Echo)
        measure2 = usonic.measure(Trig2, Echo2)
        print(measure1, measure2)

        date = datetime.datetime.now()
        cur_date = str(date.strftime("%Y-%m-%d"))
        cur_time = str(date.strftime("%H:%M:%S"))
        img_name = "{0} {1}.jpg".format(cur_date, cur_time)
        m1 = ( measure1 / 32)*100
        m2 = ( measure2 / 26)*100
        avg = int((m1+m2)/2)

        json_data = {
        "latest":{
            "file":str(cur_date+"/"+img_name),
            "date":cur_date, 
            "time":cur_time
            },
        "measure1":m1,
        "measure2":m2,
        "avg":avg
        }

        with open("data.json",'w') as json_out:
            json.dump(json_data, json_out)
        json_out.close()

        print(img_name)
        relay.relay(Relay, 0)
        cam.camera_take(image_save_dir+img_name)
        time.sleep(1)
        relay.relay(Relay, 1)
        upload_blob(bucket_name, "data.json", "data.json")
        upload_blob(bucket_name, image_save_dir+img_name, str(image_save_dir+cur_date+"/"+img_name))
        body = "Your mailbox was triggered on {0} {1}\nYou can view more info on https://rich-ripple-262608.appspot.com".format(cur_date, cur_time)
        sendmail.send_mail("IOT Mailbox got Mail", body)
Ejemplo n.º 3
0
    def move(self, x, y):
    
        utils.player.x += x
        utils.player.y += y
        if x > 0:
            utils.direction = "right"
        elif x < 0:
            utils.direction = "left"
        elif y > 0:
            utils.direction = "down"
        elif y < 0:
            utils.direction = "up"

        if utils.player.x <= 0:
            utils.player.x -= x
        elif utils.player.x >= 800 - 32:
            utils.player.x -= x
        elif utils.player.y <= 0:
            utils.player.y -= y
        elif utils.player.y >= 600 - 32:
            utils.player.y -= y

        relay.relay({"type":"player", "x":utils.player.x, "y":utils.player.y, "id":utils.id_, "health":utils.health})
Ejemplo n.º 4
0
    def __init__(self):
        for key in hotpiConfig['devices'].keys():
            device = hotpiConfig['devices'][key]

            if device['type'] == 'ds18b20':
                device['handler'] = ds18b20(device)

            elif device['type'] == 'ct30':
                device['handler'] = ct30(device)

            elif device['type'] == 'relay':
                device['handler'] = relay(device)

            elif device['type'] == 'semaphore':
                device['handler'] = semafile(device)
Ejemplo n.º 5
0
    def update(self):
        if len(utils.enemies) < utils.max_enemies:
            top_bottom = random.randint(0, 1)
            left_right = random.randint(0, 1)
            sides_top = random.randint(0, 1)
            if sides_top == 1 and top_bottom == 1: # Bottom
                enemy = {"x":random.randint(0, 800), "y":800, "health":100}
            elif sides_top == 1 and top_bottom == 0: # Top
                enemy = {"x":random.randint(0, 800), "y":0, "health":100}

            elif sides_top == 0 and top_bottom == 1: # Left
                enemy = {"x":random.randint(0, 800), "y":0, "health":100}

            else:
                enemy = {"x":random.randint(0, 800), "y":800, "health":100}
            enemy['type'] = "enemy" 
            relay.relay(enemy)

        for index,  enemy in enumerate(utils.enemies):
            try:
                self.collide(index)
            except:
                pass
            self.animate(index)
Ejemplo n.º 6
0
def main():
    id = 27
    r = relay(id)
    r.output(True)
    r.output(False)
    r.cleanup()
Ejemplo n.º 7
0
        print 'Started httpserver on port ' , PORT_NUMBER

        #Wait forever for incoming htto requests
        server.serve_forever()

    except KeyboardInterrupt:
        print '^C received, shutting down the web server'
        server.socket.close()


# Runs the web server thread
thread.start_new_thread(WebServerThread,())
iremote = IRemote()
iremote.add_listener(my_iremote_handler)
iremote.start()
theRelay = relay()
player = iTunes()
alarm = wecker(player,theRelay)
alarm.start()
beamer = projector()
room = my_hue()
#theTimer = sleeptimer(player,theRelay)
print 'Remote catch up and running'

while True:
    try:
        if alarm_set and not alarm.alarm_set:
            alarm.set_time(alarm_time)
            #alarm_set = True
            #alarm_on = True
        if not alarm_set and alarm.alarm_set:
Ejemplo n.º 8
0
    return retval


logging.basicConfig(level=logging.INFO)

system('clear')

print('Python GSM control module')
print('by Yves Pattyn,  June 2019')
print('--------------------------')

now = datetime.now()
logging.info("Current date is : %s" % now.strftime("%d-%m-%y %H:%M:%S"))
logging.info("IP Address of this RaspberryPi is: %s" % getIPaddress())

r = relay(12, "Testing")
r.off()
try:
    out = system('ls /dev/ttyU*')
except:
    logging.error('Failed system call')

ser = serial.Serial(port="/dev/ttyUSB0", baudrate=460800, timeout=1)
# ATtention - Set Echo Off
serialCommand(ser, "ATE0\r\n")

# Preferred Message Storage
logging.info("Setting Preferred Message Storage to SIM card.")
cmd = 'AT+CPMS="SM","SM","SM"\r\n'
serialCommand(ser, cmd)
Ejemplo n.º 9
0
# see the README file for more details

CONFIG ='CONFIG'

# first read the config file
conf = door.readConfig(CONFIG)
print conf

# then load the database of authorized RFID tags
tagsDB = rfid.tagsDB(conf['rfidDB'][0])		# read the rfid.db (database) if CONFIG Debug mode is True, add first index of tag to database?




# then instantiate the relays
strikeRelay = relay.relay(conf['strikeRelay'])
doorRelay = relay.relay(conf['doorRelay'])

# then the door lock
doorLock = zwaving.zwave(conf['vera'][0])
doorId = int(conf['doorId'][0])				# door ID is 16 in CONFIG (not sure why)

# then start threads for each RFID reader
for dev in conf['rfidReader']:
    rfid.readRFID(dev, tagsDB, doorLock, doorId).start() #??? is .start() specifically for things that are being threaded?
    rfid.readRFID(dev, tagsDB, doorLock, doorId).start() #??? is .start() specifically for things that are being threaded?
											
# instantiate object to perform open action
delay = float(conf['openDelay'][0])
action = door.opendoor(strikeRelay, doorRelay, delay)
Ejemplo n.º 10
0
BACKLIGHT_DIM_SECONDS = 30

BACKLIGHT_BRIGHT_LEVEL = 50
BACKLIGHT_DIM_LEVEL = 20

# Global objects for our hardware devices
DOOR = door.door(door_pin, door_open_state)

if rotary is not None:
    encoder = rotaryEncoder.rotaryEncoder(rotary_A, rotary_B, rotary_PB)
else:
    encoder = rotaryEncoder.rotaryEncoder(0, 0, 0, dummy=True)

encoder.start()

heater = relay.relay(relay_HOT, invert=invert_hot)
cooler = relay.relay(relay_COLD, invert=invert_cold)

# Nokia LCD has 17 chars by 6 lines, but original display and web display
# show 20 chars by 4 lines, so make a buffer at least that big.
LCD = lcd.lcd(lines=6, chars=20, hardware=LCD_hardware)

tempControl = tempControl.tempController(ID_fridge,
                                         ID_beer,
                                         ID_ambient,
                                         cooler=cooler,
                                         heater=heater,
                                         door=DOOR)

# Set the temperature calibration offsets (if available)
# FIXME - This should be part of deviceManager & saved to/loaded from the eeprom
Ejemplo n.º 11
0
 def shoot(self):
 
     relay.relay({"type":"bullet", "x":utils.player.x, "y":utils.player.y, "direction":utils.direction, "id":uuid.uuid4().hex})
Ejemplo n.º 12
0
print('log - ', path.logPath, '\n')
# ZAPIS NASTAW DO PLIKU
settings.settingsWrite(temp_zad1, temp_zad2, histereza, time_sleep, run)
# PĘTLA GŁÓWNA
while run:  # jezeli 0 to stop
    set = settings.settingsRead()  # ODCZYT NASTAW Z PLIKU
    temp_zad1_F = set[0]
    temp_zad2_F = set[1]
    histereza_F = set[2]
    time_sleep_F = set[3]
    run = set[4]
    temperatura = read_temp()  # ODCZYT SENSORA
    local_time = loc_time()  # ODCZYT DATY
    data = local_time[1]
    godzina = local_time[2]
    relayMesage = relay.relay(pin, temperatura, temp_zad1_F, histereza_F)  # WYSTEROWANIE WYJSCIA
    # WYDRUK POMIARU
    if temperatura > temp_zad1_F and temperatura < temp_zad2_F:
        color = '\x1b[1;32;40m'
        message = ' ' + relayMesage
    else:
        color = '\x1b[1;31;40m'
        if temperatura < temp_zad1_F:
            message = '!!! Temp. poniżej dolnej granicy !!! ' + relayMesage

        elif temperatura > temp_zad2_F:
            message = '!!! Temp. powyzej górnej granicy !!! ' + relayMesage

    print(godzina + ' ' + color + str(temperatura) + '°C ' + message + '\x1b[0m')

    # ZAPIS POMIARU
Ejemplo n.º 13
0
BACKLIGHT_DIM_SECONDS = 30

BACKLIGHT_BRIGHT_LEVEL = 50
BACKLIGHT_DIM_LEVEL = 20

# Global objects for our hardware devices
DOOR = door.door(door_pin, door_open_state)

if rotary is not None:
    encoder = rotaryEncoder.rotaryEncoder(rotary_A, rotary_B, rotary_PB)
else:
    encoder = rotaryEncoder.rotaryEncoder(0, 0, 0, dummy=True)

encoder.start()

heater = relay.relay(relay_HOT, invert=invert_hot)
cooler = relay.relay(relay_COLD, invert=invert_cold)


# Nokia LCD has 17 chars by 6 lines, but original display and web display
# show 20 chars by 4 lines, so make a buffer at least that big.
LCD = lcd.lcd(lines=6, chars=20, hardware=LCD_hardware)

tempControl = tempControl.tempController(ID_fridge, ID_beer, ID_ambient,
                                         cooler=cooler, heater=heater, door=DOOR)

# Set the temperature calibration offsets (if available)
# FIXME - This should be part of deviceManager & saved to/loaded from the eeprom
tempControl.fridgeSensor.calibrationOffset = fridgeCalibrationOffset
tempControl.beerSensor.calibrationOffset = beerCalibrationOffset
tempControl.ambientSensor.calibrationOffset = ambientCalibrationOffset
Ejemplo n.º 14
0
def test_one():
    relay.relay()
    with codecs.open('output.json', 'r', encoding='utf-8') as jfile:
        data = json.load(jfile)
    expect = [{
        'id': 6634,
        'result': 1,
        'time': '2:25:18'
    }, {
        'id': 1742,
        'result': 1,
        'time': '2:25:18'
    }, {
        'id': 4983,
        'result': 2,
        'time': '2:25:52'
    }, {
        'id': 2479,
        'result': 2,
        'time': '2:25:52'
    }, {
        'id': 5190,
        'result': 2,
        'time': '2:25:52'
    }, {
        'id': 4867,
        'result': 3,
        'time': '2:27:23'
    }, {
        'id': 919,
        'result': 3,
        'time': '2:27:23'
    }, {
        'id': 829,
        'result': 4,
        'time': '2:28:07'
    }, {
        'id': 5923,
        'result': 4,
        'time': '2:28:07'
    }, {
        'id': 4462,
        'result': 4,
        'time': '2:28:07'
    }, {
        'id': 3034,
        'result': 5,
        'time': '2:32:25'
    }, {
        'id': 2064,
        'result': 5,
        'time': '2:32:25'
    }, {
        'id': 5619,
        'result': 5,
        'time': '2:32:25'
    }, {
        'id': 5411,
        'result': 6,
        'time': '2:33:45'
    }, {
        'id': 182,
        'result': 6,
        'time': '2:33:45'
    }, {
        'id': 3884,
        'result': 6,
        'time': '2:33:45'
    }, {
        'id': 5188,
        'result': 7,
        'time': '2:44:44'
    }, {
        'id': 6162,
        'result': 7,
        'time': '2:44:44'
    }, {
        'id': 986,
        'result': 7,
        'time': '2:44:44'
    }, {
        'id': 394,
        'result': 8,
        'time': '3:15:09'
    }, {
        'id': 995,
        'result': 8,
        'time': '3:15:09'
    }, {
        'id': 350,
        'result': 8,
        'time': '3:15:09'
    }, {
        'id': 18442,
        'result': 1,
        'time': '2:04:26'
    }, {
        'id': 10138,
        'result': 1,
        'time': '2:04:26'
    }, {
        'id': 9529,
        'result': 1,
        'time': '2:04:26'
    }, {
        'id': 12357,
        'result': 2,
        'time': '2:05:26'
    }, {
        'id': 10816,
        'result': 2,
        'time': '2:05:26'
    }, {
        'id': 17304,
        'result': 2,
        'time': '2:05:26'
    }, {
        'id': 17447,
        'result': 3,
        'time': '2:05:43'
    }, {
        'id': 15737,
        'result': 3,
        'time': '2:05:43'
    }, {
        'id': 15748,
        'result': 3,
        'time': '2:05:43'
    }, {
        'id': 15946,
        'result': 4,
        'time': '2:07:41'
    }, {
        'id': 16077,
        'result': 4,
        'time': '2:07:41'
    }, {
        'id': 14392,
        'result': 4,
        'time': '2:07:41'
    }, {
        'id': 11846,
        'result': 5,
        'time': '2:09:17'
    }, {
        'id': 9777,
        'result': 5,
        'time': '2:09:17'
    }, {
        'id': 7939,
        'result': 6,
        'time': '2:13:23'
    }, {
        'id': 15943,
        'result': 6,
        'time': '2:13:23'
    }, {
        'id': 15478,
        'result': 6,
        'time': '2:13:23'
    }, {
        'id': 13198,
        'result': 7,
        'time': '2:14:45'
    }, {
        'id': 10354,
        'result': 7,
        'time': '2:14:45'
    }, {
        'id': 9272,
        'result': 7,
        'time': '2:14:45'
    }, {
        'id': 11612,
        'result': 8,
        'time': '2:16:09'
    }, {
        'id': 15148,
        'result': 8,
        'time': '2:16:09'
    }, {
        'id': 8263,
        'result': 8,
        'time': '2:16:09'
    }, {
        'id': 8150,
        'result': 9,
        'time': '2:19:21'
    }, {
        'id': 9760,
        'result': 9,
        'time': '2:19:21'
    }, {
        'id': 14485,
        'result': 10,
        'time': '2:22:01'
    }, {
        'id': 15654,
        'result': 10,
        'time': '2:22:01'
    }, {
        'id': 7411,
        'result': 10,
        'time': '2:22:01'
    }, {
        'id': 6902,
        'result': 11,
        'time': '2:21:41'
    }, {
        'id': 9423,
        'result': 11,
        'time': '2:21:41'
    }, {
        'id': 13291,
        'result': 11,
        'time': '2:21:41'
    }, {
        'id': 15533,
        'result': 12,
        'time': '2:30:29'
    }, {
        'id': 13583,
        'result': 13,
        'time': '2:35:42'
    }, {
        'id': 10891,
        'result': 13,
        'time': '2:35:42'
    }, {
        'id': 11886,
        'result': 13,
        'time': '2:35:42'
    }, {
        'id': 16741,
        'result': 14,
        'time': '2:38:26'
    }, {
        'id': 8526,
        'result': 14,
        'time': '2:38:26'
    }, {
        'id': 16354,
        'result': 14,
        'time': '2:38:26'
    }, {
        'id': 17020,
        'result': 15,
        'time': '2:57:59'
    }, {
        'id': 7077,
        'result': 15,
        'time': '2:57:59'
    }]
    assert all(x in expect for x in data) and len(data) == len(expect)