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.

  • Hi,

     

    Could you post the full log of Provisioner and provisionee ? I assume you should have separate python windows to control them. 

    Make sure you declare the simple on of server on the provisionee as well (This I believe has not been implemented in our python code, you need to implement one). 

  • Ok, ill try to implement the SimpleOnOffServer. Can you say me why do I need this ? I dont see the full puzzle

  • Ok there is my first try to implement SimpleOnOffServer:

    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

    1) the problem is, in access.py there is no access_model_publish() or accecc_model_reply()

    just the send method and I don't know how to implement this, that why I use the send(opcode,message) with

    opcode=SIMPLE_ON_OFF_STATUS

    2) At the moment i still does not work and I am not sure that I have implemented the OnOff Server correct and whether I use this Server in correct context

    Provisioner Log:

    C:\Users\AEH4Lab\nRF\mesh_2.1.1\scripts\interactive_pyaci>python interactive_pyaci.py -d COM10 --no-logfile

        To control your device, use d[x], where x is the device index.
        Devices are indexed based on the order of the COM ports specified by the -d option.
        The first device, d[0], can also be accessed using device.

        Type d[x]. and hit tab to see the available methods.

    add packet recipient
    <bound method Access.__event_handler of <mesh.access.Access object at 0x03AC6830>>
    add packet recipient
    <bound method Interactive.__event_handler of <__main__.Interactive object at 0x03AC6750>>
    Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)]
    Type 'copyright', 'credits' or 'license' for more information
    IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.

    In [1]: 2018-07-30 12:55:37,932 - ERROR - COM10: Invalid packet: bytearray(b'\x00')
    2018-07-30 12:55:38,497 - INFO - COM10: Device rebooted.
    In [1]: db = MeshDB("database/example_database.json")

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

    In [3]: 2018-07-30 12:59:11,213 - INFO - COM10: Success
    2018-07-30 12:59:11,214 - INFO - COM10: Success
    2018-07-30 12:59:11,217 - INFO - COM10: SubnetAdd: {'subnet_handle': 0}
    2018-07-30 12:59:11,219 - INFO - COM10: AppkeyAdd: {'appkey_handle': 0}
    2018-07-30 12:59:11,222 - INFO - COM10: AppkeyAdd: {'appkey_handle': 1}
    In [3]: p.scan_start()


    In [4]: 2018-07-30 12:59:17,618 - INFO - COM10: Received UUID 0059ffff00000000c4e0725be36e2477 with RSSI: -35 dB
    In [4]: p.scan_stop()

    2018-07-30 12:59:23,919 - INFO - COM10: Success
    In [5]: p.provision(name="Light bulb")

    In [2018-07-30 12:59:29,999 - INFO - COM10: Provision: {'context': 0}6
    ]:      2018-07-30 12:59:30,013 - INFO - COM10: Link established
    2018-07-30 12:59:30,067 - INFO - COM10: Received capabilities
    2018-07-30 12:59:30,070 - INFO - COM10: Number of elements: 1
    2018-07-30 12:59:30,075 - INFO - COM10: OobUse: {'context': 0}
    2018-07-30 12:59:30,298 - INFO - COM10: ECDH request received
    2018-07-30 12:59:30,308 - INFO - COM10: EcdhSecret: {'context': 0}
    2018-07-30 12:59:30,636 - INFO - COM10: Provisioning complete
    2018-07-30 12:59:30,638 - INFO - COM10:         Address(es): 0x10-0x10
    2018-07-30 12:59:30,640 - INFO - COM10:         Device key: ddf8ee131ea34be4575fa67694f52ca7
    2018-07-30 12:59:30,643 - INFO - COM10:         Network key: 18eed9c2a56add85049ffc3c59ad0e12
    2018-07-30 12:59:30,645 - INFO - COM10: Adding device key to subnet 0
    2018-07-30 12:59:30,647 - INFO - COM10: Adding publication address of root element
    2018-07-30 12:59:30,659 - INFO - COM10: DevkeyAdd: {'devkey_handle': 8}
    2018-07-30 12:59:30,662 - INFO - COM10: AddrPublicationAdd: {'address_handle': 0}
    2018-07-30 12:59:30,731 - INFO - COM10: Provisioning link closed
    In [6]: cc = ConfigurationClient(db)

    In [7]: device.model_add(cc)

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

    In [9]: cc.composition_data_get()

    2018-07-30 13:00:08,871 - INFO - COM10: SuccessI
    In [10]: cc.appkey_add(0)

    2018-07-30 13:01:14,059 - INFO - COM10: Success
    In [11]: cc.model_app_bind(db.nodes[0].unicast_address, 0, mt.ModelId(0, 0x59))

    2018-07-30 13:01:22,205 - INFO - COM10: Success
    In [12]: sc = SimpleOnOffClient()

    In [13]: device.model_add(sc)

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

    In [15]: sc.set(True)

    2018-07-30 13:01:51,189 - INFO - COM10: Success
    In [16]:

    As you can see there is no response from the server after Provisioning Process

    Provisionee Log:

    In [2]: send(cmd.Echo("Test"))

    In [3]: 2018-07-30 12:57:11,885 - INFO - COM11: {event: DeviceEchoRsp, data: {'data': bytearray(b'Test')}}
    pe=Provisionee(device)
    add packet recipient
    <bound method Provisionee.__event_handler of <mesh.provisioning.Provisionee object at 0x03CE0070>>

    In [4]: 2018-07-30 12:57:29,531 - INFO - COM11: Success
    2018-07-30 12:57:29,536 - INFO - COM11: Success
    ss=SimpleOnOffServer()

    In [5]: device.model_add(ss)

    In [6]: ss.publish_set(0,0)

    In [7]: pe.listen()

    In [8]: 2018-07-30 12:58:40,869 - INFO - COM11: Success
    2018-07-30 12:59:30,002 - INFO - COM11: Link established
    2018-07-30 12:59:30,644 - INFO - COM11: Provisioning complete
    2018-07-30 12:59:30,644 - INFO - COM11: Address(es): 0x10-0x10
    2018-07-30 12:59:30,644 - INFO - COM11: Device key: ddf8ee131ea34be4575fa67694f52ca7
    2018-07-30 12:59:30,645 - INFO - COM11: Network key: 18eed9c2a56add85049ffc3c59ad0e12
    2018-07-30 12:59:30,645 - INFO - COM11: Adding network key (subnet)
    2018-07-30 12:59:30,645 - INFO - COM11: Adding device key to subnet 0
    2018-07-30 12:59:30,646 - INFO - COM11: Setting the local unicast address range
    2018-07-30 12:59:30,653 - INFO - COM11: SubnetAdd: {'subnet_handle': 0}
    2018-07-30 12:59:30,655 - INFO - COM11: DevkeyAdd: {'devkey_handle': 1}
    2018-07-30 12:59:30,657 - INFO - COM11: Success
    2018-07-30 12:59:30,664 - INFO - COM11: Provisioning link closed

  • 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.

Related