MQTT data_publish() in timer handler !!

Hi,

Using the "mqtt_simple" example I found that the data_publish () function does not work for a timer handler.

In the case of the example below, when the data_publish () function is called by the timer, a memory violation occurs and the system is reset.

How can I resolve this issue where the data_publish () function can be called by the timer?

Regards,
Neculai


s

static void button_handler(uint32_t button_states, uint32_t has_changed)
{
      if (has_changed & button_states &
          BIT(CONFIG_BUTTON_EVENT_BTN_NUM - 1)) {


      int ret;

      ret = data_publish(&client,                               // OK, Working well !
                        MQTT_QOS_1_AT_LEAST_ONCE,
                        CONFIG_BUTTON_EVENT_PUBLISH_MSG,
                        sizeof(CONFIG_BUTTON_EVENT_PUBLISH_MSG)-1);
      if (ret) {
                   LOG_ERR("Publish failed: %d", ret);
                }
      }
}


static void data_interval_timer_handler(struct k_timer *timer)
{
    ARG_UNUSED(timer);

    int ret;
    ret = data_publish(&client,                                         // Error !!, system violation !!
                        MQTT_QOS_1_AT_LEAST_ONCE,
                        CONFIG_BUTTON_EVENT_PUBLISH_MSG,
                        sizeof(CONFIG_BUTTON_EVENT_PUBLISH_MSG)-1);
    if (ret) {
                  LOG_ERR("Publish failed: %d", ret);
              }

}

in main() function
k_timer_start(&data_interval_timer,      // start timer, OK!
                K_MINUTES(1),
                K_MINUTES(1));

Parents Reply
  • Hi,

    I'm sorry, I had to specify that I don't use the data_publish () function simultaneously in the two interrupts: button and timer.

    I just wanted to show that in the button interrupt this function works correctly (as in the mqtt_simple example in the SDK).

    When I use this function in the timer interrupt it does not work and a system violation results.

    In this case, the following messages appear in my terminal:


    [00: 01: 10.208,160] <err> os: Exception occurred in Secure State

    [00: 01: 10.208,160] <err> os: ***** HARD FAULT *****

    [00: 01: 10.208,160] <err> os: Fault escalation (see below)

    [00: 01: 10.208,160] <err> os: ***** BUS FAULT *****

    [00: 01: 10.208,160] <err> os: Precise data bus error

    [00: 01: 10.208,190] <err> os: BFAR Address: 0x50008158

    Kind regards,

    Neculai

Children
Related