def evt_connection_disconnected(connection, reason): logging.info('connection disconneted, reason={0}'.format(reason)) ble.cmd_gap_set_mode(ble.GENERAL_DISCOVERABLE, ble.UNDIRECTED_CONNECTABLE)
# Set up logging log_level = getattr(logging, args.loglevel.upper(), None) if not isinstance(log_level, int): raise ValueError('Invalid log level: {0}'.format(loglevel)) logging.basicConfig(level=log_level, stream=sys.stdout) if args.reset: ble.init_connect(args.port) else: ble.connect(args.port) ble.cmd_system_get_info() ble.read_message(1000) if args.mode == 'advertise': ble.cmd_gap_set_mode(ble.GENERAL_DISCOVERABLE, ble.UNDIRECTED_CONNECTABLE) ble.read_message(1000) elif args.mode == 'scan': ble.cmd_gap_discover(ble.DISCOVER_OBSERVATION) ble.read_message(1000) # Just run and loop now while True: try: ble.read_message(1000) except RuntimeError as err: pass except KeyboardInterrupt: print('disconnecting') ble.disconnect()