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

Send message from gateway to specific LPN address

Hi,

I am trying to send messages from my gateway, which has UART and __LOG enabled, to a specific LPN address (0003).

 So I want to send messages from my FN Light1 (0002) to LPN Button1 (0003).

I am trying to change publication address, and I think this works:

static void change_publication_address(access_model_handle_t handle, uint16_t address)
{
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Change Publication address\n");
    uint32_t status = NRF_SUCCESS;  
    nrf_mesh_address_t publish_address_stored;
    destination_address = address;
    
    if(publish_address_handle != DSM_HANDLE_INVALID)
    {
        NRF_MESH_ASSERT(dsm_address_publish_remove(publish_address_handle) == NRF_SUCCESS);
    }

    if(access_model_publish_address_get(handle, &publish_address_handle) == NRF_SUCCESS)      
    {
        status = dsm_address_publish_add(destination_address, &publish_address_handle);       // add destination address        
    }   
    else
    {
        if(dsm_address_get(publish_address_handle, &publish_address_stored) == NRF_SUCCESS)
        {
            if((publish_address_stored.type == NRF_MESH_ADDRESS_TYPE_VIRTUAL)||(publish_address_stored.type != NRF_MESH_ADDRESS_TYPE_VIRTUAL && publish_address_stored.value != destination_address))
            {
                NRF_MESH_ASSERT(dsm_address_publish_remove(publish_address_handle) == NRF_SUCCESS);
                status = dsm_address_publish_add(destination_address, &publish_address_handle);
            }
            else
            {
                // use the retrieved publish_address_handle
            }
        }
        else
        {
            status = dsm_address_publish_remove(publish_address_handle);
            status = dsm_address_publish_add(destination_address, &publish_address_handle);
        }
    }

    switch(status)
    {
        case NRF_ERROR_NO_MEM:
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "NRF_ERROR_NO_MEM\n");
            return;
        case NRF_SUCCESS:
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "NRF_SUCCESS\n");
            break;
        default:
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Not defined ERROR\n");
            return;
    }
    NRF_MESH_ASSERT(access_model_publish_address_set(handle, publish_address_handle) == NRF_SUCCESS);  // change the address
}

However when i run this code:

oid uart_event_handle(app_uart_evt_t * p_event)
{
    static uint8_t data_array[20];
    //static uint8_t index = 0;
    uint32_t  err_code;
    generic_onoff_set_params_t set_params;
    model_transition_t transition_params;
    static uint8_t tid = 0;
    uint32_t status = NRF_SUCCESS;

    //__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "UART Event\n");

    switch(p_event->evt_type)
    {
        case APP_UART_DATA_READY:
            app_uart_get(&data_array[0]);
            //index++;
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "UART Data received: ------------- %x\n", data_array[0]);
            if(data_array[0] == 0x61)
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "0x61 pressed, blinking LEDs ------------- \n");
                change_publication_address(m_on_off_client.model_handle, 3);
                (void)access_model_reliable_cancel(m_on_off_client.model_handle);
                status = generic_onoff_client_set(&m_on_off_client, &set_params, &transition_params);
                hal_led_blink_ms(LEDS_MASK, LED_BLINK_SHORT_INTERVAL_MS, LED_BLINK_CNT_NO_REPLY);
            }
            break;


        case APP_UART_COMMUNICATION_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_code);
            break;
    
        default:
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Undifinded UART Handle state\n");
            break;
    }
}
It gets stuck.

On the RTT Viewer I see the messages "UART Data received: ------------- 61" (61 because I sent an 'a') , "0x61 pressed, blinking LEDs ------------- " and "Change Publication address".

I now expect the hal_led_blink_ms() to run on my LPN device (0003), but nothing happens.

When I try to send some other data, I receive nothing on the RTT Viewer and also no button events are triggered anymore.

The publication address is uint16_t, so it should be possible to set it to a fixed value, here 3, right?

I'm glad for any help.

Thanks

Parents
  • Hi BroccLee, 

    Please clarify: 

    1. Have you provisioned the light switch node to the mesh network ? 

    2. Have you established the friendship to the LPN node ? 

    I assume you have followed the documentation for the LPN here.

    You can check what the actual address sending out on access layer by adding a break point inside packet_tx() , look for the place where we print "TX:" in the function. You can find the destination address there. 

  • Hi Hung Bui,

    I have provisioned bot devices, bot devices have their publish and subscription adress to the group address C000. 

    I have not established a friendship to the lpn yet because it still acts a normal node inside this small mesh. I Forgot to mention, my Gateway is on the "FN Light1" node, the "LPN Button1" node is ist still a normal node which has the friendship functionality built in, but not activated.

    I did follow the instruction from that document.

    I also tried to send messages from the gateway to the address C000 with

    change_publication_address(m_on_off_client.model_handle, 0xC000);

    tgis did not work aswell. I am not sure weather this is the publication address i have to use to send messages to node, and in what format i need to write it in that function. Since it's a uint_16 format i belive there should be no " " around the 0xC000.

    Thank you

Reply
  • Hi Hung Bui,

    I have provisioned bot devices, bot devices have their publish and subscription adress to the group address C000. 

    I have not established a friendship to the lpn yet because it still acts a normal node inside this small mesh. I Forgot to mention, my Gateway is on the "FN Light1" node, the "LPN Button1" node is ist still a normal node which has the friendship functionality built in, but not activated.

    I did follow the instruction from that document.

    I also tried to send messages from the gateway to the address C000 with

    change_publication_address(m_on_off_client.model_handle, 0xC000);

    tgis did not work aswell. I am not sure weather this is the publication address i have to use to send messages to node, and in what format i need to write it in that function. Since it's a uint_16 format i belive there should be no " " around the 0xC000.

    Thank you

Children
Related