def rcvdBeacon(): global seq global thread_kill dev_id = 0 try: sock = bluez.hci_open_dev(dev_id) print("\n *** Looking for BLE Beacons ***\n") print("\n *** CTRL-C to Cancel ***\n") except: print("Error accessing bluetooth") ScanUtility.hci_enable_le_scan(sock) t = 0.0 #Scans for iBeacons try: while True: returnedList = ScanUtility.parse_events(sock, 100) #print(time.time(), returnedList) if returnedList: for item in returnedList: if seq >= 12: seq = 0 else: seq += 1 # print(item) # byteData = item #if beacons4Server[item['uuid']][1] beacons4Server[item['uuid']] = [item['rssi'], seq] #interval=time.time()-t #print(interval, beacons4Server) print(" ") else: for item in returnedList: beacons4Server[item['uuid']] = [0.0, -1] returnedList.clear() if thread_kill: break #t=time.time() except KeyboardInterrupt: pass
def start(self): p=re.compile(UUID_REGEX.lower()) try: sock = bluez.hci_open_dev(self.dev_id) except: print("Error accessing bluetooth") print(traceback.format_exc()) ScanUtility.hci_enable_le_scan(sock) # Scans for iBeacons try: while True: returnedList = ScanUtility.parse_events(sock, 10) for item in returnedList: if item['type'] is 'iBeacon' and \ p.match(item['uuid'].replace('-','').lower()) is not None: sg = item['minor'] / 1000 t_f = item['major'] self.grav = 135.997 * (sg ** 3) - 630.272 * (sg ** 2) + 1111.14 * sg - 616.868 self.temp = (t_f - 32) * 5 / 9. except KeyboardInterrupt: pass
def _scanLoop(self): #Set bluetooth device. Default 0. dev_id = 0 try: sock = bluez.hci_open_dev(dev_id) except: print("Error accessing bluetooth") ScanUtility.hci_enable_le_scan(sock) self.scanExit = False self.scanMutex.acquire() self.beaconList = {} self.scanMutex.release() while not self.scanExit: beacons = ScanUtility.parse_events(sock, 10) currTime = datetime.datetime.now() self.scanMutex.acquire() for beacon in beacons: if beacon['type'] == 'iBeacon': if beacon['uuid'] == str(self.uuid): self.beaconList[self._deviceKey(beacon)] = (currTime, beacon) ''' elif beacon['type'] == 'Overflow': if beacon['uuid'] == '2f234454-cf6d-4a0f-adf2-f4911ba9ffa6': print("Overflow:-------------") print(beacon) print("") ''' self.scanMutex.release()
def inLoop(): try: returnedList = ScanUtility.parse_events(sock, 10) if not returnedList is None: for item in returnedList: # print(item) # print(item['type']) if not item is None: if(item['type'] == "iBeacon"): return item ; else : return {} else : return {} except Exception as e: # print("inE1") # print (e) return {} pass
#This is a working prototype. DO NOT USE IT IN LIVE PROJECTS import ScanUtility import bluetooth._bluetooth as bluez import os #Set bluetooth device. Default 0. dev_id = 0 try: sock = bluez.hci_open_dev(dev_id) print("\n *** Looking for BLE Beacons ***\n") print("\n *** CTRL-C to Cancel ***\n") except: print("Error accessing bluetooth") ScanUtility.hci_enable_le_scan(sock) #Scans for iBeacons try: while True: returnedList = ScanUtility.parse_events(sock, 10) for item in returnedList: if item.get("macAddress") == "e2:e3:23:d1:b0:54": print("") os.system( "php /home/projektimies/Lighthouse/DatabaseInsert1.php") print("") print("BEACON 1") print(item.get("macAddress")) print(item.get("rssi")) print("") if item.get("macAddress") == "d6:2c:ca:c0:d4:9c":
"00000000-0000-0000-0000-000000000057", "00000000-0000-0000-0000-00000000001C", "00000000-0000-0000-0000-000000000060", "00000000-0000-0000-0000-00000000002B", "00000000-0000-0000-0000-000000000072", "00000000-0000-0000-0000-000000000039" ] #Set bluetooth device. Default 0. dev_id = 0 try: sock = bluez.hci_open_dev(dev_id) except: print("Error accessing bluetooth") ScanUtility.hci_enable_le_scan(sock) #Scans for iBeacons try: while True: beaconList = ScanUtility.parse_events(sock, 10) for beacon in beaconList: if beacon['type'] == 'iBeacon': if beacon['uuid'] == '2f234454-cf6d-4a0f-adf2-f4911ba9ffa6': print("iBeacon:-------------") print(beacon) print("") elif beacon['type'] == 'Overflow': print("Overflow:-------------") print(beacon) print("")
except Exception as e: # print("inE1") # print (e) return {} pass try: print(dev_id) sock = bluez.hci_open_dev(dev_id) print(sock) print ("\n *** Looking for BLE Beacons ***\n") print ("\n *** CTRL-C to Cancel ***\n") except: print ("Error accessing bluetooth") ScanUtility.hci_enable_le_scan(sock) #Scans for iBeacons def checkRssi(x,z): sz = 20 # 数据量 # x = 0.1 # 真实值 # z = np.random.normal(x, 0.1, size=sz) # 观测值,服从高斯分布 Q = 1e-5 # 过程噪声 R = 1e-2 # 观测噪声 # 为变量分配空间 x_predict = np.zeros(sz) # x的先验估计,也就是预测值 P_predict = np.zeros(sz) # P的先验估计 x_update = np.zeros(sz) # x的后验估计,也就是最终的估计量