# Sending Struct

**URL:** <https://forums.freertos.org/t/sending-struct/18503>\
**Category:** Kernel\
**Created:** [November 14, 2023, 10:53am UTC](https://forums.freertos.org/t/sending-struct/18503 "2023-11-14T10:53:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kutaykivik](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kutaykivik](https://forums.freertos.org/u/kutaykivik)\
**Post date:** [November 14, 2023, 10:53am UTC](https://forums.freertos.org/t/sending-struct/18503/1 "2023-11-14T10:53:20Z")

</div>

I changed the demo project of FreeRTOS and i can get only first element of struct.

```auto
> void main_blinky( void )
> {
> 
> printf( "\r\nStarting the blinky demo. Press \'%c\' to reset the software timer used in this demo.\r\n\r\n", mainRESET_TIMER_KEY );
> 
> /* Create the queue. */
> xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( uint32_t ) );
> 
> if( xQueue != NULL )
> {
> /* Start the two tasks as described in the comments at the top of this
> file. */
> xTaskCreate( prvQueueReceiveTask,			
> "Rx", 							
> configMINIMAL_STACK_SIZE, 		
> NULL, 							
> mainQUEUE_RECEIVE_TASK_PRIORITY,
> NULL );							
> 
> xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );
> 
> 		
> 
> 
> vTaskStartScheduler();
> }
> 
> for( ;; );
> }
> /-----------------------------------------------------------/
> 
> typedef struct {
> int initialPosition[2]; // x and y coordinates
> int velocity[2]; // V_x and V_y components
> float gaussianNoise[2]; // O_x and O_y components
> } Measurments;
> 
> static void prvQueueSendTask( void *pvParameters )
> {
> TickType_t xNextWakeTime;
> const TickType_t xBlockTime = mainTASK_SEND_FREQUENCY_MS;
> 
> Measurments data;
> 
> ( void ) pvParameters;
> 
> xNextWakeTime = xTaskGetTickCount();
> 
> 
> for( ;; )
> {
> 
> data.initialPosition[0] = 10; // Example: x coordinate
> data.initialPosition[1] = 30; // Example: y coordinate
> data.velocity[0] = 5; // Example: V_x
> data.velocity[1] = 2; // Example: V_y
> data.gaussianNoise[0] = 0.1f; // Example: O_x
> data.gaussianNoise[1] = 0.2f; // Example: O_y
> 
> vTaskDelayUntil( &xNextWakeTime, xBlockTime );
> 
> 
> xQueueSend( xQueue, &data, 0U );
> 
> }
> }
> 
> 
> static void prvQueueReceiveTask( void *pvParameters )
> {
> uint32_t ulReceivedValue;
> 
> Measurments receivedData;
> 
> ( void ) pvParameters;
> 
> for( ;; )
> {
> xQueueReceive( xQueue, &receivedData, portMAX_DELAY );
> 
> taskENTER_CRITICAL();
> {
> 
>                  
> printf("Received Data:\r\n");
> printf("Initial Position: x=%d, y=%d\r\n", receivedData.initialPosition[0], receivedData.initialPosition[1]);
> printf("Velocity: V_x=%d, V_y=%d\r\n", receivedData.velocity[0], receivedData.velocity[1]);
> printf("Gaussian Noise: O_x=%f, O_y=%f\r\n", receivedData.gaussianNoise[0], receivedData.gaussianNoise[1]);
>             
>             
> 
> }
> taskEXIT_CRITICAL();
> }
> }

```

Output:

> Received Data:  
> Initial Position: x=10, y=-858993460  
> Velocity: V\_x=-858993460, V\_y=-858993460  
> Gaussian Noise: O\_x=-107374176.000000, O\_y=-107374176.000000

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [November 14, 2023, 11:09am UTC](https://forums.freertos.org/t/sending-struct/18503/2 "2023-11-14T11:09:08Z")

</div>

> [@kutaykivik](#):
>
> `xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( uint32_t ) );`

This line is the problem. You need to tell the size of each item at the time of queue creation -

```auto
xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( Measurments) );

```

See the detailed documentation here - [FreeRTOS - FreeRTOS queue API functions, including source code functions to create queues, send messages on queues, receive messages on queues, peek queues, use queues in interrupts.](https://www.freertos.org/a00018.html).
