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

interactive_pyaci acting as a node in the network

I am working on creating a mesh network consisting of sensors and output devices.

I am using the serial example with interactive_pyaci to provision the network from a PC,

I would also like the PC to participate in the network as a node.

I can poll my sensors for the state of an input and I can set the state of an output, using the Gereric_OnOff  model. 

What I would like to do is have the PC receive a notification on input change.

I currently have the sensor set up to transmit using the access_model_publish().  How do I get the interactive_pyaci to subscribe to the messages, so it can respond to events.

This is the code on the sever side

uint32_t simple_input_server_status_publish(simple_input_server_t * p_server, bool value)
{
    simple_input_msg_status_t status;
    status.present_on_off = value ? 1 : 0;
    access_message_tx_t msg;
    msg.opcode.opcode = SIMPLE_INPUT_OPCODE_STATUS;
    msg.opcode.company_id = SIMPLE_INPUT_COMPANY_ID;
    msg.p_buffer = (const uint8_t *) &status;
    msg.length = sizeof(status);
    msg.force_segmented = false;
    msg.transmic_size = NRF_MESH_TRANSMIC_SIZE_DEFAULT;
    msg.access_token = nrf_mesh_unique_token_get();
    return access_model_publish(p_server->model_handle, &msg);
}

This is derives from the simple_on_off_server.

 

I have not implemented a client on the serial board as I want the PC to perform the client functions

I am using Mesh sdk 3.1.0 and the interactive_pyaci script that cam with it. I have added the new model for the script

from mesh.access import Model, Opcode
import struct


class SimpleInputClient(Model):
    SIMPLE_INPUT_STATUS = Opcode(0xe4, 0x5900, "Simple Input Status")
    SIMPLE_INPUT_GET = Opcode(0xe2, 0x0059, "Simple Input Get")

    def __init__(self):
        self.opcodes = [
            (self.SIMPLE_INPUT_STATUS, self.__simple_input_status_handler)]
        self.__tid = 0
        super(SimpleInputClient, self).__init__(self.opcodes)

    def get(self):
        self.send(self.SIMPLE_INPUT_GET)

    @property
    def _tid(self):
        tid = self.__tid
        self.__tid += 1
        if self.__tid >= 255:
            self.__tid = 0
        return tid

    def __simple_input_status_handler(self, opcode, message):
        on_off = "on" if message.data[0] > 0 else "off"    
        self.logger.info("Input value is %s", on_off)

  • Hi,

    This should be described in the configuration demo readme:

    #### Publishing and subscribing
    
    With both the client and server in the network, we can let the client _subscribe_ to state changes
    from the server.
    
    To do that, we ensure that we're talking to the Light switch server, and set its publication state
    such that it can publish state changes to a pre-defined group address:
    
    
        In  [25]: cc.publish_set(8, 0)
        In  [26]: cc.model_publication_set(db.nodes[0].unicast_address, mt.ModelId(0x1000), mt.Publish(db.groups[0].address, index=0, ttl=1))
        2018-03-12 15:10:48,071 - INFO - COM1.ConfigurationClient: Model publication status: AccessStatus.SUCCESS
        2018-03-12 15:10:48,078 - INFO - COM1.ConfigurationClient: Publication status for model 1000 at element 10 to {'period': 0, 'ttl': 1, 'address': 0010, 'retransmit': {'interval': 50, 'interval_steps': 0, 'count': 0}, 'index': 0, 'credentials': <FriendshipCredentials.DISABLED: 0>}
    
    
    Next, we add the same group address to the client's _subscription list_:
    
        In  [27]: cc.publish_set(9, 1)
        In  [28]: cc.model_subscription_add(db.nodes[1].unicast_address + 1, db.groups[0].address, mt.ModelId(0x1001))
        2018-03-12 15:11:49,993 - INFO - COM1.ConfigurationClient: Model subscription status: AccessStatus.SUCCESS
        2018-03-12 15:11:49,996 - INFO - COM1.ConfigurationClient: Added subscription 'c001' to model 1001 at element 18
    
    
    You should now be able to use the Generic OnOff client to change the state of the server and observe
    that the client also changes its state accordingly:
    
    
        In  [16]: gc.set(True)
        2018-03-09 15:12:49,230 - INFO - COM1.GenericOnOffClient: Present value is on

    Best regards,
    Jørgen

Related