def main(): pi.wiringPiSetupGpio() pi.pinMode(BUZZER_GPIOPIN, pi.OUTPUT) service = BeaconService() service.start_advertising() oldbeacon = {} al_notification = {} # hoge = [] devices = service.scan(2) for i, (address, data) in enumerate(list(devices.items())): b = Beacon(data, address) oldbeacon[b.get_uuid()] = b while True: devices = service.scan(1) for i, (address, data) in enumerate(list(devices.items())): b = Beacon(data, address, oldbeacon[data[0]].get_low_rssi(), oldbeacon[data[0]].get_distance()) # hoge.append(b.get_rssi()) print(b) # print(len(hoge)) # if len(hoge) == 100: # print(oldbeacon) # print(sum(hoge)/len(hoge)) # exit(0) is_address, userlist = check_uuid(b.get_uuid()) # send_alert_mails(userlist, b) #出ているのか if is_out_distance(b.get_distance(), oldbeacon[b.get_uuid()].get_distance(), oldbeacon[b.get_uuid()].get_distance( set="old")) and is_address: # 以前通知したかどうか if check_notifincation(b.get_uuid(), al_notification): al_notification[b.get_uuid()] = True nonfication_mails( userlist, "{0}さんが外出しました".format(userlist[0].name), str(datetime.now().strftime("%Y/%m/%d %H:%M:%S")) + "に外出されました") # 入っているのか elif is_in_distance( b.get_distance(), oldbeacon[b.get_uuid()].get_distance(), oldbeacon[b.get_uuid()].get_distance(set="old")): al_notification[b.get_uuid()] = False print("戻った") # 最後に今回のビーコン情報の更新 oldbeacon[b.get_uuid()] = b print("Done.")
def scan_beacon(leave_user): service = BeaconService() devices = service.scan(2) for address, data in list(devices.items()): b = Beacon(data, address) print(b) for i in leave_user: sql_str = "SELECT uuid FROM Employee WHERE Name = "+i+";" cur.execute(sql_str) tmp=cur.fetchall[0][0] if b._uuid==tmp: sql_str = "INSERT INTO time_card(Name,Time,State) VALUES("+i+","+datatime.datatime.now()+","+"enter);" cur.execute(sql_str) print("Done.")
def __init__(self, **kwargs): """Instance initialization. Args: logger (logging.Logger): Configured logger. **kwargs: Keyword arguments corresponding to instance attributes. Any unassociated keyword arguments are ignored. """ # Beacon settings for key, value in DEFAULT_CONFIG['scanner'].items(): if key in kwargs and kwargs[key]: setattr(self, key, kwargs[key]) # Create beacon self.__service = BeaconService(BLE_DEVICE) self.__timeout = None
def discover_beacons(self): if BeaconService is None: return logging.info("Scanning beacon devices") beacondevices = BeaconService().scan(5) timestamp = datetime.now().isoformat() logging.info("Discovered %d beacon devices" % len(beacondevices.keys())) for address, data in beacondevices.items(): self.send_reading('/'.join([address, "uuid"]), data[0]) self.send_reading('/'.join([address, "major"]), data[1]) self.send_reading('/'.join([address, "minor"]), data[2]) self.send_reading('/'.join([address, "power"]), data[3]) self.send_reading('/'.join([address, "rssi"]), data[4]) self.send_reading('/'.join([address, "distance"]), self.calculate_distance(data[3], data[4])) self.send_reading('/'.join([address, "le"]), True) self.send_reading('/'.join([address, "last_seen"]), timestamp)
def handle(self, *args, **options): iottalk = dan.Iottalk( dm_name="Dummy_Device", df_list=["Dummy_Sensor", "Dummy_Control"], d_name="Rollcall-Sensor-1", mac=uuid.uuid4().hex, ) iottalk.device_registration_with_retry(os.getenv("IOTTALK_ENDPOINT")) service = BeaconService() try: while True: devices = service.scan(2) for address, data in devices.items(): student = Beacon(data, address) if student._rssi > -40: print("Get UUID: ", student._uuid) iottalk.push("Dummy_Sensor", str(student._uuid)) time.sleep(0.5) finally: iottalk.deregister()
def __init__(self, logger, **kwargs): """Instance initialization. Args: logger (logging.Logger): Configured logger. **kwargs: Keyword arguments corresponding to instance attributes. Any unassociated keyword arguments are ignored. """ # Logger self.__logger = logger # Beacon settings for key, value in DEFAULT_CONFIG['scanner'].items(): if key in kwargs and kwargs[key]: setattr(self, key, kwargs[key]) else: self.__logger.debug("Using default beacon scanner " f"configuration {key}: {value}.") setattr(self, key, value) # Create beacon self.__service = BeaconService(BLE_DEVICE)
""" + code server = smtplib.SMTP("smtp.gmail.com",587) server.starttls() server.login('uiucbleats','WirelessNetworks') server.sendmail('Your Professor','*****@*****.**',message) #conn = sqlite3.connect('students.db') #cursor = conn.cursor() #connAuth = sqlite3.connect('AuthDB.db') #cursorAuth = connAuth.cursor() service = BeaconService("hci0") #service = DiscoveryService("hci0") while True: with sqlite3.connect('AuthDB.db') as connAuth: with sqlite3.connect('students.db') as conn: cursor = conn.cursor() cursorAuth = connAuth.cursor() print ("Start Scan") devices = service.scan(2) print ("Scanned") for address, data in list(devices.items()): b = Beacon(data, address) if (b._major==1): cursorAuth.execute("SELECT * FROM students WHERE uuid = '" + b._uuid + "' LIMIT 1") print (cursorAuth.fetchone()) cursorAuth.execute("select codeSent FROM students WHERE uuid = '"+b._uuid+"'")
""" TODO """ def __init__(self, address, data): """ TODO """ self._address = address self._uuid = data[0] self._major = data[1] self._minor = data[2] self._power = data[3] self._rssi = data[4] def __str__(self): """ TODO """ return 'Beacon: address:{ADDR} uuid:{UUID} major:{MAJOR} minor:{MINOR} txpower:{POWER} rssi:{RSSI}'\ .format(ADDR=self._address, UUID=self._uuid, MAJOR=self._major, MINOR=self._minor, POWER=self._power, RSSI=self._rssi) if __name__ == '__main__': # Create beacon service and scan for devices (2 seconds) service = BeaconService('hci0') devices = service.scan(2) # Connect to each beacon, print results of device scan for address, data in list(devices.items()): beacon = Beacon(address, data) print(beacon) print('*** Beacon scan complete! ***')
#class libraries for the blueetooth applicatio import time #<---- class library. 1st from bluetooth.ble import BeaconService # <--- thried party module service = BeaconService( ) #<--- creating an instance object of the class library service.start_advertising( "11111111-2222-3333-44444-5555555555555", 1, 1, 1, 200) #<--- advertide the UUID and different ports for spoofing device time.sleep(15) sevice.stop_advertise() print("Done.")
#This script that advertises a bluetooth low energy beacon for 15 seconds import time #<----1st party class module from bluetooth.ble import BeaconService #<---3rd party module #Create an instace of the object from the 3rd party class service = BeaconService() #Creating BeaconService as a variable into service service.start_advertising("11111111-2222-3333-4444-555555555555", 1, 1, 1, 200) #Parameters are how you recive the UUID #UUID #Parameters time.sleep(15) #Sets amount of time the signal will last. service.stop_advertising() #This stops advertising the signal print("Done.") #Send message letting us know its done
dbFunctions.createTable() input_file = csv.DictReader(open("beaconStations.csv")) beaconsList = [] addressM = "" for row in input_file: beaconsList.append(row) for beacon in beaconsList: beacon["state"] = True beacon["read"] = False station = 1 direction = True DISCOVER_TIME = 5 # In seconds, scan interval duration. service = BeaconService() # Start the service object as beacon service def getMaxRssi(): rssiM = -100 beacon = Beacon.Beacon([0, 0, 0, 0, -100], "") for beaconRead in beaconsRead: if int(beaconRead._rssi) > rssiM: rssiM = beaconRead._rssi beacon = beaconRead return beacon while True: beaconsRead = [] devices = service.scan(DISCOVER_TIME)
def scan(): try: return Beacon.found_to_list(BeaconService().scan(2)) except RuntimeError as e: print(e) return []
def beacon_scan(): service = BeaconService() return service.scan(2)
#!/usr/bin/python3 from bluetooth.ble import BeaconService service = BeaconService() devices = service.scan(10) for addr, data in devices.items(): print("%s (UUID %s Major %d Minor %d Power %d RSSI %d)" % (addr, data[0], data[1], data[2], data[3], data[4]))
#class libraries for bluetooth application import time #<-- 1st party class library from bluetooth.ble import BeaconService #<-- 3rd party module (someone from the internet who created class library) #instantiate the object service = BeaconService() #<-- create an instance object of class library service.start_advertising("1, 1, 200") #<-- advertise the UUID and different ports for spoofing devices time.sleep(15) #<--every fifteen seconds service.stop_advertise() #<-- stop service print("Done ") #<--print when done
#this script that advertises a bluetooth low energy beacon for 15 seconds import time #<-----classs library for a first party module from bluetooth.ble import BeaconService #<-------class library for a third party module #create an instance of an object form the 3rd party class service = BeaconService() #<--creatong beacon service service.start_advertising("11111111-2222-3333-4444-555555555555", 1, 1, 1, 200) #<--advertising a signal time.sleep(15) service.stop_advertising() print("Done.")
#This script that advertises a bluetooth low energy beacon for 15 seconds #penetaration example right here #class libary using bluetooth in time import time #<--- First part class moudle it manuiplues time from bluetooth.ble import BeaconService #<---- 3rd party module #create an instance of object from the 3rd party class service - BeaconService() # service minus 3rd party module service.start_advertising( "11111111-2222-3333-4444-555555555555", 1, 1, 1, 200) #<-- when call this accept UUIDs.# port, port, channel time.sleep(15) #<--- low energy beacon for 15 seconds service.stop_advertising() # <--- stop the bluetooth connection print("Done.") #<--- this is going to pop up on the screen saying done
@property def address(self): return self._address def __str__(self): ret = "Beacon:\n" \ "\taddress: {ADDR}\n" \ "\tuuid: {UUID}\n" \ "\tmajor: {MAJOR} minor: {MINOR} txpower: {POWER}\n" \ "\trssi: {RSSI}\n" \ .format(ADDR=self._address, UUID=self._uuid, MAJOR=self._major, MINOR=self._minor, POWER=self._power, RSSI=self._rssi) return ret counter = 0 serviceB = BeaconService() while True: beacons = serviceB.scan(2) i = 0 os.system('clear') print(counter) print("-"*20) for address, data in list(beacons.items()): b = Beacon(data, address, beacons, i) i += 1 print(b.rssi) print(b.address) print("-"*20) # time.sleep(1)
control_file = Path(value).resolve() control_file.touch() control_file.chmod(0o777) with control_file.open(mode='w') as f: f.write("1") control_file_handle = None with open(control_file, 'w') as f: f.write("1") control_file_handle = control_file.open(mode='r+') # Initialize bluetooth BLE_DEVICE = "hci0" service = BeaconService(BLE_DEVICE) run = True while run: control_file_handle.seek(0) control_flag = control_file_handle.read() # 0 = off # 1 = on # 2 = scan if control_flag == "0": run = False print('done') if control_flag == "1": continue if control_flag == "2":