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 , 

     

    You would need to define  the server on the python code to be able to handle the event comes to your server model implemented on the server node.

    This is similar to the provisionee implemented in provisioning.py and the provisionee.c implemented in the nRF52 code. 

    But of course you can chose to implement everything on the python code instead. 

    In your python code I don't see you implemented "__simple_on_off_status_handler()" , without that how do you expect it to print out anything ? 

    I assume when you sent the command from the client on the python code, you can see the light physically changed on the NRF52 server+serial node ? This is what you should already have after you follow the instruction here

     

  • I have implemented the status_handler but pasted it incorrect. There is the full code I use for the Server :

    class SimpleOnOffServer(Model):
        SIMPLE_ON_OFF_STATUS = Opcode(0xc4, 0x59, "Simple OnOff Status")
        SIMPLE_ON_OFF_SET = Opcode(0xc1, 0x59, "Simple OnOff Set")
        SIMPLE_ON_OFF_GET = Opcode(0xc2, 0x59, "Simple OnOff Get")
        SIMPLE_ON_OFF_SET_UNACKNOWLEDGED = Opcode(0xc3, 0x59, "Simple OnOff Set Unacknowledged")
        ON_OF_STATE = 0
    
        def __init__(self):
            self.opcodes = [
                (self.SIMPLE_ON_OFF_SET, self.__simple_on_off_status_handler),
                (self.SIMPLE_ON_OFF_GET, self.__simple_on_off_status_handler),
                (self.SIMPLE_ON_OFF_SET_UNACKNOWLEDGED, self.__simple_on_off_status_handler)
            ]
            self.__tid = 0
            super(SimpleOnOffServer, self).__init__(self.opcodes)
    
        @property
        def _tid(self):
            tid = self.__tid
            self.__tid += 1
            if self.__tid >= 255:
                self.__tid = 0
            return tid
    
        def __simple_on_off_status_handler(self, opcode, message):
    
            if opcode == self.SIMPLE_ON_OFF_GET:
                message = bytearray()
                message += struct.pack("<BB", int(self.ON_OF_STATE), self._tid)
                self.send(self.SIMPLE_ON_OFF_STATUS, message)
            elif opcode == self.SIMPLE_ON_OFF_SET:
                self.ON_OF_STATE = message.data[0]
                message = bytearray()
                message += struct.pack("<BB", int(self.ON_OF_STATE), self._tid)
                self.send(self.SIMPLE_ON_OFF_STATUS, message)
            elif opcode == self.SIMPLE_ON_OFF_SET_UNACKNOWLEDGED:
                self.ON_OF_STATE = message.data[0]
    

    this is the problem I can not see any light physical change  on my nRF52840 after I do the provisioning and try to switch it on.

    1) If I don't do the : pe=Provisionee(devide) pe.listen() on the server+serial site and do the provisioning process like in the link i can switch the light on and off via sc.set(True) and i can even sent messages to serial port on pc but i get the error like I said above.

    2) And if I do the pe=Provisionee(devide) pe.listen() process on server+serial I don't get any response from the server+serial after provisioning process and i can not switch the light on, to see this look on Provisioner Log I posted above.

  • Hi,

     

    I'm not sure what could be wrong here. I guess we will need to try ourselves here. I will get back to you tomorrow. 

  • ok thank you man , i need to finish this "mesh-monitor" in this month

  • Hi, 

    I'm trying here but seems that it's more complex than I expected. 

    Doesn't seem there is an easy way to combine a normal application firmware with the serial library to make it output the serial interface. 

    My understanding is that if you want to create a node that use serial interface, you need to declare the model, the configuration server, the provisionee on python on PC, instead of having them in the code in the firmware. 

    So if you want to create a simple on off server, you would need to do what 's similar to what we do in the tutorial with pyACI where we created the simple on off client. You would need configuration server to be declared as well. 

    I'm not sure about your application, could you describe your requirements a little bit more ? 

Reply
  • Hi, 

    I'm trying here but seems that it's more complex than I expected. 

    Doesn't seem there is an easy way to combine a normal application firmware with the serial library to make it output the serial interface. 

    My understanding is that if you want to create a node that use serial interface, you need to declare the model, the configuration server, the provisionee on python on PC, instead of having them in the code in the firmware. 

    So if you want to create a simple on off server, you would need to do what 's similar to what we do in the tutorial with pyACI where we created the simple on off client. You would need configuration server to be declared as well. 

    I'm not sure about your application, could you describe your requirements a little bit more ? 

Children
  • ok man I give up this idea and have a new one which I think is simpler:

    as you know my wish is to build a mesh monitor where i can see all the neighbors of each node

    to do this I modified the simple onoff server for the device. and will modify the client.py

    Idea:  setup a mesh which consist of several servers with advertising beacons activated and a client (client is purely on pc via serial port and interactive.py  and client.py). Each such server can send and receive advertising Beacons to see who is in the neighborhood . Each server creates a list of hes neighbors and if a client which is on pc can send a get_list message it responses with a list of hes neighbors.

    I described it in this topic:

    devzone.nordicsemi.com/.../beacons-in-conjunction-with-a-server-in-a-mesh

     

  • I would think monitoring the heartbeat would be the best option for you. Heartbeat is configure during configuration phase. You state the heart beat original and destination address you want to subscribe and publish to. Base on the original TTL and actual TTL you can find if the heart beat is from your neighbor or not. Please have a look at the heart beat documentation in the spec. 

  • you mean I should just  replace beacons by the heartbeat messages but I will steel need to create a neighbor list in each node and send it to the pc-client right ? Because if the the number of hops = InitTTL - RxTTL +1  is the same it does not mean that they are neighbors if every node just send hertbeat messages and I try to decide it in the "edge-node" (host pc client) which node is neighbor of which nother nodes.

    Implementation question:

    as I understand I need to send two configuration messages if I want transmit and receive heartbeat at each node 

    Config Heartbeat Publication Set  0x80 0x39

    Config Heartbeat Subscription Set  0x80 0x3B

    I have created new Topic for the Heartbeat please join for future discussion

    devzone.nordicsemi.com/.../mesh-monitor-with-heartbeat-messages

  • Hi, 

    Correct, you still need to build the list of the neighbors of a node. I don't think there is a way to build network topology with just the heartbeat. 

    I will be on vacation for 3 weeks. One of my coworker will continue assisting you on the other case. 

Related