Python 多蓝牙设备扫描

Python 多蓝牙设备扫描,python,raspberry-pi,Python,Raspberry Pi,我是新手。我一直在尝试扩展一些代码来扫描多个设备,而不是一部手机。 这是原始代码: import automationhat import bluetooth import time while True: print "Checking " + time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()) result = bluetooth.lookup_name('B0:70:2D:D0:C9:XX', timeout=5)

我是新手。我一直在尝试扩展一些代码来扫描多个设备,而不是一部手机。 这是原始代码:

import automationhat
import bluetooth
import time

while True:
    print "Checking " + time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime())
    result = bluetooth.lookup_name('B0:70:2D:D0:C9:XX', timeout=5)
    if (result != None):
        print "User present"
        automationhat.relay.one.on()
        time.sleep(2)
        automationhat.relay.one.off()
        time.sleep(200)
    else:
        print "User out of range"
        automationhat.relay.one.off()
    time.sleep(5)
在我尝试扩展它之后

import automationhat
import bluetooth
import time

DEVICES=['D8:BB:2C:XX:22:17', '34:AB:37:EA:XX:XX', '74:8D:08:XX:XX:7B']

while True:

        print "Checking " + time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime())

        for device in DEVICES:
                result = bluetooth.lookup_name(device, timeout=5)
        if (result != None):
                print "User present"
                automationhat.relay.one.on()
                time.sleep(2)
                automationhat.relay.one.off()
                time.sleep(20)
        else:
                print "User out of range"
                automationhat.relay.one.off()

        time.sleep(10)
<>但是它似乎只考虑了设备列表中的最后一个设备。 我错过了什么? 很抱歉问你这个“愚蠢”的问题,但我才刚开始,在网上找不到任何东西。
Cheers

看起来处理
结果的操作超出了设备中设备的
范围:
循环,因此
结果始终具有最后一个设备的值

缩进下面的代码
result=bluetooth.lookup\u name(设备,超时=5)
,使其处于同一级别