def __init__(self, buf=None): self.epoch = 0 self.type = SensorEventType.RESERVED self.number = 0 self.magnet_state = MagnetState.FAR self.temperature = 0.0 self.batteryVoltage = 0.0 self.reset_reason = ResetReason.UNKNOWN if buf is not None: self.update(AdvParser(buf)) self.logger = logging.getLogger('AD parser')
timeout=1, rtscts=True) with serial.threaded.ReaderThread(ser, BL65x) as bt_module: jt = jtester() jt.set_protocol(bt_module) bt_module.secondary_initialization() name_to_look_for = "BT510" bt_module.scan(nameMatch=name_to_look_for) configured_devices = dict() while True: ad = bt_module.get_scan(timeout=None) ap = None try: junk, address, rssi, ad_rsp = ad.split(' ') logging.debug(f"{address} {rssi} {ad_rsp}") ap = AdvParser(ad_rsp.strip('"')) except: logging.debug("unable to process advertisement") if ap is not None: if ap.adv_valid: # Use a dictionary of address and last events because the # event handler doesn't handle events from different devices. if ap.bd_addr not in configured_devices: bt_module.cancel_scan() logging.debug("Preparing to configure new device") bt_module.allow_pairing() bt_module.connect(ap.get_at_bd_addr(), bt_module.connection_timeout) if bt_module.vspConnection: config = sensor_config()
jt.set_protocol(bt_module) bt_module.secondary_initialization() name_to_look_for = jc.get("system_name_to_look_for") bt_module.scan(nameMatch=name_to_look_for) event_dict = dict() while True: ad = bt_module.get_scan(timeout=None) ap = None try: junk, address, rssi, ad_rsp = ad.split(' ') logging.debug(f"{address} {rssi} {ad_rsp}") except: logging.info("unable to split advertisement") try: ap = AdvParser(ad_rsp.strip('"')) except: logging.info("unable to parse") if ap is not None: if ap.adv_valid: # Use a dictionary of address and last events because the # event handler doesn't handle events from different devices. if ap.bd_addr not in event_dict: logging.info( f'Found new sensor "{ap.name}" with BDA: {ap.bd_addr}') event_dict[ap.bd_addr] = SensorEvent() if ap.rsp_valid: logging.info(ap.rsp) if event_dict[ap.bd_addr].update(ap):