SilvairGit / python-bluetooth-mesh

https://pypi.org/project/bluetooth-mesh/
GNU General Public License v2.0
71 stars 22 forks source link

Create Network : Operation failed #189

Open lebrislo opened 7 months ago

lebrislo commented 7 months ago

Hello,

I'm trying since few days to implement a Mesh provisioner with your library for test purpose. According to the bluez mesh-api.txt file the CreateNetwork method is "This is the first method that an application calls to becomea Provisioner node, and a Configuration Client on a newly created Mesh Network."

I tried to do the operation with your library with the following code :

import asyncio
import logging
import secrets

from time import sleep
from bluetooth_mesh.bluez.application import Application, Element, Capabilities
from bluetooth_mesh.crypto import ApplicationKey, DeviceKey, NetworkKey
from bluetooth_mesh.messages.config import GATTNamespaceDescriptor, StatusCode
from bluetooth_mesh.models import ConfigClient, ConfigServer, HealthClient, HealthServer

class PrimaryElement(Element):
    LOCATION = GATTNamespaceDescriptor.MAIN
    MODELS = [
        ConfigClient,
        ConfigServer,
        HealthClient,
    ]

class SampleApplication(Application):
    COMPANY_ID = 0x025E
    PRODUCT_ID = 1
    VERSION_ID = 1
    ELEMENTS = {
        0: PrimaryElement,
    }

    CRPL = 32767
    PATH = "/fr/scheiber/mesh"

    @property
    def dev_key(self):
        return DeviceKey(secrets.token_bytes(16))

    @property
    def net_key(self):
        return 0, NetworkKey(secrets.token_bytes(16))

    @property
    def app_keys(self):
        return {0: ApplicationKey(secrets.token_bytes(16))}

async def main():
    # Set up logging
    logging.basicConfig(level=logging.INFO)

    # Create an event loop
    loop = asyncio.get_event_loop()

    # Create an instance of the Application class
    app = SampleApplication(loop=loop)

    try:
        # Connect to BlueZ
        await app.dbus_connect()

        app.address = 0x0001

        await app.create_network()

    except Exception as e:
        logging.error("Error occurred: %s", e)

# Run the asynchronous function
asyncio.run(main())

When I run the python file I get the following error :

INFO:SampleApplication:Connecting to org.bluez.mesh
INFO:SampleApplication:Registering application
INFO:SampleApplication:Create 5c5e3ef3-3afe-57af-b34a-9c1e9788b431
ERROR:root:Error occurred: Operation failed

Here is my bluetooth-mesh.service status :

bluetooth-mesh.service - Bluetooth mesh service
     Loaded: loaded (/lib/systemd/system/bluetooth-mesh.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2024-03-12 12:11:40 CET; 3s ago
   Main PID: 703290 (bluetooth-meshd)
      Tasks: 1 (limit: 19022)
     Memory: 324.0K
        CPU: 29ms
     CGroup: /system.slice/bluetooth-mesh.service
             └─703290 /usr/libexec/bluetooth/bluetooth-meshd --debug

mars 12 12:11:40 SCHEIBER0049 bluetooth-meshd[703290]: mesh/cfgmod-server.c:cfgmod_server_init() 00
mars 12 12:11:40 SCHEIBER0049 bluetooth-meshd[703290]: mesh/mesh-mgmt.c:mesh_mgmt_list() send read inde>
mars 12 12:11:40 SCHEIBER0049 bluetooth-meshd[703290]: mesh/mesh.c:mesh_init() io 0x56243b269ea0
mars 12 12:11:40 SCHEIBER0049 bluetooth-meshd[703290]: mesh/mesh-mgmt.c:read_index_list_cb() Number of >
mars 12 12:11:40 SCHEIBER0049 bluetooth-meshd[703290]: mesh/mesh-mgmt.c:read_info_cb() hci 0 status 0x00
mars 12 12:11:40 SCHEIBER0049 bluetooth-meshd[703290]: mesh/mesh-mgmt.c:read_info_cb() settings: supp 0>
mars 12 12:11:40 SCHEIBER0049 bluetooth-meshd[703290]: mesh/mesh-io-generic.c:hci_init() Started mesh o>
mars 12 12:11:40 SCHEIBER0049 bluetooth-meshd[703290]: Added Network Interface on /org/bluez/mesh
mars 12 12:11:40 SCHEIBER0049 bluetooth-meshd[703290]: Hci dev 0000 removed
mars 12 12:11:40 SCHEIBER0049 bluetooth-meshd[703290]: LE Scan disable failed (0x0c)

According the provided code, Do you have any idea how to solve my problem?

Thank you for your reply.