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

Mesh serial rx

Hello,

I have just started working with mesh and I'm using the 0.9.2 Mesh SDK. When I use the Serial interface (nrf_mesh_serial) I don't see any function about rx or rx callback. Is it true that Mesh doesn't support rx interface or I have to write it? If it supports, where can I find it?

Thank you very much

Parents
  • Hi Duy,

    The mesh serial interface does support rx. If not how would it take the commands from peer device (PC) :) ?

    UART data is processed in serial_uart.c in serial_uart_process() function.

    The documentation of serial interface can be found here.

    If you want to handle extra application command, when you declare nrf_mesh_serial_init() you can define the call back function that you will handle application command there. The opcode for application command should be in the range of SERIAL_OPCODE_CMD_RANGE_APP_START and SERIAL_OPCODE_CMD_RANGE_APP_END.

  • This is my main loop:

    void nrf_mesh_rx_cb(const uint8_t p_data, uint32_t length) { 
    	__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Rx received\r\n"); 
    }
    int main(void)
    {
    #if defined(NRF51) && defined(NRF_MESH_STACK_DEPTH)
        stack_depth_paint_stack();
    #endif
    
    
        __LOG_INIT(LOG_MSK_DEFAULT | LOG_SRC_ACCESS | LOG_SRC_SERIAL | LOG_SRC_APP, LOG_LEVEL_INFO, log_callback_rtt);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- Bluetooth Mesh Serial Interface Application -----\n");
    
        NRF_GPIO->DIRSET = 0xFFFFFFFF;
        NRF_GPIO->OUT    = LEDS_MASK;
    
        /* Flash leds at boot */
        for (int i = 0; i < 10; ++i)
        {
            NRF_GPIO->OUT ^= BSP_LED_0_MASK;
            nrf_delay_ms(100);
        }
    
        mesh_core_setup();
    
        /* Initialize dsm and access */
        dsm_init();
        access_init();
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Enabling ECDH offloading...\n");
        nrf_mesh_opt_t value = {.len = 4, .opt.val = 1 };
        ERROR_CHECK(nrf_mesh_opt_set(NRF_MESH_OPT_PROV_ECDH_OFFLOADING, &value));
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Enabling serial interface...\n");
        ERROR_CHECK(nrf_mesh_serial_init(nrf_mesh_rx_cb));
        ERROR_CHECK(nrf_mesh_serial_enable());
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initialization complete!\n");
        NRF_GPIO->OUTCLR = BSP_LED_0_MASK;
        uint32_t result;
        char hello[] = "\r\nHello from Nordic\r\n";
        result = nrf_mesh_serial_tx(hello, sizeof(hello));
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Send result hello: %d\r\n", result);
        while (true)
        {
            (void)nrf_mesh_process();
        }
    }
    

    It worked fine. I can see the Hello text on UART (115200 bps) If I send a application command (opcode start from 0x20) : 0x01 0x20 , I can see RX call back is triggered and text is printed out on RTT.

    Note that you need to use the format of the packet we have, first byte is length, next is opcode and then payload. The opcode have to be inside the application opcode range I mentioned above.

Reply
  • This is my main loop:

    void nrf_mesh_rx_cb(const uint8_t p_data, uint32_t length) { 
    	__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Rx received\r\n"); 
    }
    int main(void)
    {
    #if defined(NRF51) && defined(NRF_MESH_STACK_DEPTH)
        stack_depth_paint_stack();
    #endif
    
    
        __LOG_INIT(LOG_MSK_DEFAULT | LOG_SRC_ACCESS | LOG_SRC_SERIAL | LOG_SRC_APP, LOG_LEVEL_INFO, log_callback_rtt);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- Bluetooth Mesh Serial Interface Application -----\n");
    
        NRF_GPIO->DIRSET = 0xFFFFFFFF;
        NRF_GPIO->OUT    = LEDS_MASK;
    
        /* Flash leds at boot */
        for (int i = 0; i < 10; ++i)
        {
            NRF_GPIO->OUT ^= BSP_LED_0_MASK;
            nrf_delay_ms(100);
        }
    
        mesh_core_setup();
    
        /* Initialize dsm and access */
        dsm_init();
        access_init();
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Enabling ECDH offloading...\n");
        nrf_mesh_opt_t value = {.len = 4, .opt.val = 1 };
        ERROR_CHECK(nrf_mesh_opt_set(NRF_MESH_OPT_PROV_ECDH_OFFLOADING, &value));
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Enabling serial interface...\n");
        ERROR_CHECK(nrf_mesh_serial_init(nrf_mesh_rx_cb));
        ERROR_CHECK(nrf_mesh_serial_enable());
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initialization complete!\n");
        NRF_GPIO->OUTCLR = BSP_LED_0_MASK;
        uint32_t result;
        char hello[] = "\r\nHello from Nordic\r\n";
        result = nrf_mesh_serial_tx(hello, sizeof(hello));
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Send result hello: %d\r\n", result);
        while (true)
        {
            (void)nrf_mesh_process();
        }
    }
    

    It worked fine. I can see the Hello text on UART (115200 bps) If I send a application command (opcode start from 0x20) : 0x01 0x20 , I can see RX call back is triggered and text is printed out on RTT.

    Note that you need to use the format of the packet we have, first byte is length, next is opcode and then payload. The opcode have to be inside the application opcode range I mentioned above.

Children
Related