def main(): cm = pyble.CentralManager() print 'Checkpoint 1' if not cm.ready: return target = None while True: try: # target = cm.startScan(withServices=["180D"]) print 'Checkpoint 2' target = cm.startScan() print 'Checkpoint 3' if target and target.name == "EcoZe1": # if target: print target break except Exception as e: print e print 'Checkpoint 4' target.delegate = MyPeripheral p = cm.connectPeripheral(target) print 'Checkpoint 5' for service in p: # if service.UUID == "FFF0": # continue # if service.UUID == "180A": # continue print service for c in service: print c, " : ", print c.value # print c # print "description: ", c.description # print "value : ", c.value c = p["EcoZen Profile"]["EcoZen Char 1"] print c.value # c = p["FFA0"]["FFA1"] # p["FFA0"]["FFA6"].notify = True # c.value = bytearray(chr(1)) # cm.loop(duration=10) # cm.loop() cm.disconnectPeripheral(p)
def connectToPolarH7(self): """ Initialise a Bluetooth Low Energy Central Manager, continuously scan for Polar H7 chest strap, and connect to this peripheral :returns: cm - Bluetooth Low Energy Central Manager p - Polar H7 Peripheral """ self.cm = pyble.CentralManager() if not self.cm.ready: return self.target = None while True: try: self.target = self.cm.startScan(withServices=["180D"]) if self.target and "Polar" in self.target.name: print(self.target) break except Exception as e: print(e) self.target.delegate = Peripheral self.p = self.cm.connectPeripheral(self.target) self.battery_level = self.get_battery_level() return self.cm, self.p
client_socket.connect((dongle_config.address, dongle_config.port)) # TODO Bluetooth, perform CAN bus message injection dongle_init(1, client_socket) # test_input(1, client_socket) # read_VIN(1, client_socket) # filter_test(1, client_socket) client_socket.close() else: print "[!] Device name %s not found!" % dongle_config.name else: # Bluetooth LE cm = pyble.CentralManager() if cm.ready: target = None device_list = [] p = None scan_interval = 50 # number of scans for i in range(scan_interval): try: target = cm.startScan() if target: if target not in device_list: device_list.append(target) if str(target).__contains__(dongle_config.name): print "Target dongle %s found, connecting to it..." % dongle_config.name p = cm.connectPeripheral(target) break