This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

mqtt simple + timer collision

Dear Sir.

We are using software based on mqtt simple project .

We added a 1 hz timer, Every 1 hz we toggle a led on and off.

Sometime the led is stuck on " on " or " off  which means to me that the timer is not 

working fine or the mqtt routine in the background stops it.

Any idea how to debug this problem.

Please Advise.

  • Hi Ephraim,

    My guess is that this is due to scheduling.

    Could you post the code and configuration you use for the timer?

    Regards,
    Sigurd Hellesvik

  • Hi.

    In main.c  configure timer

    k_timer_init(&my_timer, my_expiry_function, NULL); //Timer - 1 Hz
    k_timer_start(&my_timer, K_MSEC(TIEMR_INTERVAL_SEC), K_SECONDS(TIEMR_INTERVAL_SEC)); //Timer - 1 Hz

    void my_expiry_function(struct k_timer *timer_id)
    {
    k_work_submit(&work_top);
    }

    The code of mqtt is the same as in the project mqtt simple , turning on and off the mqtt

    by issuing the commands   lte_lc_offline(); and lte_lc_normal();

    Every time the the modem reconnect there is a delay in the timer ( see pic ). Sometimes the timer is stopped.

    Please Advise.

  • Hi.

    Another input.

    I have found the following is responsible for the timer's mismatch

    if((get_mqtt_conn_flag() == 1)) { // && (gtimer > 50)) {
    printk("Try to connect - 1, %d \n",gtimer);
    lte_lc_offline();
    set_mqtt_conn_flag(3);
    } else if (get_mqtt_conn_flag() == 2) {
    printk("Try to connect - 2, %d \n",gtimer);
    lte_lc_normal();
    battery_value = get_battery_value();
    set_latest_valid_battery_value(battery_value);
    set_mqtt_conn_flag(3);
    }

    It is either the lte_lc_offline(); or the lte_lc_normal(); 

    Please Advise

  • Hi

    If you se LOG_INF to log inside "my_expiry_function()", you should get prints with timestamps.
    Then log inside the work done by "work_top".

    This will help us find if the delay is in the timer or the work queue.

    Regards,
    Sigurd Hellesvik

Related