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

DFU project

I try to create coap server project and it should by  updateable by DFU. I merge project simple coap server and thread dfu client, and I keep  instructions in documentation to build it and run DFU. But Server doesnt response to coap requests and when I start multicast DFU process server is not updated. and when I try to start unicast DFU it waiting to promote a router. 

  • We wanna use it for thousands devices an update firmware without DFU will not possible. 

  • If I understand it, I should use coap library which is used in DFU project? 

  • Hi Fran,

    That's the buildt-in OpenThread coap library, the external coap library (the one used by the thread DFU client) is this one: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.iotsdk.v0.9.0%2Flib_iot_coap.html

  • I use nRF5_SDK_for_Thread_and_Zigbee_v3.2.0_9fade31

    I try example to DFU thread client and I add turn on LED. DFU was sucessfull. Next I add CoAP resources to code and it not start.

    This is terminal output:

    D:\IS\nRF5_SDK_for_Thread_and_Zigbee_v3.2.0_9fade31\examples\thread\dfu>nrfutil dfu thread -f -pkg app_dfu_package.zip -p COM12 --channel 11 --panid 43981
    Address not specified. Using ff03::1 (all Thread nodes)
    Using connectivity board at serial port: COM12
    Flashing connectivity firmware...
    Connectivity firmware flashed.
    Waiting for NCP to promote to a router...
    Thread DFU server is running... Press <Ctrl + D> to stop.

    edited file: coap_dfu.c

    added code:

    #define MY_APP_RESOURCE_HELLO "hello"
    coap_resource_t coap_resource_hello;
    
    #define MY_APP_RESOURCE_READ "read"
    coap_resource_t coap_resource_read;
    
    #define MY_APP_RESOURCE_WRITE "write"
    coap_resource_t coap_resource_write;
    
    static void hello_request_callback(coap_resource_t * p_resource, coap_message_t * p_request)
    {
    NRF_LOG_INFO("Hello packet");
    
    coap_message_t * p_response = NULL;
    
    if (!is_addr_multicast(&p_request->local))
    {
    p_response = empty_reset_response_create(p_request);
    }
    
    // Send response, if created.
    if (p_response != NULL)
    {
    coap_dfu_message_send(p_response);
    }
    
    }
    
    static void read_request_callback(coap_resource_t * p_resource, coap_message_t * p_request)
    {
    NRF_LOG_INFO("Read packet");
    
    coap_message_t * p_response = NULL;
    
    if (!is_addr_multicast(&p_request->local))
    {
    p_response = empty_reset_response_create(p_request);
    }
    
    // Send response, if created.
    if (p_response != NULL)
    {
    coap_dfu_message_send(p_response);
    }
    
    }
    
    static void write_request_callback(coap_resource_t * p_resource, coap_message_t * p_request)
    {
    NRF_LOG_INFO("Write packet");
    
    coap_message_t * p_response = NULL;
    
    if (!is_addr_multicast(&p_request->local))
    {
    p_response = empty_reset_response_create(p_request);
    }
    
    // Send response, if created.
    if (p_response != NULL)
    {
    coap_dfu_message_send(p_response);
    }
    
    }
    
    
    static uint32_t MyAppCoapResource_init()
    {
        uint32_t err_code = NRF_SUCCESS;
        
        do
        {
            err_code = coap_resource_create(&coap_resource_hello, MY_APP_RESOURCE_HELLO);
            err_code = coap_resource_create(&coap_resource_read, MY_APP_RESOURCE_READ);
            err_code = coap_resource_create(&coap_resource_write, MY_APP_RESOURCE_WRITE);
            if (err_code != NRF_SUCCESS)
            {
                break;
            }
    
            coap_resource_hello.permission = (COAP_PERM_POST | COAP_PERM_GET);
            coap_resource_hello.callback = hello_request_callback;
    
            coap_resource_read.permission = (COAP_PERM_POST | COAP_PERM_GET);
            coap_resource_read.callback = read_request_callback;
    
            coap_resource_write.permission = (COAP_PERM_POST | COAP_PERM_GET);
            coap_resource_write.callback = write_request_callback;
    
            NRF_LOG_INFO("Endpoints initialized");
    
        } while (0);
    
        return err_code;
    }
    
    //upgrade this existing function
    
    uint32_t coap_dfu_init(const void * p_context)
    {
        uint32_t err_code;
    
        do
        {
            memset(&m_coap_dfu_ctx, 0 , sizeof(m_coap_dfu_ctx));
    
            err_code = coap_protocol_init(p_context);
            if (err_code != NRF_SUCCESS)
            {
                break;
            }
    
            err_code = MyAppCoapResource_init();
            if (err_code != NRF_SUCCESS)
            {
                break;
            }
    
            err_code = endpoints_init(&m_coap_dfu_ctx);
            if (err_code != NRF_SUCCESS)
            {
                break;
            }
    
            nrf_dfu_settings_init(false);
            nrf_dfu_req_handler_init(dfu_observer);
    
            background_dfu_state_init(&m_dfu_ctx);
    
            app_timer_create(&m_send_timer, APP_TIMER_MODE_SINGLE_SHOT, delayed_send_handler);
            app_timer_create(&m_reset_timer, APP_TIMER_MODE_SINGLE_SHOT, delayed_reset_handler);
            app_timer_create(&m_coap_delayed_error_handling_timer, APP_TIMER_MODE_SINGLE_SHOT, coap_delayed_error_handler);
    
            APP_SCHED_INIT(SCHED_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);
        } while (0);
    
        return err_code;
    }
    

Related