Exemplo n.º 1
0
def b*****b(rfid, seconds):
    global stamp, realstamp, punmqtt

    devices = slaves.get_device(rfid)
    slave_id = slaves.get_id(rfid)

    if realstamp[rfid] > 0 and realstamp[rfid] < int(
            datetime.timestamp(datetime.now())):
        showLogo()
        realstamp[rfid] = 0

    for dev in devices:
        if tordevices.support_function(dev['device'], 'b*****b'):
            device = tordevices.get_device(dev['device'])
            funcs = tordevices.get_functions(dev['device'], 'b*****b')
            for i in funcs:
                if int(datetime.timestamp(datetime.now())) > stamp[rfid]:
                    seconds = int(seconds)
                    stamp[rfid] = int(datetime.timestamp(
                        datetime.now())) + seconds + random.randint(10, 120)
                    realstamp[rfid] = int(datetime.timestamp(
                        datetime.now())) + seconds

                    if device['protocol'] == "MQTT":
                        punmqtt.publish(
                            'punisher/slave/' + str(slave_id) + '/b*****b',
                            '{"seconds": 60, "countdown": 100}')
                    if i['image'] != "":
                        showfunc(i['image'])
Exemplo n.º 2
0
def rfid():
    (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
    if status == MIFAREReader.MI_OK:
        (status,uid) = MIFAREReader.MFRC522_Anticoll()
        key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
        try:
            MIFAREReader.MFRC522_SelectTag(uid)
        except:
            log.warning('RFID has an error')
        status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 8, key, uid)
        if status == MIFAREReader.MI_OK:
            data = MIFAREReader.MFRC522_Read(8)
            MIFAREReader.MFRC522_StopCrypto1()
            slaveid = listToString(data[:9])
            cursor.execute('SELECT * FROM slaves, program WHERE slave_rfid = "'+slaveid+'" AND pro_id = slave_program')
            slave = cursor.fetchone()
            if slave is None:
                logger.info( 'Slave not found - RFID '+slaveid )
                showLCD('Slave not found','')
                sleep(2)
                defaultLCD()
            else:
                if slaves.slave_online( slave[1] ):
                    logger.debug( "Slave '"+slave[2]+"'  disconnected - RFID "+slaveid )
                    devices = slaves.get_device( slave[1] )

                    for dev in devices:
                        device = tordevices.get_device( dev['device'] )

                        if device['protocol'] == "MQTT":
                            punmqtt.publish("punisher/devices/"+dev['device']+"/settings", "{\"slave_id\": 0, \"slave_name\": \""+slave[2]+"\"} ");

                    slaves.remove_slave( slave[1] )
                    showLCD(slave[2], 'Slave disconnected')
                    sleep(2)
                    showLCD('Training program', 'disabled...')
                    sleep(2)
                    defaultLCD()
                else:
                    logger.debug( "Slave '"+slave[2]+"' connected - RFID "+slaveid )
                    slaves.add_slave( slave[0], slave[1], slave[2], slave[3], slave[6], slave[7] )
                    stamp[ slave[1] ] = datetime.timestamp( datetime.now() )
                    realstamp[ slave[1] ] = datetime.timestamp( datetime.now() )
                    cursor.execute('SELECT * FROM devtoslave, devices WHERE dts_slaveid = "'+str(slave[0])+'" AND dev_id = dts_deviceid')
                    device = cursor.fetchall()
                    for dev in device:
                        if tordevices.device_online( dev[4] ):
                            slaves.add_device( slave[1], slave[2], dev[4] )
                            punmqtt.publish("punisher/devices/"+dev[4]+"/settings", "{\"slave_id\": "+str(slave[0])+", \"slave_name\": \""+slave[2]+"\"} ");

                    showLCD(slave[2], 'Slave connected')
                    sleep(2)
                    showLCD('Training program', slave[6]+' started...')
                    sleep(2)
                    defaultLCD()
Exemplo n.º 3
0
def shock_punish( rfid, seconds ):
    global stamp, realstamp
    devices = slaves.get_device( rfid )
    slave_id = slaves.get_id( rfid )

    for dev in devices:
        if tordevices.support_function( dev['device'], 'tens' ):
            device = tordevices.get_device( dev['device'] )
            funcs   = tordevices.get_functions( dev['device'], 'tens' )
            for i in funcs:
                if device['protocol'] == "MQTT":
                    punmqtt.publish('punisher/slave/'+str(slave_id)+'/shock', '{"seconds": '+str(seconds)+', "countdown": '+str(counter)+'}' )
                if i['image'] != "":
                    showfunc( i['image'] )
Exemplo n.º 4
0
def shock( rfid, mode ):
    global stamp, realstamp, punmqtt

    devices = slaves.get_device( rfid )
    slave_id = slaves.get_id( rfid )

    if realstamp[ rfid ] > 0 and realstamp[ rfid ] < int( datetime.timestamp( datetime.now()) ):
        showLogo()
        realstamp[ rfid ] = 0

    for dev in devices:
        if tordevices.support_function( dev['device'], 'tens' ):
            device = tordevices.get_device( dev['device'] )
            funcs   = tordevices.get_functions( dev['device'], 'tens' )
            for i in funcs:
                if int(datetime.timestamp( datetime.now()) ) > stamp[ rfid ]:
                    value = random.randint(0, 30)
                    counter = random.randint(0, 30)
                    if value == 1:
                        mode = randint(1,6)
                        if mode == 1:
                            seconds = 10
                        elif mode == 2:
                            seconds = 30
                        elif mode == 3:
                            seconds = 60
                        elif mode == 4:
                            seconds = 90
                        elif mode == 5:
                            seconds = 120
                        elif mode == 6:
                            seconds = 160

                        stamp[ rfid ]     = int(datetime.timestamp( datetime.now() )) + seconds + counter +random.randint(10, 120)
                        realstamp[ rfid ] = int(datetime.timestamp( datetime.now() )) + seconds + counter
                        if device['protocol'] == "MQTT":
                            punmqtt.publish('punisher/slave/'+str(slave_id)+'/shock', '{"seconds": '+str(seconds)+', "countdown": '+str(counter)+'}' )
                        if i['image'] != "":
                            showfunc( i['image'] )