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

Sending messages to unicast addresses

In the latest Mesh SDK, nodes are subscribed to a GROUP address. In previous versions - 2.0.0 I believe - you could also send to a predetermined node.

I am trying to figure out how to send a message to any one node via its unicast address. I have created a CLIENT in node_setup.c for this:

case NODE_SETUP_CONFIG_PUBLICATION_ONOFF_CLIENT2:
        {
            config_publication_state_t pubstate = {0};
            client_pub_state_set(&pubstate, 
                                 m_current_node_addr + ELEMENT_IDX_ONOFF_CLIENT2,
                                 UNPROV_START_ADDRESS + CLIENT_MODEL_INSTANCE_COUNT + ELEMENT_IDX_ONOFF_CLIENT1);
            status = config_client_model_publication_set(&pubstate);

            static const access_status_t exp_status[] = {ACCESS_STATUS_SUCCESS};
            expected_status_set(CONFIG_OPCODE_MODEL_PUBLICATION_STATUS, ARRAY_SIZE(exp_status), exp_status);
            break;
        }

However, how do I (a) get the address of a node to send to it and (b) send to it.

Ultimately, I want to be able to configure one of the button presses to send a message to each server one by one.

  • Do I need to have a model for each server? When I use access_model_publish_address_set it just changes the publish address, which means that when I call generic_onoff_client_set it returns NRF_ERROR_BUSY because it's trying to run the same model. If I need a model for each server, how can I do this without having to write a separate NODE_SETUP_CONFIG_PUBLICATION_ONOFF_CLIENTx for each of them?

  • jonappleseed said:
    Do I need to have a model for each server?

     No, you do not need to have a generic on off client model for each server. You could for example publish from one client to multiple servers via a group address. If you however want to publish messages via a unicast address from the client to one server & do this for multiple servers, I would suggest having one client model for each server model. Let's say you had 4 server nodes for example. You could then have four generic on off client models & each client model would publish to the unicast address of one of the server models. You could then use the four buttons on the DK to publish to each of the four server nodes.

    jonappleseed said:
    If I need a model for each server, how can I do this without having to write a separate NODE_SETUP_CONFIG_PUBLICATION_ONOFF_CLIENTx for each of them?

     You could have one NODE_SETUP_CONFIG_PUBLICATION_ONOFF_CLIENT case & then based on the m_current_node_addr, you know which client you are setting the publish address for. You could then have an if or switch statement & then set the publish address to the corresponding server unicast address (similar to how it is done with the if else statement in NODE_SETUP_CONFIG_SUBSCRIPTION_ONOFF_SERVER). In client_config_steps[], remember to have the same amount of NODE_SETUP_CONFIG_APPKEY_BIND_ONOFF_CLIENT calls as there are client models. In addition, you would need to call NODE_SETUP_CONFIG_PUBLICATION_ONOFF_CLIENT the same amount of times as the client models.

  • Hi Bjørn, thanks for the detailed response. I have implemented your suggestions in the provisioner. However, I have used a for loop inside NODE_SETUP_CONFIG_APPKEY_BIND_ONOFF_CLIENT rather than having it listed many times in the config steps. But, I am getting an NRF_BUSY_ERROR after the first time the loop is run. It's caused by client_in_wrong_state() in config_client.c :

    static bool client_in_wrong_state(uint32_t * p_status)
    {
        if (m_client.state == CONFIG_CLIENT_STATE_NONE)
        {        
            *p_status = NRF_ERROR_INVALID_STATE;
            return true;
        }
        else if (m_client.state == CONFIG_CLIENT_STATE_WAIT_REPLY)
        {
            *p_status = NRF_ERROR_BUSY;
            return true;
        }
        return false;
    }

    which is called by app_bind_unbind_send() which is in turn called by config_client_model_app_bind(). I cannot work out why this is.

  • I've got it working now, though the code is not ideal, I have NODE_SETUP_CONFIG_APPKEY_BIND_ONOFF_CLIENT listed 31 (!) times in client_config_steps and NODE_SETUP_CONFIG_PUBLICATION_ONOFF_CLIENT2 listed 30 (!) times. Many thanks for the help.

  • Hi Bjørn,

    I was also looking into sending unicast messages. It seems very silly to me to have a model instance for every possible node in the network, so I was wondering:

    Is it out of spec if a node sends messages to unicast addresses it was not specifically told to publish to by a provisioner?

    Can you call access_model_publish_address_set() before publishing a message, maybe multiple times per second. Or does that break some mesh code? Is this maybe different for reliable and unreliable messages?

Related