Cannot bind app key for one of the model with PYACI Script

Hello

I am trying to bind app key for one of the models with the help of PYACI Python script. I am using latest version v5.0.0 for PYACI script and downloaded it here: https://github.com/NordicSemiconductor/nRF5-SDK-for-Mesh , also with same version of documentation for commands https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.meshsdk.v2.1.1%2Fmd_scripts_interactive_pyaci_README.html.  And I am using Raspberry pi where my py script is running and nRF52840 with Serial Script running connected to Raspberry Pi with Ports /dev/ttyACM0 (or) /dev/ttyACM1. I am trying to bind app key for Sensor_Server Example and i get like this where all the earlier commands works well.

NOTE: examples are connected to Laptop which is obvious where we can run with bluetooth

 I also tried with Mesh Chat sample like above and get same problem

Another Question: we can identify the sample with last model ID where vendor Setup Model ID bound to "0059000a" which is 8 bit and where it should be 4 bit. Even in app i get the same ID

which is ok to setup in app but in this command - cc.model_app_bind(db.nodes[0].unicast_address, 0, mt.ModelId(0x1000)) it should have only 4 bit right?

Please help me as soon as possible. I really in need of help to continue my work further

Regards

Parents
  • Hi Sai,

    While getting the PyACI script to work, I ran into the same error.

    The cause of the error, for my case, was that the nodes at index 0 (db.nodes[0]) was not the Light Bulb node that I am trying to interact with.
    When I determine and use the correct node index, things work as it

    should.

    Could you please check your database.json and see if the nodes you want to talk with are not at index 0?

    If you need help with checking that, you could copy the content of the file into a code block here.

    Regards,

    Hieu

  • Hello

    I apologise for my late response. Here is my content and i am trying to provision Sensor Server Example from nordic samples. Still not able to resolve this issue.

    Regards

  • Sure will be waiting for your reply

    {
      "$schema": "",
      "appKeys": [
        {
          "boundNetKey": 0,
          "index": 0,
          "key": "REDACTED",
          "name": "lights"
        },
        {
          "boundNetKey": 0,
          "index": 1,
          "key": "REDACTED",
          "name": "locks"
        }
      ],
      "groups": [
        {
          "address": 49153,
          "name": "Room 1",
          "parentAddress": 0
        },
        {
          "address": 49154,
          "name": "Room 2",
          "parentAddress": 0
        }
      ],
      "ivIndex": 0,
      "ivUpdate": 0,
      "meshName": "BT Mesh",
      "meshUUID": "01020304050607080102030405060708",
      "netKeys": [
        {
          "index": 0,
          "key": "REDACTED",
          "minSecurity": "low",
          "name": "root",
          "phase": 0
        }
      ],
      "nodes": [
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "configComplete": false,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0000"
            }
          ],
          "name": "Mesh Sensor",
          "netKeys": [
            0
          ],
          "security": "low",
          "unicastAddress": 16
        },
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "configComplete": false,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0000"
            }
          ],
          "name": "Mesh Sensor",
          "netKeys": [
            0
          ],
          "security": "low",
          "unicastAddress": 17
        },
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "configComplete": false,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0000"
            }
          ],
          "name": "Mesh Sensor",
          "netKeys": [
            0
          ],
          "security": "low",
          "unicastAddress": 18
        },
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "configComplete": false,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0000"
            }
          ],
          "name": "Mesh Sensor",
          "netKeys": [
            0
          ],
          "security": "low",
          "unicastAddress": 19
        },
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "configComplete": false,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0000"
            }
          ],
          "name": "Mesh Sensor",
          "netKeys": [
            0
          ],
          "security": "low",
          "unicastAddress": 20
        },
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "configComplete": false,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0000"
            }
          ],
          "name": "Mesh Sensor",
          "netKeys": [
            0
          ],
          "security": "low",
          "unicastAddress": 21
        },
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "configComplete": false,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0000"
            }
          ],
          "name": "Mesh Sensor",
          "netKeys": [
            0
          ],
          "security": "low",
          "unicastAddress": 22
        },
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "cid": "0059",
          "configComplete": false,
          "crpl": "000a",
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0001",
              "models": [
                {
                  "modelId": "0000"
                },
                {
                  "modelId": "0002"
                },
                {
                  "modelId": "1100"
                },
                {
                  "modelId": "1101"
                }
              ]
            }
          ],
          "features": {
            "friend": 0,
            "lowPower": 2,
            "proxy": 0,
            "relay": 0
          },
          "name": "Sensor Server",
          "netKeys": [
            0
          ],
          "pid": "0000",
          "security": "low",
          "unicastAddress": 23,
          "vid": "0000"
        },
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "cid": "0059",
          "configComplete": false,
          "crpl": "000a",
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0001",
              "models": [
                {
                  "modelId": "0000"
                },
                {
                  "modelId": "0002"
                },
                {
                  "modelId": "1100"
                },
                {
                  "modelId": "1101"
                }
              ]
            }
          ],
          "features": {
            "friend": 0,
            "lowPower": 2,
            "proxy": 0,
            "relay": 0
          },
          "name": "Mesh Sensor",
          "netKeys": [
            0
          ],
          "pid": "0000",
          "security": "low",
          "unicastAddress": 24,
          "vid": "0000"
        },
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "configComplete": false,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0000"
            }
          ],
          "name": "Light bulb",
          "netKeys": [
            0
          ],
          "security": "low",
          "unicastAddress": 25
        },
        {
          "UUID": "f787347cfc2c47528878cb8303d3c8ad",
          "configComplete": false,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0000"
            }
          ],
          "name": "Sensor Server",
          "netKeys": [
            0
          ],
          "security": "low",
          "unicastAddress": 26
        },
        {
          "UUID": "f787347cfc2c47528878cb8303d3c8ad",
          "appKeys": [
            0
          ],
          "cid": "0059",
          "configComplete": false,
          "crpl": "000a",
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0001",
              "models": [
                {
                  "modelId": "0000"
                },
                {
                  "modelId": "0002"
                },
                {
                  "modelId": "1102"
                }
              ]
            }
          ],
          "features": {
            "friend": 0,
            "lowPower": 2,
            "proxy": 0,
            "relay": 0
          },
          "name": "Mesh Sensor",
          "netKeys": [
            0
          ],
          "pid": "0000",
          "security": "low",
          "unicastAddress": 27,
          "vid": "0000"
        },
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "configComplete": false,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0000"
            }
          ],
          "name": "Mesh Client",
          "netKeys": [
            0
          ],
          "security": "low",
          "unicastAddress": 28
        },
        {
          "UUID": "dbf4a7cc2c6448f1a40b5833d39ba70e",
          "appKeys": [
            0
          ],
          "cid": "0059",
          "configComplete": false,
          "crpl": "000a",
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0001",
              "models": [
                {
                  "modelId": "0000"
                },
                {
                  "modelId": "0002"
                },
                {
                  "modelId": "1100"
                },
                {
                  "modelId": "1101"
                }
              ]
            }
          ],
          "features": {
            "friend": 0,
            "lowPower": 2,
            "proxy": 0,
            "relay": 0
          },
          "name": "Mesh Sensor",
          "netKeys": [
            0
          ],
          "pid": "0000",
          "security": "low",
          "unicastAddress": 29,
          "vid": "0000"
        },
        {
          "UUID": "dbf4a7cc2c6448f1a40b5833d39ba70e",
          "appKeys": [
            0
          ],
          "cid": "0059",
          "configComplete": false,
          "crpl": 10,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0001",
              "models": [
                {
                  "modelId": "0000"
                },
                {
                  "modelId": "0002"
                },
                {
                  "modelId": "0059000a"
                }
              ]
            }
          ],
          "features": {
            "friend": 0,
            "lowPower": 2,
            "proxy": 0,
            "relay": 0
          },
          "name": "ServerExample",
          "netKeys": [
            0
          ],
          "pid": "0000",
          "security": "low",
          "unicastAddress": 30,
          "vid": "0000"
        }
      ],
      "provisioners": [
        {
          "UUID": "00000000000000000000000000000000",
          "allocatedGroupRange": [
            {
              "highAddress": 65279,
              "lowAddress": 49152
            }
          ],
          "allocatedUnicastRange": [
            {
              "highAddress": 32767,
              "lowAddress": 16
            }
          ],
          "name": "BT Mesh Provisioner"
        }
      ],
      "timestamp": "2023-03-13 10:51:31.547760"
    }

  • If you post the entire file, please remember to remove the app keys and the net keys as well. I have removed them again this time.

    I see multiple nodes in this database. Did you start from a fresh database? What does your database backup look like?

    This is the file in the nRF5 SDK for Mesh, unmodified. Your backup file should look like this.
    https://github.com/NordicSemiconductor/nRF5-SDK-for-Mesh/blob/master/scripts/interactive_pyaci/database/example_database.json.backup

  • sorry didn't realise i had a reply.This is the fresh data base i deleted the database file and added new one and started provisioning.I will download a new file again from internet and will check again. Also backup file looks like this: 

    {
      "$schema": "",
      "appKeys": [
        {
          "boundNetKey": 0,
          "index": 0,
          "key": "REDACTED",
          "name": "lights"
        },
        {
          "boundNetKey": 0,
          "index": 1,
          "key": "REDACTED",
          "name": "locks"
        }
      ],
      "groups": [
        {
          "address": 49153,
          "name": "Room 1",
          "parentAddress": 0
        },
        {
          "address": 49154,
          "name": "Room 2",
          "parentAddress": 0
        }
      ],
      "ivIndex": 0,
      "ivUpdate": 0,
      "meshName": "BT Mesh",
      "meshUUID": "01020304050607080102030405060708",
      "netKeys": [
        {
          "index": 0,
          "key": "REDACTED",
          "minSecurity": "low",
          "name": "root",
          "phase": 0
        }
      ],
      "nodes": [
      ],
      "provisioners": [
        {
          "UUID": "00000000000000000000000000000000",
          "allocatedGroupRange": [
            {
              "highAddress": 65279,
              "lowAddress": 49152
            }
          ],
          "allocatedUnicastRange": [
            {
              "highAddress": 32767,
              "lowAddress": 16
            }
          ],
          "name": "BT Mesh Provisioner"
        }
      ],
      "timestamp": "2018-03-08 21:59:17.239719"
    }
    

  • That backup file looks OK as far as the node database go (it's empty).

    If you don't feel certain about the file, feel free to download a copy either from the GitHub link I used or the nRF5 SDK for Mesh product website.

  • Thank You so much, Its working now i installed from the website you attached and started the first provisioning with 0. So each time i provision should i copy the new database files?

Reply Children
  • I tried provisioning for both server and client with PYACI script.

    Problem:1 when both server and client dk is on and when i do this command "p.provision(name="server")" and later this "cc.composition_data_get()" i get 1102 model ID which is client model ID. it is mixing up so i am doing server first with client power off and then client power on with server power off.

    Problem:2 same problem as earlier with node number now i successfully provisioned server then when i am provisioning client same error as earlier.

    Problem:3 "p.provision(name="Light bulb")" for this command if i give wrong name also its provisioning.

    Problem:4 each time i provision new devices should i copy the new database files

    Awaiting for your reply

    Edit: Needed info in urgent can you please help me as soon as possible

    Regards

  • SaSu said:
    So each time i provision should i copy the new database files?
    SaSu said:
    Problem:4 each time i provision new devices should i copy the new database files

    Sorry, I wrote a reply two days ago, but it was already midnight, and I was too tired to continue struggling to find the right words while going over it, so I had to put it off.

    I'm afraid that is not the correct conclusion. You should not copy a new database file each time you provision.

    Please understand that the database is literally a description of your entire network, including as many nodes as there actually are.

    By the way, the format of the file is actually defined in the Mesh Configuration Database Profile (link to v1.0).

    The "nodes" field include an array of JSON objects, each object describes a node in the network. At least with the cc.model_app_bind function, you need to refer to the correct index.

    The problem you initially faced is that across your multiple attempts, you have been adding multiple nodes to the network, but you still try to bind the app key to the node at index 0 (or 1), which are no longer there (because you reflashed the device with a new software).

    I suggested starting a new considering that you are still struggling to add your first node, and your database contained a lot of no-longer-valid nodes like that.

    Now that you know what is going on, the next time you provision a node, as long as you do things correctly, you just need to find and use the correct index of the node you are working with.

    Starting with a new database is just resetting your network. You lose the first node that way.

    SaSu said:
    Problem:1 when both server and client dk is on and when i do this command "p.provision(name="server")" and later this "cc.composition_data_get()" i get 1102 model ID which is client model ID. it is mixing up so i am doing server first with client power off and then client power on with server power off.

    What sample are you using where you find the Server having model ID 1102?

    Keeping only one unprovisioned node power on at a time is a way to make sure you can get the correct node. That's a good approach.

    SaSu said:
    Problem:2 same problem as earlier with node number now i successfully provisioned server then when i am provisioning client same error as earlier.

    As I explained the nodes array above, please check your database file and check if the client is actually at index 1 like you are using.

    SaSu said:
    Problem:3 "p.provision(name="Light bulb")" for this command if i give wrong name also its provisioning.

    See the documentation of the provision() method in mesh/provision.py. The name parameter is only to give a name to the node, not to refer to the node.

    I don't have a setup to verify this today, but I believe that if there are multiple unprovisioned nodes around and you want to make sure a specific one is provision, you will need to use the uuid parameter. The script codes look like that as far as I can tell.

    Regards,

    Hieu

    P.s:

    SaSu said:
    Edit: Needed info in urgent can you please help me as soon as possible

    I am having a lot of DevZone question at the moment, and I don't have the authority to give anyone's question priority over another's. So, while I will do what I can, please don't expect too highly.

  • I am having a lot of DevZone question at the moment, and I don't have the authority to give anyone's question priority over another's. So, while I will do what I can, please don't expect too highly.

    firstly, I apologize for causing inconvenience to you. and Thank You for your reply.

    As I explained the nodes array above, please check your database file and check if the client is actually at index 1 like you are using.

    for problem:2 i did not copy new database file while provisioning it was same when i provisioned server and looks like index for both "server" and "client" are '0' i attached the file below. you can have a look.

    IMP: can you check with Mesh Server and Mesh Sensor Observor which i am checking now with and give me a update and also another concern, having similar problems with Mesh Chat example too can u please check with "Mesh Chat" example too want to make sure if only me having such kind of problems or not(also please tell me which four digits i want to use for "Mesh Chat" model id: '0059000a' not sure if it is '0059' or '000a').

    {
      "$schema": "",
      "appKeys": [
        {
          "boundNetKey": 0,
          "index": 0,
          "key": "REDACTED",
          "name": "lights"
        },
        {
          "boundNetKey": 0,
          "index": 1,
          "key": "REDACTED",
          "name": "locks"
        }
      ],
      "groups": [
        {
          "address": 49153,
          "name": "Room 1",
          "parentAddress": 0
        },
        {
          "address": 49154,
          "name": "Room 2",
          "parentAddress": 0
        }
      ],
      "ivIndex": 0,
      "ivUpdate": 0,
      "meshName": "BT Mesh",
      "meshUUID": "01020304050607080102030405060708",
      "netKeys": [
        {
          "index": 0,
          "key": "REDACTED",
          "minSecurity": "low",
          "name": "root",
          "phase": 0
        }
      ],
      "nodes": [
        {
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "appKeys": [
            0
          ],
          "cid": "0059",
          "configComplete": false,
          "crpl": 10,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0001",
              "models": [
                {
                  "modelId": "0000"
                },
                {
                  "modelId": "0002"
                },
                {
                  "modelId": "1100"
                },
                {
                  "bind": [
                    0
                  ],
                  "modelId": "1101"
                }
              ]
            }
          ],
          "features": {
            "friend": 0,
            "lowPower": 2,
            "proxy": 0,
            "relay": 0
          },
          "name": "server",
          "netKeys": [
            0
          ],
          "pid": "0000",
          "security": "low",
          "unicastAddress": 16,
          "vid": "0000"
        },
        {
          "UUID": "3442243ef35a46a58bbddbc10ca5395a",
          "appKeys": [
            0
          ],
          "cid": "0059",
          "configComplete": false,
          "crpl": 10,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0001",
              "models": [
                {
                  "modelId": "0000"
                },
                {
                  "modelId": "0002"
                },
                {
                  "bind": [
                    0
                  ],
                  "modelId": "1102",
                  "publish": {
                    "address": 16,
                    "credentials": 0,
                    "index": 0,
                    "period": 0,
                    "retransmit": {
                      "count": 0,
                      "interval": 50
                    },
                    "ttl": 1
                  }
                }
              ]
            }
          ],
          "features": {
            "friend": 0,
            "lowPower": 2,
            "proxy": 0,
            "relay": 0
          },
          "name": "client",
          "netKeys": [
            0
          ],
          "pid": "0000",
          "security": "low",
          "unicastAddress": 17,
          "vid": "0000"
        }
      ],
      "provisioners": [
        {
          "UUID": "00000000000000000000000000000000",
          "allocatedGroupRange": [
            {
              "highAddress": 65279,
              "lowAddress": 49152
            }
          ],
          "allocatedUnicastRange": [
            {
              "highAddress": 32767,
              "lowAddress": 16
            }
          ],
          "name": "BT Mesh Provisioner"
        }
      ],
      "timestamp": "2023-03-23 11:14:48.318598"
    }

    I don't have a setup to verify this today, but I believe that if there are multiple unprovisioned nodes around and you want to make sure a specific one is provision, you will need to use the uuid parameter. The script codes look like that as far as I can tell.

    to confirm it again, "uuid" is the only one to identify the device? i edited in "mesh/provision.py" in "class provisioner" function "__event_handler" to give name when showing "uuid" and "rssi" when sent "p.scan_start()" command but got error.(In app we get name while seeing for "unprovisioned devoces" right? i was hoping it works like that also with "MAC addr" ). That means we also dont get MAC address here right? as we have in the app?.

    Regards

  • Hi, I am out of office from now until the end of the week. Let me try to quickly answer about the nodes field and the indices. Please see the comments I added to the JSON and see that the node named "client" should be in index 1.

    Keep in mind that indexing starts with 0 and increment for each array member.

      "nodes": [
    	{ 	// Index 0 begins
          "UUID": "0d49c695b0b444efb2b6396a4f4b8b10",
          "appKeys": [
            0
          ],
          "cid": "0059",
          "configComplete": false,
          "crpl": 10,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0001",
              "models": [
                {
                  "modelId": "0000"
                },
                {
                  "modelId": "0002"
                },
                {
                  "modelId": "1100"
                },
                {
                  "bind": [
                    0
                  ],
                  "modelId": "1101"
                }
              ]
            }
          ],
          "features": {
            "friend": 0,
            "lowPower": 2,
            "proxy": 0,
            "relay": 0
          },
          "name": "server",
          "netKeys": [
            0
          ],
          "pid": "0000",
          "security": "low",
          "unicastAddress": 16,
          "vid": "0000"
        }, 	// Index 0 ends
        { 	// Index 1 begins
          "UUID": "3442243ef35a46a58bbddbc10ca5395a",
          "appKeys": [
            0
          ],
          "cid": "0059",
          "configComplete": false,
          "crpl": 10,
          "deviceKey": "REDACTED",
          "elements": [
            {
              "index": 0,
              "location": "0001",
              "models": [
                {
                  "modelId": "0000"
                },
                {
                  "modelId": "0002"
                },
                {
                  "bind": [
                    0
                  ],
                  "modelId": "1102",
                  "publish": {
                    "address": 16,
                    "credentials": 0,
                    "index": 0,
                    "period": 0,
                    "retransmit": {
                      "count": 0,
                      "interval": 50
                    },
                    "ttl": 1
                  }
                }
              ]
            }
          ],
          "features": {
            "friend": 0,
            "lowPower": 2,
            "proxy": 0,
            "relay": 0
          },
          "name": "client",
          "netKeys": [
            0
          ],
          "pid": "0000",
          "security": "low",
          "unicastAddress": 17,
          "vid": "0000"
        }	// Index 1 ends
      ],

    Actually I can quickly answer partially about the other part too.

    Yes, UUID looks like the only option to identify a node uniquely in the context of the provision() method.

    The name and address you see in the mobile apps are from the BLE Advertisement.

    I agree it would be helpful if the scan reports can show the nodes' name and address. I will try to look into how next week.

  • Please see the comments I added to the JSON and see that the node named "client" should be in index 1.

    Yes, i got it that "client" index should be '1' but i checked with PYACI commands its not working with '1' but working with '0' as shown in below pictures.1st picture is "server" provisioning(used commands from PYACI Script(1-12))  and 2nd picture is "client" provisioning(used commands from PYACI Script(17-28)). While i checked with index '0' for both server and client not sure how to use commands(23,24,26,28) still i used index '0' and checked but could not get output with '26' command as shown in 3rd picture

    I agree it would be helpful if the scan reports can show the nodes' name and address. I will try to look

    I already tried getting name but says "KeyError: 'name'" in "mesh/provision.py" in "class provisioner" function "__event_handler" like below code.

    def __event_handler(self, event):
            if event._opcode == Event.PROV_UNPROVISIONED_RECEIVED:
                uuid = event._data["uuid"]
                name = event._data["name"]
                rssi = event._data["rssi"]
                if uuid not in self.unprov_list:
                    self.logger.info(
                        "Received UUID {} and name {} with RSSI: {} dB".format(uuid.hex(),name,  rssi))
                    self.unprov_list.append(uuid)

    Regards

Related