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

include Mesh Serial device into the Light Switch Mesh

Hello, I want to include Mesh Serial Example into the Mesh Light Switch example.

The aim is to allow the serial device to listen to the mesh messages.

What is the best way to do this ? Do i need to write a new Model ?

My idea was just to extend the Client Model by the Serial features but I'm not sure if it will work and before i spend a lot of time on it i better ask.

Parents
  • Hi,

     

    Do you want to let the light switch model runs autonomously on the serial node or you want to let the model run on the peer device (e.g PC) and the serial still act a just connectivity chip ? 

    If you want to let the model run on the peer device, we already do that in this guide, look for "blinking LEDs"

    But you can add a model in the serial code as well, shouldn't have any problem. 

  • I want to run the client model on the serial node or rather I want to integrate the seril communication abilities  into the client model of the mesh  light switch example. For that :
    in mesh_init(void) I added : nrf_mesh_serial_init(NULL);   
    in the start() I added : nrf_mesh_serial_enable();

    And I added all necessery files for serial communication from the mesh into the Light Switch Client Model to activate the serial communication, but  if I try to send some messages  from Server to Client the application does not work proper and after some "button messages" it seems that the Client Model application crashes.

    My aim is to build a mesh with several servers and client and one node with the serial communication abilities. All nodes should have all the necessary keys. And in the end i want to receive with this serial node all the mesh messages and send them to the host pc


    the problem is:

    1) i dont know how add the same keys to all devices by the "hand"

    2) i dont know how to receive the mesh messages with the serial node or rather i dont know how to implement the receive funktion in serial node (is it implemented allready ?)

     3) I can not use interactive.py script to send comands to the serial device, I can just receive events from serial device. Because of this unsolved problem : devzone.nordicsemi.com/.../mesh-serial-example-problem-timeout-waiting-for-event

    That's why i tried to use the Light-Switch Example and to activate the Serial Communication by the Client. Because in this example I have one provisioner and all nodes get the keys.

  • Hi, 

    A serial node should work like a normal node and vice versa. We don't know what kind of issue you have. We need more debug information. We can try to create an example for you but due to reduced staff in the summer, we can't do it right now. 

    1. What do you mean by keys ? It's the network key, app key or device key ? What is "by hand" ? You mean like hardcoded in the application , not by a provisioner ? 

    2. I guess it's the best to test between 2 serials nodes, one works a provisioner and one as a normal node. But you need to make the PyACI works first. 

    3. Bjørn Kvale is on vacation for 1 week. But which hardware did you use ? Was it a nRF52 DK ? Could you verify you can communicate with UART to PC without problem ? (test with UART example in SDK v15)

     

  • Hey,

    An Example would be great !

    1)I was confused  and wanted to hard code the dev,net,app keys without provisioning but it is not more necessary.

    Now  I can run the serial example on Windows and it works fine till now.  Think the problem is in the Linux Mint 18 and how the OS manages the connection. If your are interested in I can try to give you some more information about it.

    2 and 3) not important anymore

    Now I try to understand the , Interactive mesh provisioning and configuration with PyACI on Windows.

    http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.meshsdk.v2.0.1%2Fmd_examples_README.html

    Concerning this I have some questions:

    0) I do not understand the exactly functionality of the serial device in this example.

    Do we use the serial node just to send command and receive events or do you load some models onto the serial device in the process ?

    provisioning:
    Next, we create a Provisioner object: p = Provisioner(device, db)

    1) the Device there is the serial device right ? where do we create the provisioning object ?


    DevkeyAdd: {'devkey_handle': 8} 

    2) why is the handle=8 ? what do we have in the previous 7 handles ?

    configuration:

    device.model_add(cc)

    3) I do not understand the magic change, previously the device was the serial device or is it not so ?

    4) How I can turn on the relay mode ?

    5) now i have the server,client and the serial device in the mesh , how can i receive the mesh messages with serial device and send it to the hos pc ?

  • ok, I  build a mesh: Server with Serial feature and Client.  To build the mesh I used additional serial device and provisioned the server and the client with help of Interactive mesh provisioning and configuration python script.

    I modified the Light Switch Server:

     ERROR_CHECK(nrf_mesh_serial_init(NULL));  in the mesh_init(void)

       ERROR_CHECK(nrf_mesh_serial_enable()); in the start(void)

    and in the  on_off_server_set_cb (...) I added

     uint32_t result;
      char data[]="Message Received\n";
      result=nrf_mesh_serial_tx (data, sizeof(data));

    It works almost. I can receive the Message from the Client to the server and send it to the Host-PC but i get Error in the aci_uart.py and access.py



    2018-07-20 08:52:27,063 - INFO - COM11: {event: Application, data: {'data': bytearray(b'Message Received\n\x00')}}
    2018-07-20 08:52:27,070 - ERROR - COM11: Exception in pkt handler <bound method Access.__event_handler of <mesh.access.Access object at 0x038BB910>>
    2018-07-20 08:52:27,096 - ERROR - COM11: traceback: Traceback (most recent call last):
    File "C:\Users\XYZ\nRF\mesh_2.1.1\scripts\interactive_pyaci\aci\aci_uart.py", line 88, in process_packet
    fun(packet)
    File "C:\Users\XYZ\nRF\mesh_2.1.1\scripts\interactive_pyaci\mesh\access.py", line 209, in __event_handler
    assert(element_index < len(self.elements) and element_index >= 0)
    AssertionError

    Any ideas what I'm doing wrong ?

    I think the constellation Server with Serial feature and Client + Serial Device to provide the keys is not the best solution. It must work also with Server, Client and purely Serial device. Because if I look on the log of the purely Serial device, I see that the serial device gets the mesh messages if I push the button on the client site and send message to the server but at the moment i don't know how to receive this messages on the Host-PC that why i use again the "Serial-Feature" by the Server.

    Debug Logs from purely Serial Device by pushing the Button on the Client:

    <t:    9565047>, net_packet.c,  230, Unencrypted data: : 00106EFCBFA313F56D5395D0
    <t:    9565698>, net_packet.c,  230, Unencrypted data: : 00126E5813DD6B10E872BC
    <t:    9580083>, net_packet.c,  230, Unencrypted data: : 00106EDEF1B21FBEFF5E9EA2
    <t:    9580991>, net_packet.c,  230, Unencrypted data: : 00126E3740A10ED65F70BE
    <t:    9598512>, net_packet.c,  230, Unencrypted data: : 00106ECA6E96D67C0170C3B4
    <t:    9599003>, net_packet.c,  230, Unencrypted data: : 00126E4FEAF4A021018537

Reply
  • ok, I  build a mesh: Server with Serial feature and Client.  To build the mesh I used additional serial device and provisioned the server and the client with help of Interactive mesh provisioning and configuration python script.

    I modified the Light Switch Server:

     ERROR_CHECK(nrf_mesh_serial_init(NULL));  in the mesh_init(void)

       ERROR_CHECK(nrf_mesh_serial_enable()); in the start(void)

    and in the  on_off_server_set_cb (...) I added

     uint32_t result;
      char data[]="Message Received\n";
      result=nrf_mesh_serial_tx (data, sizeof(data));

    It works almost. I can receive the Message from the Client to the server and send it to the Host-PC but i get Error in the aci_uart.py and access.py



    2018-07-20 08:52:27,063 - INFO - COM11: {event: Application, data: {'data': bytearray(b'Message Received\n\x00')}}
    2018-07-20 08:52:27,070 - ERROR - COM11: Exception in pkt handler <bound method Access.__event_handler of <mesh.access.Access object at 0x038BB910>>
    2018-07-20 08:52:27,096 - ERROR - COM11: traceback: Traceback (most recent call last):
    File "C:\Users\XYZ\nRF\mesh_2.1.1\scripts\interactive_pyaci\aci\aci_uart.py", line 88, in process_packet
    fun(packet)
    File "C:\Users\XYZ\nRF\mesh_2.1.1\scripts\interactive_pyaci\mesh\access.py", line 209, in __event_handler
    assert(element_index < len(self.elements) and element_index >= 0)
    AssertionError

    Any ideas what I'm doing wrong ?

    I think the constellation Server with Serial feature and Client + Serial Device to provide the keys is not the best solution. It must work also with Server, Client and purely Serial device. Because if I look on the log of the purely Serial device, I see that the serial device gets the mesh messages if I push the button on the client site and send message to the server but at the moment i don't know how to receive this messages on the Host-PC that why i use again the "Serial-Feature" by the Server.

    Debug Logs from purely Serial Device by pushing the Button on the Client:

    <t:    9565047>, net_packet.c,  230, Unencrypted data: : 00106EFCBFA313F56D5395D0
    <t:    9565698>, net_packet.c,  230, Unencrypted data: : 00126E5813DD6B10E872BC
    <t:    9580083>, net_packet.c,  230, Unencrypted data: : 00106EDEF1B21FBEFF5E9EA2
    <t:    9580991>, net_packet.c,  230, Unencrypted data: : 00126E3740A10ED65F70BE
    <t:    9598512>, net_packet.c,  230, Unencrypted data: : 00106ECA6E96D67C0170C3B4
    <t:    9599003>, net_packet.c,  230, Unencrypted data: : 00126E4FEAF4A021018537

Children
  • after provisioning of the light switch server+serial_enable and light switch client with the pyACI script,

    I connect to the server serial and can see this if I press the button on the client site:

    {event: MeshMessageReceivedUnicast, data: {'src': 18, 'dst': 16, 'appkey_handle': 0, 'subnet_handle': 0, 'ttl': 1, 'adv_addr_type': 1, 'adv_addr': bytearray(b'\x16\xfc\xb4\xb0\xd7\xea'), 'rssi': -30, 'actual_length': 5, 'data': bytearray(b'\xc1\x00Y\x00\x13')}}

    the problem is in this code line.

    element_index = event._data["dst"] - self.elements[0].address
    assert(element_index < len(self.elements) and element_index >= 0)

    the element_index=15 in this case but the number of the elements is 1 in this case.

  • Hi,

     It's just an update. We found a bug in the python code that we didn't update the element addresses database. 

    You can just add this code: 

          for i, e in enumerate(self.iaci.access.elements):

                    e.address = event._data["address"] + i

    At the end of Provisionee() in provisioning.py right before "else:"
    This will update the iaci database of the address.

    Please let us know if this workaround works. 

  • Hey, no did not work

    2018-07-26 14:18:50,659 - ERROR - COM11: Exception in pkt handler <bound method Access.__event_handler of <mesh.access.Access object at 0x03AC64F0>>
    2018-07-26 14:18:50,661 - ERROR - COM11: traceback: Traceback (most recent call last):
      File "C:\Users\Lab\nRF\mesh_2.1.1\scripts\interactive_pyaci\aci\aci_uart.py", line 94, in process_packet
        fun(packet)
      File "C:\Users\Lab\nRF\mesh_2.1.1\scripts\interactive_pyaci\mesh\access.py", line 209, in __event_handler
        assert(element_index < len(self.elements) and element_index >= 0)
    AssertionError

    I want to point this out to you: I use two pyACI instances one instance i run with the pure serial device to provide the provisioning process for server with serial feature enable and client. After the provisioning i use another instance of pyACI and connect to the another port to the server with serial feature enable and try to get messages send to this server.

    But this fixed partly another problem I had: to communicate from Several Clients to one Server

    devzone.nordicsemi.com/.../interactive-mesh-provisioning-and-configuration-provisioning-several-clients-problem

  • This customer has almost the same set up like your and with the fix it worked for him. Could you have a look here

    Note that you need to start the provisionee() in python on the PC when you do provisioning of the node, so that the python app can update the address of the node. 

  • What I did is fallow: i ues the pure serial device as Provisioner on COM10 and use the Server Device with serial enable on COM11 as Provisionee, start the Provisionee(device) and start to listen.

    the provisioning process works but after that i get no response from the device and I can not control anything.

    In [1]: db = MeshDB("database/example_database.json")

    In [2]: p = Provisioner(d[0], db)
    add packet recipient
    <bound method Provisioner.__event_handler of <mesh.provisioning.Provisioner object at 0x04

    In [3]: 2018-07-27 10:36:15,036 - INFO - COM10: Success
    2018-07-27 10:36:15,038 - INFO - COM10: Success
    2018-07-27 10:36:15,042 - INFO - COM10: SubnetAdd: {'subnet_handle': 0}
    2018-07-27 10:36:15,046 - INFO - COM10: AppkeyAdd: {'appkey_handle': 0}
    2018-07-27 10:36:15,050 - INFO - COM10: AppkeyAdd: {'appkey_handle': 1}



    In [4]: pe=Provisionee(d[1])
    add packet recipient
    <bound method Provisionee.__event_handler of <mesh.provisioning.Provisionee object at 0x04

    2018-07-27 10:36:50,910 - INFO - COM11: Success
                                                           2018-07-27 10:36:50,920 - INFO - CO
    In [5]: pe.listen()

    2018-07-27 10:37:04,388 - INFO - COM11: SuccessIn
    In [6]: p.scan_start()

    2018-07-27 10:37:12,056 - INFO - COM10: SuccessIn
     [7]:   2018-07-27 10:37:13,242 - INFO - COM10: Received UUID 0059ffff00000000c4e0725be36e
    In [7]: p.scan_stop()

    I2018-07-27 10:37:32,578 - INFO - COM10: Successn
    In [8]: p.provision(name="Light bulb")

    In [2018-07-27 10:37:40,290 - INFO - COM10: Provision: {'context': 0}9
    ]:      2018-07-27 10:37:40,303 - INFO - COM11: Link established
    2018-07-27 10:37:40,318 - INFO - COM10: Link established
    2018-07-27 10:37:40,372 - INFO - COM10: Received capabilities
    2018-07-27 10:37:40,374 - INFO - COM10: Number of elements: 1
    2018-07-27 10:37:40,378 - INFO - COM10: OobUse: {'context': 0}
    2018-07-27 10:37:40,571 - INFO - COM10: ECDH request received
    2018-07-27 10:37:40,581 - INFO - COM10: EcdhSecret: {'context': 0}
    2018-07-27 10:37:40,959 - INFO - COM10: Provisioning complete
    2018-07-27 10:37:40,962 - INFO - COM10:         Address(es): 0x10-0x10
    2018-07-27 10:37:40,964 - INFO - COM10:         Device key: c58ef2bd05d6876e372d719eac1972
    2018-07-27 10:37:40,967 - INFO - COM10:         Network key: 18eed9c2a56add85049ffc3c59ad0
    2018-07-27 10:37:40,969 - INFO - COM10: Adding device key to subnet 0
    2018-07-27 10:37:40,972 - INFO - COM10: Adding publication address of root element
    2018-07-27 10:37:40,984 - INFO - COM10: DevkeyAdd: {'devkey_handle': 8}
    2018-07-27 10:37:40,989 - INFO - COM10: AddrPublicationAdd: {'address_handle': 0}
    2018-07-27 10:37:40,992 - INFO - COM11: Provisioning complete
    2018-07-27 10:37:40,993 - INFO - COM11:         Address(es): 0x10-0x10
    2018-07-27 10:37:40,994 - INFO - COM11:         Device key: c58ef2bd05d6876e372d719eac1972
    2018-07-27 10:37:40,995 - INFO - COM11:         Network key: 18eed9c2a56add85049ffc3c59ad0
    2018-07-27 10:37:40,996 - INFO - COM11: Adding network key (subnet)
    2018-07-27 10:37:40,997 - INFO - COM11: Adding device key to subnet 0
    2018-07-27 10:37:40,998 - INFO - COM11: Setting the local unicast address range
    2018-07-27 10:37:41,003 - INFO - COM11: SubnetAdd: {'subnet_handle': 0}
    2018-07-27 10:37:41,005 - INFO - COM11: Provisioning link closed
    2018-07-27 10:37:41,007 - INFO - COM11: DevkeyAdd: {'devkey_handle': 1}
    2018-07-27 10:37:41,008 - INFO - COM11: Success
    2018-07-27 10:37:41,079 - INFO - COM10: Provisioning link closed
    In [9]: cc = ConfigurationClient(db)

    In [10]: d[0].model_add(cc)

    In [11]: cc.publish_set(8, 0)

    In [12]: cc.composition_data_get()

    2018-07-27 10:38:38,336 - INFO - COM10: SuccessIn
    In [13]: cc.appkey_add(0)

    In 2018-07-27 10:38:52,380 - INFO - COM10: Success[
    In [14]: cc.model_app_bind(db.nodes[0].unicast_address, 0, mt.ModelId(0, 0x59))

    2018-07-27 10:39:03,965 - INFO - COM10: Success
    In [15]: sc = SimpleOnOffClient()

    In [16]: d[0].model_add(sc)

    In [17]: sc.publish_set(0, 0)

    In [18]: sc.set(True)

    2018-07-27 10:39:44,809 - INFO - COM10: SuccessI

Related