Server advertising only 1 custom service out of 2
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
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
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
I disagree; there is a bug.
Running the examples with an additional service and characteristic doesn't show up; only the first service and characteristic do. I have tried restarting Bluetooth and the Raspberry Pi I was using to host the server.
I tested with a separate Python library ( bluez_peripheral ) using the same setup and they all get advertised.
For checking the services/characteristics, I used:
- "Bluetooth Terminal" app on iPhone
- Custom Flutter app running with the package
universal_ble
I also noticed this behavior on linux (bluez backend), but it works fine on Windows (winrt backend). I was able to get it to work by hardcoding primary to True in BlueZGattApplication.add_service (link). This configures all services as "primary" rather than just the first. Mobile apps I'm testing with now see all services (LightBlue, BLE Hero, nRF Connect).
This doesn't feel like an appropriate fix, but it's the only thing I've found so far.