Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server advertising only 1 custom service out of 2 #146

Open
Delecons opened this issue Feb 10, 2025 · 1 comment
Open

Server advertising only 1 custom service out of 2 #146

Delecons opened this issue Feb 10, 2025 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Delecons
Copy link

Delecons commented Feb 10, 2025

The problem
I'm using the exemple of the gatt server that i personalised for the purpose of testing so client sided code and i can only receive 4 service and only one of the custom services

Reproduction

"""
Example for a BLE 4.0 Server using a GATT dictionary of services and
characteristics
"""
import sys
import logging
import asyncio
import threading

from typing import Any, Dict, Union

from bless import (  # type: ignore
    BlessServer,
    BlessGATTCharacteristic,
    GATTCharacteristicProperties,
    GATTAttributePermissions,
)

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(name=__name__)

trigger: Union[asyncio.Event, threading.Event]
if sys.platform in ["darwin", "win32"]:
    trigger = threading.Event()
else:
    trigger = asyncio.Event()

CONFIG_SERVICE = "A07498CA-AD5B-474E-940D-16F1FBE7E8CD"
CONFIG_ID = "12345678-1234-5678-1234-56789abcdef0"
CONFIG_ADRESSE_NOEUD = "98765432-9876-5432-9876-54321abcdef0"
COMMUNICATION_SERVICE = "5c339364-c7be-4f23-b666-a8ff73a6a86a"
COMMUNICATE = "bfc0c92f-317d-4ba9-976b-cc11ce77b4ca"

#A transformer le serveur en Generic Network Device/ Mesh Device/ Mesh Network Proxy

def read_request(characteristic: BlessGATTCharacteristic, **kwargs) -> bytearray:
    logger.debug(f"Reading {characteristic.value}")
    characteristic.password= "Test12"
    return characteristic.value


def write_request(characteristic: BlessGATTCharacteristic, value: Any, **kwargs):
    characteristic.value = value
    logger.debug(f"Char value set to {characteristic.value}")
    if characteristic.value == b"\x0f":
        logger.debug("Nice")
        trigger.set()


async def run(loop):
    trigger.clear()

    # Instantiate the server
    gatt: Dict = {
        CONFIG_SERVICE: {
            CONFIG_ID: {
                "Properties": (
                    GATTCharacteristicProperties.read
                    | GATTCharacteristicProperties.write
                    | GATTCharacteristicProperties.indicate
                ),
                "Permissions": (
                    GATTAttributePermissions.readable
                    | GATTAttributePermissions.writeable
                ),
                "Value": None,
            },
            CONFIG_ADRESSE_NOEUD:{
                "Properties":(
                    GATTCharacteristicProperties.read
                    | GATTCharacteristicProperties.write
                    | GATTCharacteristicProperties.indicate
                ),
                "Permissions": (
                    GATTAttributePermissions.readable
                    | GATTAttributePermissions.writeable
                ),
                "Value": None,
                }
        },
        COMMUNICATION_SERVICE: {
            COMMUNICATE: {
                "Properties": (
                    GATTCharacteristicProperties.read
                    | GATTCharacteristicProperties.write
                    | GATTCharacteristicProperties.indicate
                ),
                "Permissions": (
                    GATTAttributePermissions.readable
                    | GATTAttributePermissions.writeable
                ),
                "Value": bytearray(b"\x69"),
            }
        },
    }
    my_service_name = "RECSANet"
    server = BlessServer(name=my_service_name, loop=loop)
    server.read_request_func = read_request
    server.write_request_func = write_request

    await server.add_gatt(gatt)
    await asyncio.sleep(2)
    await server.start()
    logger.debug(server.get_characteristic(CONFIG_ADRESSE_NOEUD))
    logger.debug(server.get_characteristic(CONFIG_ID))
    logger.debug(server.get_characteristic(COMMUNICATE))
    logger.debug("Advertising")
    logger.info(
        "Write '0xF' to the advertised characteristic: "
        + CONFIG_ADRESSE_NOEUD
    )
    if trigger.__module__ == "threading":
        trigger.wait()
    else:
        await trigger.wait()
    await asyncio.sleep(2)
    logger.debug("Updating")
    server.get_characteristic(COMMUNICATE).value
    
    server.update_value(
        CONFIG_SERVICE, CONFIG_ID
    )
    server.update_value(
        CONFIG_SERVICE, CONFIG_ADRESSE_NOEUD
    )
    server.update_value(
        COMMUNICATION_SERVICE, COMMUNICATE    
    )
    await asyncio.sleep(5)
    await server.stop()


loop = asyncio.get_event_loop()
loop.run_until_complete(run(loop))

Expected behavior
Should advertise both customs service

Screenshots

Image

Desktop (please complete the following information):

  • OS: Debian Xfce 4.20

Additional context
The code i passed down is not final nor will be used for exeterior purposes than testing

@kevincar kevincar added bug Something isn't working help wanted Extra attention is needed labels Feb 10, 2025
@Delecons
Copy link
Author

Delecons commented Feb 13, 2025

Quick info : there is no real bug the services are indeed advertised but they are not on the app i use for testing, i used bleak code to confirm this.
Do not worry about this 'bug' as there is none

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants