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

Hii everyone

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

my code

struct xDataMensagem
String xData;

void xTaskRecives(void * pvParameters){
String myData = “02,1234.567”;
while (true){
xMensagem.xData = myData;
if (xQueueSend(xDataQueue,(void * ) & xMensagem,portMAX_DELAY)){
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


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?

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

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.

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

i will send String value …

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/xQueueReceive 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.

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

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.

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

struct xDataMensagem
    char xData[32];

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