Ejemplo n.º 1
0
    def setUpClass(cls) -> None:
        if BlatannTestCase.logger is None:
            BlatannTestCase.logger = setup_logger()
        cls.logger = logging.getLogger(cls.__module__)

        cls.dev1 = _configure_device(1, cls.dev1_config)
        cls.dev2 = _configure_device(2, cls.dev2_config)

        if cls.requires_3_devices:
            cls.dev3 = _configure_device(3, cls.dev3_config)
            if not cls.dev3:
                raise SkipTest("Need third device for this TestCase")
        else:
            cls.dev3 = None

        cls.dev1.open(True)
        cls.dev2.open(True)
        if cls.dev3:
            cls.dev3.open(True)
Ejemplo n.º 2
0
"""
This example implements Nordic's custom UART service and demonstrates how to configure the MTU size.
It is configured to use an MTU size based on the Data Length Extensions feature of BLE for maximum throughput.
This is compatible with the nRF Connect app (Android version tested) and the central_uart_service example.

This is a simple example which just echos back any data that the client sends to it.
"""
from blatann import BleDevice
from blatann.gap import advertising
from blatann.utils import setup_logger
from blatann.services import nordic_uart
from blatann.gatt import MTU_SIZE_FOR_MAX_DLE
from blatann.waitables import GenericWaitable

logger = 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, initiating MTU exchange")
        peer.exchange_mtu()
    else:
        logger.warning("Connection timed out")
"""
This example demonstrates using Bluetooth SIG's defined Current Time service as a peripheral.
"""
import datetime
from blatann import BleDevice
from blatann.gap import advertising
from blatann.utils import setup_logger
from blatann.services import current_time
from blatann.waitables import GenericWaitable

logger = setup_logger(level="INFO")


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):
    """
    Event callback for when the client disconnects from us (or when we disconnect from the client)