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

nRF51: Extending the IoT-MQTT example

Hello,

I need a little help regarding IoT-SDK 0.8.0 on nRF51. In the MQTT-Example connection to the broker is established only when I press the button (callback), but not when I call mqtt_connect() directly with same set of parameters after recognizing IPV6_UP (absuing m_display_state for that, because I still need some time to get familiar with the firmware).

Can anyone help me with this?

if(false == m_connection_state)
{
  if(LEDS_IPV6_IF_UP == m_display_state)
  {
    mqtt_connect_t param;
                
    param.broker_addr    = m_broker_addr;
    param.broker_port    = APP_MQTT_BROKER_PORT;
    param.evt_cb         = app_mqtt_evt_handler;
    param.device_id      = m_device_id;
    param.p_password     = NULL;
    param.p_user_name    = NULL;

    UNUSED_VARIABLE(mqtt_connect(&m_app_mqtt_id, &param));
  }
}

Thank you very much in advance!

Regards

Parents
  • Today I tried the timer of SDK 8.1.0.

    I tried to implement the timer from the example:

    nrf_drv_config.h:

    #define TIMER1_ENABLED 1 
    

    Timer0 seems to be not available when a Softdevice is present.

    main.c:

    const nrf_drv_timer_t MYTIM = NRF_DRV_TIMER_INSTANCE(1);
    ...
    
    err_code = nrf_drv_timer_init(&MYTIM, NULL, mytim_event_handler);
    time_ticks = nrf_drv_timer_ms_to_ticks(&MYTIM, 2000);
    nrf_drv_timer_extended_compare(&MYTIM, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
    nrf_drv_timer_enable(&MYTIM);
    

    The callback function:

    void mytim_event_handler(nrf_timer_event_t event_type, void* p_context)
    {
    
          
        switch(event_type)
        {
            case NRF_TIMER_EVENT_COMPARE0:
            {
              __asm("nop");
            }
            break;
           
            default:
            break;
        }    
    }
    

    I expected, that the event NRF_TIMER_EVENT_COMPARE0 is triggered every 2 seconds (2000 ms). Unfortunately, it is called almost instantaneous after starting the program without the delay. Same result when I activate the breakpoint during running execution of the program. I also tried Timer2 instead of Timer1 with the same result.

    Can you help me?

    Regards

Reply
  • Today I tried the timer of SDK 8.1.0.

    I tried to implement the timer from the example:

    nrf_drv_config.h:

    #define TIMER1_ENABLED 1 
    

    Timer0 seems to be not available when a Softdevice is present.

    main.c:

    const nrf_drv_timer_t MYTIM = NRF_DRV_TIMER_INSTANCE(1);
    ...
    
    err_code = nrf_drv_timer_init(&MYTIM, NULL, mytim_event_handler);
    time_ticks = nrf_drv_timer_ms_to_ticks(&MYTIM, 2000);
    nrf_drv_timer_extended_compare(&MYTIM, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
    nrf_drv_timer_enable(&MYTIM);
    

    The callback function:

    void mytim_event_handler(nrf_timer_event_t event_type, void* p_context)
    {
    
          
        switch(event_type)
        {
            case NRF_TIMER_EVENT_COMPARE0:
            {
              __asm("nop");
            }
            break;
           
            default:
            break;
        }    
    }
    

    I expected, that the event NRF_TIMER_EVENT_COMPARE0 is triggered every 2 seconds (2000 ms). Unfortunately, it is called almost instantaneous after starting the program without the delay. Same result when I activate the breakpoint during running execution of the program. I also tried Timer2 instead of Timer1 with the same result.

    Can you help me?

    Regards

Children
Related