Skip to main content
Visitor II
December 4, 2021
Question

Problem Sending MQTT messages using FreeRTOS

  • December 4, 2021
  • 0 replies
  • 544 views

Hello,

I have an FreeRTOS task that sends 4 MQTT messages (using LwIP MQTT) every 10 seconds:

void HomeAssistantConfigTask(void *argument)
{
 /* USER CODE BEGIN HomeAssistantConfigTask */
 /* Infinite loop */
 for(;;)
 {
 
 SendAvailabilityMessage();
 SendPowerConfigMessage();
 SendDisplayConfigMessage();
 SendFrontLedConfigMessage();
 osDelay(10000);
 
 }
 
 osThreadTerminate(NULL);
 
 /* USER CODE END HomeAssistantConfigTask */
}

But most of the times the last 2 messages are not sent... Seems like the thread is being interrupted before sending the message. I also tried to add osDelay between sending messages and I have same problem.

I have in total 4 FreeRTOS tasks and this one is configured like this:

osThreadId_t HMConfigTaskHandle;
const osThreadAttr_t HMConfigTask_attributes = {
 .name = "HMConfigTask",
 .stack_size = 4096 * 4,
 .priority = (osPriority_t) osPriorityAboveNormal2,
};

The other tasks are running every 100ms and every 5s.

I'm using STM32F407VGT with FreeRTOS using CMSIS_V2.

Thanks for reading.

    This topic has been closed for replies.