Esempio n. 1
0
 def centralManager_didDiscoverPeripheral_advertisementData_RSSI_(
         self, manager, peripheral, data, rssi):
     if CBAdvertisementDataServiceDataKey not in data:
         return
     service_data = hexlify(data[CBAdvertisementDataServiceDataKey][
         CBUUID.UUIDWithString_("FD6F")].bytes().tobytes()).decode("ascii")
     encounter = Encounter(
         device_key=str(peripheral.identifier()),
         service_data=service_data,
         time=datetime.now(),
         rssi=rssi.intValue(),
     )
     for listener in self.listeners:
         listener.new_encounter(encounter=encounter)
def string2uuid(uuid_str: str) -> CBUUID:
    """Convert a string to a uuid"""
    return CBUUID.UUIDWithString_(uuid_str)
Esempio n. 3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Originally from https://github.com/masato-ka/python-corebluetooth-sample.git

import struct

from Foundation import CBCentralManager, CBUUID
from PyObjCTools import AppHelper

from btleclassifier import BTLEAdvClassifier

from constants import C
import btleclassifier
import datetime

wx2_service = CBUUID.UUIDWithString_(u'0C4C3000-7700-46F4-AA96-D5E974E32A54')
wx2_characteristic_data = CBUUID.UUIDWithString_(
    u'0C4C3001-7700-46F4-AA96-D5E974E32A54')

EXIT_COUNT = 10


class MyBLE(object):
    def __init__(self, debug=False):
        self.seen = set()
        self.debug = debug
        self.count_advertisements = 0

    def centralManagerDidUpdateState_(self, manager):
        if self.debug:
            print("centralManagerDidUpdateState_")
Esempio n. 4
0
 def centralManagerDidUpdateState_(self, manager):
     self.manager = manager
     manager.scanForPeripheralsWithServices_options_(
         [CBUUID.UUIDWithString_(self.UUID)],
         {CBCentralManagerScanOptionAllowDuplicatesKey: objc.YES},
     )