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

Related