-
Notifications
You must be signed in to change notification settings - Fork 22
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
MessageReceived doesn't reach Python code #62
Comments
The message seems to be sent to a group address, so you need to subscribe your model first. |
In theory, the provisioner is already doing that. Let me show you a more extense part of the driver log, marking the subscription:
|
I'm trying with a more contained code. I'm running now two RPis, both with the same bluez and bluetooth_mesh versions. One of them as provisioner and the other as node, in order to narrow down the problem I'm having in this issue. I'm trying to create the connection but I'm not very sure of the outputs I'm receiving. The sources are: Provisionerimport asyncio
import secrets
import logging
import sys
from time import sleep
from uuid import UUID
from typing import Dict
from bluetooth_mesh.application import Application, Element
from bluetooth_mesh.models import ConfigClient, HealthClient
from bluetooth_mesh.messages.config import GATTNamespaceDescriptor
from bluetooth_mesh.crypto import ApplicationKey, DeviceKey, NetworkKey
logger = logging.getLogger()
class MainElement(Element):
LOCATION = GATTNamespaceDescriptor.MAIN
MODELS = [ConfigClient, HealthClient]
class SampleApplication(Application):
COMPANY_ID = 0x0136 # Silvair
PRODUCT_ID = 1
VERSION_ID = 1
ELEMENTS = {0: MainElement}
CRPL = 32768
PATH = "/org/example/provisioner"
@property
def dev_key(self):
return DeviceKey(secrets.token_bytes(16))
@property
def primary_net_key(self):
return 0, NetworkKey(secrets.token_bytes(16))
@property
def app_keys(self):
return {0: ApplicationKey(secrets.token_bytes(16))}
async def run(self):
async with self:
await self.create_network()
await self.connect(addr = 0, iv_index = 5)
await self.management_interface.add_node(UUID('{cb2ce7c3-14e6-514a-9027-5bab0182f54e}'))
sleep(1)
logger.info("Node added?")
sleep(1)
client = self.elements[0][HealthClient]
while True:
await client.attention(0x0001, app_index=0, attention=3)
def main():
loop = asyncio.get_event_loop()
app = SampleApplication(loop)
loop.run_until_complete(app.run())
if __name__ == '__main__':
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(levelname)s \t %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
main() Provisioner output
Nodeimport asyncio
import logging
import sys
from bluetooth_mesh.application import Application, Element
from bluetooth_mesh.models import ConfigServer, HealthServer
from bluetooth_mesh.messages.config import GATTNamespaceDescriptor
logger = logging.getLogger()
class MainElement(Element):
LOCATION = GATTNamespaceDescriptor.MAIN
MODELS = [ConfigServer, HealthServer]
class SampleApplication(Application):
COMPANY_ID = 0x0136 # Silvair
PRODUCT_ID = 1
VERSION_ID = 1
ELEMENTS = {0: MainElement}
CRPL = 32768
PATH = "/org/example/node"
async def run(self):
async with self:
await self.join()
sleep(20)
def main():
loop = asyncio.get_event_loop()
app = SampleApplication(loop)
loop.run_until_complete(app.run())
if __name__ == '__main__':
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(levelname)s \t %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
main() Node output
Both programs are run at the same time, and the 20 seconds delay in the node is never expired. The connection is simply broken. However there seems to be a first message arriving, could you guide me on this? |
Is there a more complete example of a provisioner and/or node than the Quickstart from the reference? |
I'm sorry just posting here but I would also be very grateful for a complete and well-descripted example code. |
Sorry, I'm working in a simple example for a provisioner and a node, but I've been unable so far to create a working connection, maybe the maintainer could provide some good example |
My last attemp used the same node source but a more simplified provisioning: import asyncio
import secrets
import logging
import sys
from time import sleep
from uuid import UUID
from typing import Dict
from bluetooth_mesh.application import Application, Element
from bluetooth_mesh.models import ConfigClient, ConfigServer, HealthClient, HealthServer
from bluetooth_mesh.messages.config import GATTNamespaceDescriptor
from bluetooth_mesh.crypto import ApplicationKey, DeviceKey, NetworkKey
logger = logging.getLogger()
class MainElement(Element):
LOCATION = GATTNamespaceDescriptor.MAIN
MODELS = [ConfigClient, ConfigServer, HealthClient]
class SampleApplication(Application):
COMPANY_ID = 0x0136 # Silvair
PRODUCT_ID = 1
VERSION_ID = 1
ELEMENTS = {0: MainElement}
CRPL = 32768
PATH = "/org/example/provisioner"
CAPABILITIES = []
@property
def dev_key(self):
return DeviceKey(secrets.token_bytes(16))
@property
def primary_net_key(self):
return 0, NetworkKey(secrets.token_bytes(16))
@property
def app_keys(self):
return {0: ApplicationKey(secrets.token_bytes(16))}
def scan_result(self, rssi: int, data: bytes, options: dict):
logger.info("Detected node with RSSI %s" % rssi)
logger.info("Node has data %s" % data)
logger.info("Node has options %s" % options)
def add_node_complete(self, uuid: bytes, unicast: int, count: int):
logger.info("Connected %s (%s / %s)" % (uuid, unicast, count))
def add_node_failed(self, uuid: bytes, reason: str):
logger.info("Unable to connect to %s: %s" % (uuid, reason))
def request_prov_data(self, count: int):
logger.info("Request prov data called with count %s" % count)
return (0, count + 1)
async def configure_remote(self):
client = self.elements[0][ConfigClient]
status = await client.add_app_key(
2, net_index=0,
app_key_index=0,
net_key_index=0,
app_key=self.app_keys[0]
)
logger.info("App Key added")
assert status == StatusCode.SUCCESS, \
'Cannot add application key: %s' % status
status = await client.bind_app_key(
2, net_index=0,
element_address=2,
app_key_index=0,
model=HealthServer
)
assert status == StatusCode.SUCCESS, \
'Cannot bind application key: %s' % status
logger.info("Configured remote device")
async def run(self):
async with self:
config = await self.connect(1)
await self.management_interface.add_node(UUID('{cb2ce7c3-14e6-514a-9027-5bab0182f54e}'))
logger.info("Little wait for the connection to succeed")
sleep(15)
logger.info("Configuring remote node...")
try:
await self.configure_remote()
except Exception as ex:
logger.error("Error received: %s", ex)
logger.info("Little wait for the configuration")
sleep(10)
logger.info("Node added?")
client = self.elements[0][HealthClient]
while True:
await client.attention(0x0002, app_index=0, attention=3)
def main():
loop = asyncio.get_event_loop()
app = SampleApplication(loop)
loop.run_until_complete(app.run())
if __name__ == '__main__':
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(levelname)s \t %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
main() However, there seems to be a lost message, the request_prov_data is not properly recovered from the dbus. The output of the log is:
While the dbus console shows:
As shown, the RequestProvData is called at the moment of the management_interface.add_node, in dbus, however, the python source doesn't executes the method request_prov_data until long after that moment, when the configuration is being done. Due to this problem, the node ends up with a JoinFailed as shown by its dbus monitor:
|
I've connected a Raspberry Pi to a network as a node and the messages in the network are reaching the device but it never appears a MessageReceived in the source. The logs of the bluetooth_mesh service show this for each message sent by the emitting node:
But the
message_received
method inElementInterface
is never executed.The text was updated successfully, but these errors were encountered: