cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS Code issue Data Sending on the server

Kai_Satone
Associate III

Hello 

I am working on the Free RTOS code that I am trying to send the data on the server using Free RTOS but I am not able to send data on the server I am using some dummy data and GPS for location +STM32F411ceu6a+EC200U GNSS. But my RTOS task is not working can some one plz help me find the problem in my code.

CODE:-

// Globals
QueueHandle_t xQueue;
SemaphoreHandle_t xBinarySemaphore;

typedef struct {
    float Latitude;
    float Longitude;
    float objectTemp;
    float ambientTemp;
    float xG;
    float yG;
    float zG;
    float avg;
} GPSData_t;


/* Definitions for ec200u6 */
osThreadId_t ec200u6Handle;
const osThreadAttr_t ec200u6_attributes = {
  .name = "ec200u6",
  .stack_size = 128* 4,
  .priority = (osPriority_t) osPriorityRealtime,
};
/* Definitions for L89 */
osThreadId_t L89Handle;
const osThreadAttr_t L89_attributes = {
  .name = "L89",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityRealtime,
};
/* Definitions for myQueue01 */
osMessageQueueId_t myQueue01Handle;
const osMessageQueueAttr_t myQueue01_attributes = {
  .name = "myQueue01"
};
/* Definitions for myMutex01 */
osMutexId_t myMutex01Handle;
const osMutexAttr_t myMutex01_attributes = {
  .name = "myMutex01"
};
/* Definitions for myBinarySem01 */
osSemaphoreId_t myBinarySem01Handle;
const osSemaphoreAttr_t myBinarySem01_attributes = {
  .name = "myBinarySem01"
};


void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_ADC1_Init(void);
static void MX_I2C1_Init(void);
static void MX_SPI1_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_USART6_UART_Init(void);
void Startec200u6(void *argument);
void StartL89(void *argument);


   // Create the queue
     xQueue = xQueueCreate(10, sizeof(GPSData_t)); // Adjust the size as needed

     // Create the binary semaphore
     xBinarySemaphore = xSemaphoreCreateBinary();

     if (xQueue != NULL && xBinarySemaphore != NULL)
     {
         // Create the tasks
         xTaskCreate(Startec200u6, "Task2", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
         xTaskCreate(StartL89, "Task1", configMINIMAL_STACK_SIZE, NULL, 1, NULL);

         // Start the scheduler
         vTaskStartScheduler();
     }

  /* USER CODE END 2 */

  /* Init scheduler */
  osKernelInitialize();
  /* Create the mutex(es) */
  /* creation of myMutex01 */
  myMutex01Handle = osMutexNew(&myMutex01_attributes);

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* Create the semaphores(s) */
  /* creation of myBinarySem01 */
  myBinarySem01Handle = osSemaphoreNew(1, 1, &myBinarySem01_attributes);

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the queue(s) */
  /* creation of myQueue01 */
  myQueue01Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue01_attributes);

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* creation of ec200u6 */
  ec200u6Handle = osThreadNew(Startec200u6, NULL, &ec200u6_attributes);

  /* creation of L89 */
  L89Handle = osThreadNew(StartL89, NULL, &L89_attributes);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* USER CODE BEGIN RTOS_EVENTS */
  /* add events, ... */
  /* USER CODE END RTOS_EVENTS */
  vTaskStartScheduler();
  /* Start scheduler */
//  osKernelStart();


void Startec200u6(void *pvParameters)
{
    /* USER CODE BEGIN 5 */
    /* Infinite loop */
    GPSData_t receivedData;
    int retryCount;
    const int maxRetries = 2;

    for (;;) // Infinite loop for the task
    {
        if (xSemaphoreTake(xBinarySemaphore, portMAX_DELAY) == pdTRUE)
        {
            if (xQueueReceive(xQueue, &receivedData, portMAX_DELAY) == pdPASS)
            {
                // Retry sending data up to maxRetries times
                retryCount = 0;
                while (!sendHTTP(receivedData.Latitude, receivedData.Longitude,
                                 receivedData.objectTemp, receivedData.ambientTemp,
                                 receivedData.xG, receivedData.yG, receivedData.zG,
                                 receivedData.avg))
                {
                    vTaskDelay(pdMS_TO_TICKS(2000)); // Delay for 2000 ms
                    if (retryCount < maxRetries)
                    {
                        retryCount++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }
    /* USER CODE END 5 */
}

void StartL89(void *pvParameters)
{
    /* USER CODE BEGIN StartL89 */
    GPSData_t gpsData;

    for (;;) // Infinite loop for the task
    {
        // Receive data from UART
        HAL_UART_Receive(&huart2, (uint8_t *)Rxdata, 700, 5000);

        // Get location data
        get_location(&gpsData.Latitude, &gpsData.Longitude, 0);

        // Populate other sensor data
        gpsData.objectTemp = 25.0; // Predefined value for object temperature
              gpsData.ambientTemp = 24.0; // Predefined value for ambient temperature
              gpsData.xG = 0.1; // Predefined value for X-axis acceleration
              gpsData.yG = 0.2; // Predefined value for Y-axis acceleration
              gpsData.zG = 0.3; // Predefined value for Z-axis acceleration
              gpsData.avg = (gpsData.xG + gpsData.yG + gpsData.zG) / 3.0; // Calculate average
        // Toggle the pin to indicate data reception
        L89_TogglePin(2, 3);

        // Attempt to send the data to the queue
        if (xQueueSend(xQueue, &gpsData, portMAX_DELAY) != pdPASS)
        {
            // Handle queue send error
        }
        else
        {
            // Data was successfully queued, give the semaphore
            xSemaphoreGive(xBinarySemaphore);
        }
    }
    /* USER CODE END StartL89 */
}

 

0 REPLIES 0