This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

add/delete nodes & set sub-net function in mesh SDK Serial example

Serial Example in Mesh SDK allowed embedded system to provision a Mesh network

by interactive_pyaci.py controlling nRF52 with serial example with UART. 

But the example of Library/serial interface /Interactive mesh provisioning and configuration in infocenter

only has one example of how to provision/config a simple on/off server and a client.

May I ask first,

Does interactive_pyaci.py allow me to add second/ third... servers ?

Then,

1. HOW to add another server into the same network by interactive_pyaci.py ?

2. HOW to create a new sub-net, and record it example_database.json ?

3. HOW to delete a node , and record it example_database.json ?

4. If I have already provision some node and record in example_database.json, and  I restart the serial device,

HOW to control those provisioned simple on/off servers 

Parents
  • Hello Agatha Kuan,

    I would like to suggest you take a try on the PyACI interface, checking the API instructions by add "?" after the name of the API.

    E.g: When you are confused which parameter should be put into "publish_set", you can do:

    In [70]: sc.publish_set?
    Signature: sc.publish_set(key_handle, address_handle)
    Docstring:
    Sets the publication state for the model.
    
    Parameters
    ----------
        key_handle:     application or device key handle
        address_handle: address handle
    File:      c:\nrf52workspace\nrf5_sdk_for_mesh_v2.0.1_src\scripts\interactive_pyaci\mesh\access.py
    Type:      method
    

    1. There's no much difference between adding the first and second server into the same network

    After adding the first server node, please scan unprovisioned nearby device again, and added the unprovisioned device.

    And after the provisioning, you will get another devkey handle and address handle. Please use it to configure the second node. 

    2. Yes, it is possible to add another network by adding a new network key in the database, you can simply modify the "example_database.json"

     "netKeys": [
        {
          "index": 0,
          "key": "18eed9c2a56add85049ffc3c59ad0e12",
          "minSecurity": "low",
          "name": "root",
          "phase": 0
        },
        {
          "index": 1,
          "key": "18eed9c2a56add85049ffc3c59ad0e13",
          "minSecurity": "low",
          "name": "subnet_1",
          "phase": 0
        }
      ],

    3. Seems now we can only delete the node information in the JSON file directly

    4. After you restart the serial device, you still can use PyACI to read the database, add a Simple on/off client and assign the publication state. and we can control the nodes we have provisioned and configured before.

    Any suggestion and comment from other Devzone members are very welcome Slight smile

Reply
  • Hello Agatha Kuan,

    I would like to suggest you take a try on the PyACI interface, checking the API instructions by add "?" after the name of the API.

    E.g: When you are confused which parameter should be put into "publish_set", you can do:

    In [70]: sc.publish_set?
    Signature: sc.publish_set(key_handle, address_handle)
    Docstring:
    Sets the publication state for the model.
    
    Parameters
    ----------
        key_handle:     application or device key handle
        address_handle: address handle
    File:      c:\nrf52workspace\nrf5_sdk_for_mesh_v2.0.1_src\scripts\interactive_pyaci\mesh\access.py
    Type:      method
    

    1. There's no much difference between adding the first and second server into the same network

    After adding the first server node, please scan unprovisioned nearby device again, and added the unprovisioned device.

    And after the provisioning, you will get another devkey handle and address handle. Please use it to configure the second node. 

    2. Yes, it is possible to add another network by adding a new network key in the database, you can simply modify the "example_database.json"

     "netKeys": [
        {
          "index": 0,
          "key": "18eed9c2a56add85049ffc3c59ad0e12",
          "minSecurity": "low",
          "name": "root",
          "phase": 0
        },
        {
          "index": 1,
          "key": "18eed9c2a56add85049ffc3c59ad0e13",
          "minSecurity": "low",
          "name": "subnet_1",
          "phase": 0
        }
      ],

    3. Seems now we can only delete the node information in the JSON file directly

    4. After you restart the serial device, you still can use PyACI to read the database, add a Simple on/off client and assign the publication state. and we can control the nodes we have provisioned and configured before.

    Any suggestion and comment from other Devzone members are very welcome Slight smile

Children
  • hi , about 4. exactly how to read the database?


    In [1]: db = MeshDB("database/example_database.json")
    
    In [2]: db.provisioners
    Out[2]: [{'name': 'BT Mesh Provisioner', 'UUID': bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 'allocated_unicast_range': [{'low_address': 0010, 'high_address': 7fff}], 'allocated_group_range': [{'low_address': c000, 'high_address': feff}]}]
    
    In [3]: db.load()
    
    In [4]: sc = SimpleOnOffClient()
    
    In [5]: device.model_add(sc)
    
    In [6]: sc.publish_set(0, 0)
    
    In [7]: sc.set(True)
    
    
    In [9]: cc = ConfigurationClient(db)
    
    In [10]: device.model_add(cc)
    
    In [11]: cc.node_get(0x10)
    Out[11]: {'UUID': bytearray(b'\x00Y\xff\xff\x00\x00\x00\x00\t\xf5\xcfq\xa0\x10\x05w'), 'device_key': bytearray(b'\x06s\x89(\xf8Y\xcf\xc1F,\xc1\xd6\xdap\x95\xc7'), 'unicast_address': 0010, 'net_keys': [{'index': 0}], 'config_complete': False, 'name': '0577', 'security': <SecurityLevel.LOW: 'low'>, 'cid': 0059, 'vid': 0000, 'pid': 0000, 'crpl': 0020, 'features': {'relay': <FeatureState.DISABLED: 0>, 'proxy': <FeatureState.NOT_SUPPORTED: 2>, 'friend': <FeatureState.NOT_SUPPORTED: 2>, 'low_power': <FeatureState.NOT_SUPPORTED: 2>}, 'elements': [{'index': 0, 'location': 0000, 'models': [{'model_id': 0000, 'subscribe': [], 'publish': None, 'bind': []}, {'model_id': 0002, 'subscribe': [], 'publish': None, 'bind': []}, {'model_id': 00590000, 'subscribe': [], 'publish': None, 'bind': [0]}], 'name': ''}], 'app_keys': [0], 'secure_network_beacon': None, 'network_transmit': None, 'relay_retransmit': None, 'default_TTL': None}
    
    In [12]: sc.set(True)
    
    I2018-05-16 16:39:55,156 - ERROR - COM12: None: ERROR_REJECTEDn

    I have provisioned a node with simple on/off server element ,

    and the above is what I do after restarting the serial device,

    there is a ERROR_REJECTED to control the provisioned node.

    Am I failed to read the database, or something wrong ?

  • Hello Agatha Kuan

    The reason why "ERROR_REJECTED" happened is because of the "publish address" to the node haven't been added.

    So the procedure would be like:

    In [1]: db = MeshDB("database/example_database.json")
    
    In [2]: p = Provisioner(device, db)
    
    In [3]: 2018-05-17 15:37:26,908 - INFO - COM4: Success
    2018-05-17 15:37:26,911 - INFO - COM4: Success
    2018-05-17 15:37:26,916 - INFO - COM4: SubnetAdd: {'subnet_handle': 0}
    2018-05-17 15:37:26,919 - INFO - COM4: AppkeyAdd: {'appkey_handle': 0}
    2018-05-17 15:37:26,919 - INFO - COM4: AppkeyAdd: {'appkey_handle': 1}
    
    In [3]: device.send(cmd.AddrPublicationAdd(db.nodes[0].unicast_address))
    
    2018-05-17 15:38:09,309 - INFO - COM4: AddrPublicationAdd: {'address_handle': 0}
    In [4]: sc = SimpleOnOffClient()
    
    In [5]: device.model_add(sc)
    
    In [6]: sc.publish_set(0, 0)
    
    In [7]: sc.set(True)

    The key parts are:

    We need to add the network key and application key to the connectivity device, so we call

    p = Provisioner(device, db)

    You can see the one network key and two application keys has been added. (Actually we only use the first application key)

    Since we need to setup the SimpleOnOff client model on the connectivity device and also set the publish address for the connectivity device to publish the message to the destination node, so we have to add the address of the destination node. (You can see the connectivity device reply the result)

    device.send(cmd.AddrPublicationAdd(db.nodes[0].unicast_address))
    
    2018-05-17 15:38:09,309 - INFO - COM4: AddrPublicationAdd: {'address_handle': 0}

    The address handle '0', is the second parameter for the sc.publish_set().

    And this is the key why you saw "ERROR_REJECTED", because the publish address haven't been added.

    I found that the sc.set() cannot work immediately, may need a short time for the setting to take effect.

    I will check with internal to see the reason.

    Best regards,

    Rick

  • Thanks for your answer. I've try 

    device.send(cmd.AddrPublicationAdd(db.nodes[0].unicast_address))

    to public to provisioned nodes.

    HOWEVER, how to subscribe the node to receive message from  ?

    simple_on_off_server_status_publish(simple_on_off_server_t * p_server, uint8_t value);

    I  have try to subscripbe to same device address

     

    In [46]: device.send(cmd.AddrSubscriptionAdd(db.nodes[0].unicast_address))

    but it reply :

    2018-05-24 14:57:47,488 - ERROR - COM12: AddrSubscriptionAdd: ERROR_INVALID_DATA

    which means I can not subscribe the same address , or I have mistake in my command ?

  • Hello Agatha,

    Yes, we cannot subscribe the same address we publish.

    If you are provisioner (since you are trying the serial interface with provisioner function), and want to receive the message from the node, you can configure the node to publish the message to the unicast address of the provisioner.

  • Hello Agatha,

    I don't see how to find the unicast Address of the provisionner ... are you sure we can publish to the provisionner directly ? What is the provisionner unicast address ?

    thank you,

Related