""" This example shows how to implement a Device Info Service on a peripheral. This example can be used alongside the central_device_info_service example running on another nordic device, or using the Nordic nRF Connect app to connect and browse the peripheral's service data """ from blatann import BleDevice from blatann.examples import example_utils from blatann.gap import advertising from blatann.services import device_info from blatann.waitables import GenericWaitable logger = example_utils.setup_logger(level="DEBUG") def on_connect(peer, event_args): """ Event callback for when a central device connects to us :param peer: The peer that connected to us :type peer: blatann.peer.Client :param event_args: None """ if peer: logger.info("Connected to peer") else: logger.warning("Connection timed out") def on_disconnect(peer, event_args): """
""" This example simply demonstrates scanning for peripheral devices """ from blatann import BleDevice from blatann.examples import example_utils logger = example_utils.setup_logger(level="INFO") def main(serial_port): # Create and open the device ble_device = BleDevice(serial_port) ble_device.open() logger.info("Scanning...") # Set scanning for 4 seconds ble_device.scanner.set_default_scan_params(timeout_seconds=4) # Start scanning and iterate through the reports as they're received for report in ble_device.scanner.start_scan().scan_reports: if not report.duplicate: logger.info(report) scan_report = ble_device.scanner.scan_report print("\n") logger.info("Finished scanning. Scan reports by peer address:") # Iterate through all the peers found and print out the reports for report in scan_report.advertising_peers_found: logger.info(report) # Clean up and close the device