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

modification python files for serial mesh example

Hi,

I am using sdk for mesh V.5 and nrf52840 dk.

I have run the serial mesh example and it worked fine.

I also modified the light switch example to send and receive string data through the mesh.

How can I modify the python files of the serial mesh to the config client as I changed in the c.files?

Thank you in advance.

Br,

Sama

Parents Reply Children
  • Hi Hung,

    Thank you for your reply and I am sorry for my late reply.

    I have modified the light switch example to send string data through the mesh and added several peripherals as well. 

    Regarding python files, I mean PyACI example. As far as I found out, the "interactive_pyaci" folder contains python files used for provisioning and configuration of client and server. Furthermore, there is a folder named "model" which includes the generic and simple on-off models. 

    My question is that, regarding modifications I did, how can I use this example?

    Is there any solution to report the hex files of my codes to python?

    Br,

    Sama

  • Hi Sama, 
    I don't know what you modified in your light switch example so it's hard to give you any advice. 

    But if you have a look at the simple_on_off.py model, it's not too hard to understand: 

    class SimpleOnOffClient(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")
    
        def __init__(self):
            self.opcodes = [
                (self.SIMPLE_ON_OFF_STATUS, self.__simple_on_off_status_handler)]
            self.__tid = 0
            super(SimpleOnOffClient, self).__init__(self.opcodes)
    
        def set(self, state):
            message = bytearray()
            message += struct.pack("<BB", int(state), self._tid)
            self.send(self.SIMPLE_ON_OFF_SET, message)
    
        def get(self):
            self.send(self.SIMPLE_ON_OFF_GET)
    
        def unacknowledged_set(self, state):
            message = bytearray()
            message += struct.pack("<BB", int(state), self._tid)
            self.send(self.SIMPLE_ON_OFF_SET_UNACKNOWLEDGED, message)
    
        @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):
            on_off = "on" if message.data[0] > 0 else "off"
            self.logger.info("Present value is %s", on_off)

    In this case it's only one byte payload when you send a SIMPLE_ON_OFF_SET_UNACKNOWLEDGED. ( int state)

    In your case you may want to send varied length string, you may want to have a look here.
    When you receive a message from the server, you will need to print the message inside __simple_on_off_status_handler()

  • Hi Hung,

    Thank you very much for your support.

    I should add some modifications in my code and that has been not completed yet.

    So once it is completed, I will send my codes to you.

    Br,

    Sama

Related