# xQueueReceive(..., &..., ...) with empty return

**URL:** <https://forums.freertos.org/t/xqueuereceive-with-empty-return/12560>\
**Category:** Kernel\
**Tags:** debug\
**Created:** [May 12, 2021, 5:49pm UTC](https://forums.freertos.org/t/xqueuereceive-with-empty-return/12560 "2021-05-12T17:49:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulloCapel](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@PaulloCapel](https://forums.freertos.org/u/PaulloCapel)\
**Post date:** [May 12, 2021, 5:49pm UTC](https://forums.freertos.org/t/xqueuereceive-with-empty-return/12560/1 "2021-05-12T17:49:26Z")

</div>

Hii everyone

I need help with xQueueReceice, my problem is that xQueueReceice return an value empty.

my code

> struct xDataMensagem  
> {  
> String xData;  
> }xMensagem;
> 
> void xTaskRecives(void \* pvParameters){  
> String myData = “02,1234.567”;  
> while (true){  
> xMensagem.xData = myData;  
> if (xQueueSend(xDataQueue,(void \* ) & xMensagem,portMAX\_DELAY)){  
> Serial.println(“enviado”);  
> }  
> vTaskDelay(pdMS\_TO\_TICKS(5000));  
> }  
> }  
> void xTaskTreadsData(void \* pvParameters){  
> String myString = “”;  
> struct xDataMensagem xMensagem\_;  
> while (true){  
> if (xDataQueue != NULL){  
> **if (xQueueReceive(xDataQueue, &xMensagem\_, portMAX\_DELAY))  
> {  
> \*\* myString = xMensagem\_.xData;  
> Serial.println(myString); //print data recived  
> xMensagem\_.xData = “”; // clear flag  
> }**  
> }  
> vTaskDelay(pdMS\_TO\_TICKS(10));  
> }

the function that is failing is in bold  
But the value of returned of xQueueReceive is empty, why??  
the variable xMensagem\_ wouldn’t it be a copy of the one sent?

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [May 12, 2021, 5:58pm UTC](https://forums.freertos.org/t/xqueuereceive-with-empty-return/12560/2 "2021-05-12T17:58:58Z")

</div>

Could you please add the code snipped where you `xQueueCreate` the queue ?

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [May 12, 2021, 6:00pm UTC](https://forums.freertos.org/t/xqueuereceive-with-empty-return/12560/3 "2021-05-12T18:00:15Z")

</div>

If String is a class, it might not be suitable to send via a queue. Queues only handle POD info, nothing that needs a C++ constructor.

---

<div class="post-metadata">

**Author:** ![PaulloCapel](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@PaulloCapel](https://forums.freertos.org/u/PaulloCapel)\
**Post date:** [May 12, 2021, 6:36pm UTC](https://forums.freertos.org/t/xqueuereceive-with-empty-return/12560/4 "2021-05-12T18:36:39Z")

</div>

> xDataQueue = xQueueCreate(32,sizeof( & xMensagem));

---

<div class="post-metadata">

**Author:** ![PaulloCapel](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@PaulloCapel](https://forums.freertos.org/u/PaulloCapel)\
**Post date:** [May 12, 2021, 6:37pm UTC](https://forums.freertos.org/t/xqueuereceive-with-empty-return/12560/5 "2021-05-12T18:37:27Z")

</div>

i will send String value …

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [May 12, 2021, 6:41pm UTC](https://forums.freertos.org/t/xqueuereceive-with-empty-return/12560/6 "2021-05-12T18:41:36Z")

</div>

> [@PaulloCapel](#):
>
> xDataQueue = xQueueCreate(32,sizeof( & xMensagem));

creates a queue of POINTERS to `xMensagem`. This can be used to send messages _by reference / pointer_. If you want to send messages _by value_ (as supposed by your [xQueueSend](https://www.freertos.org/a00117.html)/[xQueueReceive](https://www.freertos.org/a00118.html) calls) use `sizeof( xMensagem )` and ensure that `xMensagem` is a POD type as Richard mentioned. Maybe reread the API docs (see the links) for further details.

---

<div class="post-metadata">

**Author:** ![PaulloCapel](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@PaulloCapel](https://forums.freertos.org/u/PaulloCapel)\
**Post date:** [May 13, 2021, 6:13pm UTC](https://forums.freertos.org/t/xqueuereceive-with-empty-return/12560/7 "2021-05-13T18:13:43Z")

</div>

what is the best way to send a string?  
what is PDO, I’m starting now with freeRTOS

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [May 13, 2021, 6:28pm UTC](https://forums.freertos.org/t/xqueuereceive-with-empty-return/12560/8 "2021-05-13T18:28:09Z")

</div>

POD is ‘Plain ole Data’, I.e structures that basically act like in C. Nothing happening in things like constructors.

To send things that are more active, you need to send them via pointers, so the objects aren’t miscopied.

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [May 13, 2021, 6:53pm UTC](https://forums.freertos.org/t/xqueuereceive-with-empty-return/12560/9 "2021-05-13T18:53:59Z")

</div>

You could use a simple char buffer to transfer strings. At least to start with.

```auto
struct xDataMensagem
{
    char xData[32];
}xMensagem;

```

and use e.g. `snprintf` to create the desired text.
