Example #1
0
def readUIDofRFID():
    print "-----------------------------------Starting MFRC522 chip reader---------------------------------------------"
    # This loop keeps checking for chips. If one is near it will get the UID and authenticate
    while CONTINUE_READING:
        # Scan for cards
        (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
        # If a card is found
        # Get the UID of the card
        (status,uid) = MIFAREReader.MFRC522_Anticoll()
        # If we have the UID, continue
        if status == MIFAREReader.MI_OK:
             global RFID_CARD_UID
             RFID_CARD_UID = str(uid[0])+":"+str(uid[1])+":"+str(uid[2])+":"+str(uid[3])
             print "Card read UID: " + RFID_CARD_UID
             # This is the default key for authentication
             key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
             # Select the scanned tag
             MIFAREReader.MFRC522_SelectTag(uid)
             # Authenticate
             status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 8, key, uid)
             # Check if authenticated
             if status == MIFAREReader.MI_OK:
                 MIFAREReader.MFRC522_Read(8)
                 MIFAREReader.MFRC522_StopCrypto1()
             if(isRFIDCardRegistered(RFID_CARD_UID)):
                 print "Authentication successful"
                 GPIO.output(iotUtils.LOCK_STATE_OFF_NOTIFY_PORT, GPIO.LOW)
                 GPIO.output(iotUtils.LOCK_STATE_ON_NOTIFY_PORT, GPIO.HIGH)
                 GPIO.output(iotUtils.DOOR_LOCKER_2_PORT, GPIO.LOW)
                 GPIO.output(iotUtils.DOOR_LOCKER_1_PORT, GPIO.LOW)
                 MQTTHandler.on_publish(MQTTHandler.mqttClient,"Locker:UNLOCKED")
    return True
Example #2
0
def main():
    configureLogger("AutomaticDoorLocker")
    ListenMQTTThread()
    ListenRFIDhread()
    initDoorLock()
    # registerUIDofRFIDCard()  # Call the register endpoint and register Device I
    # ListenMQTTThread()

    while True:
        try:
            currentTime = calendar.timegm(time.gmtime())
            sensorValue = getSensorValue()
            PUSH_DATA_TO_STREAM_1 = iotUtils.SENSOR_STATS_SENSOR1.format(
                currentTime, sensorValue)
            MQTTHandler.on_publish(MQTTHandler.mqttClient,
                                   MQTTHandler.TOPIC_TO_PUBLISH_STREAM1,
                                   PUSH_DATA_TO_STREAM_1)
            sensorValue = getSensorValue()
            PUSH_DATA_TO_STREAM_2 = iotUtils.SENSOR_STATS_SENSOR2.format(
                currentTime, sensorValue)
            MQTTHandler.on_publish(MQTTHandler.mqttClient,
                                   MQTTHandler.TOPIC_TO_PUBLISH_STREAM2,
                                   PUSH_DATA_TO_STREAM_2)
            print '~~~~~~~~~~~~~~~~~~~~~~~~ Publishing Device-Data ~~~~~~~~~~~~~~~~~~~~~~~~~'
            print('PUBLISHED DATA STREAM 1: ' + PUSH_DATA_TO_STREAM_1)
            print('PUBLISHED DATA STREAM 2: ' + PUSH_DATA_TO_STREAM_2)
            time.sleep(PUSH_INTERVAL)
        except (KeyboardInterrupt, Exception) as e:
            print "AutomaticDoorLockerStats: Exception in RaspberryAgentThread (either KeyboardInterrupt or Other)"
            print("AutomaticDoorLockerStats: " + str(e))
            print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
            pass
def main():
    configureLogger("AutomaticDoorLocker")
    ListenMQTTThread()
    ListenRFIDhread()
    initDoorLock()
    # registerUIDofRFIDCard()  # Call the register endpoint and register Device I
    # ListenMQTTThread()

    while True:
        try:
            currentTime = calendar.timegm(time.gmtime())
            sensorValue = getSensorValue()
            PUSH_DATA_TO_STREAM_1 = iotUtils.SENSOR_STATS_SENSOR1.format(currentTime, sensorValue)
            MQTTHandler.on_publish(MQTTHandler.mqttClient, MQTTHandler.TOPIC_TO_PUBLISH_STREAM1, PUSH_DATA_TO_STREAM_1)
            sensorValue = getSensorValue()
            PUSH_DATA_TO_STREAM_2 = iotUtils.SENSOR_STATS_SENSOR2.format(currentTime, sensorValue)
            MQTTHandler.on_publish(MQTTHandler.mqttClient, MQTTHandler.TOPIC_TO_PUBLISH_STREAM2, PUSH_DATA_TO_STREAM_2)
            print '~~~~~~~~~~~~~~~~~~~~~~~~ Publishing Device-Data ~~~~~~~~~~~~~~~~~~~~~~~~~'
            print ('PUBLISHED DATA STREAM 1: ' + PUSH_DATA_TO_STREAM_1)
            print ('PUBLISHED DATA STREAM 2: ' + PUSH_DATA_TO_STREAM_2)
            time.sleep(PUSH_INTERVAL)
        except (KeyboardInterrupt, Exception) as e:
            print "AutomaticDoorLockerStats: Exception in RaspberryAgentThread (either KeyboardInterrupt or Other)"
            print ("AutomaticDoorLockerStats: " + str(e))
            print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
            pass
Example #4
0
 def run(self):
     MQTTHandler.main()