Passing Date Between Tasks

Hello Everybody,

How do to pass date and time between tasks? I am using Arduino IDE 2.3.5 and ESP32S2. Below ai part of the programming:

// Create an handle for the queue
QueueHandle_t tarikhQueue = NULL;
QueueHandle_t haribulanQueue = NULL;

void readRTC(void *pvParameters) 
{
  String Haribulan;
  char tarikh[10];
while(true)
  {DateTime now = myRTC.now();
    Haribulan = String(now.day()) + '/' + String(now.month()) +'/' +String(now.year());
    Haribulan.toCharArray(tarikh, 10);
xQueueSend(tarikhQueue, (void *)tarikh, portMAX_DELAY);

xQueueSend(haribulanQueue, &Haribulan, portMAX_DELAY);
    Serial.println(Haribulan);  // i get 21/7/2026
    Serial.println(tarikh);  // I get 21/7/2026
}
}
void display(void *pvParameters){
  String Haribulan;
  char tarikh[10];
while(true){
xQueueReceive(tarikhQueue, (void *)tarikh, portMAX_DELAY);
Serial.println(tarikh); // I get 1073510226
xQueueReceive(haribulanQueue, &Haribulan, portMAX_DELAY);
Serial.println(Haribulan); // I get 1073510226
}
void setup() {
tarikhQueue = xQueueCreate(QUEUE_SIZE, sizeof(char)*10); 
  haribulanQueue = xQueueCreate(QUEUE_SIZE, sizeof(String));  
  xTaskCreatePinnedToCore(
     display,
    "display",
    4096,
    NULL,
    1,
    NULL,
    ARDUINO_RUNNING_CORE
  );
  
  xTaskCreatePinnedToCore(
    readRTC,
    "readRTC",
    4096,
    NULL,
    1,
    NULL,
    ARDUINO_RUNNING_CORE
  );
}
  

The date is correct for sending the queue i.e. 21/7/2026 but after recieving it, I did not get the the date, I get 1073510226. Any suggestion?

I suspect that this is wrong. What is sizeof(String)?

String is probably a C++ class that isn’t “Plain ol’ Data”, and thus not suitable to send with a Queue, which uses the primitive C memcopy. Likely your misuse this way has corrupted the system and broken the proper sending via a char array.

Hi @RAc @richard-damon and he is waiting for two queue from one task, could you give me clarity on how the task will get unblocked based on those two queues?

Best regards

The code makes 2 sequential calls to xQueueReceive. The task will block on the first call and then on the next one.

Note that FreeRTOS does not support an equivalent to WaitForMultipleObjects(), so you can’t implement something like “wait for either of several queues” in a single call. If you wanted to approximate that, you would need to wait with timeout and use the timeouting case on the first queue to wait on the second, but that opens up a number of follow up issues to address.

FreeRTOS DOES have the concept of a “QueueSet”, which DOES allow you to wait for data to arrive on any of the queues that are part of the set, and it tells you which queue to read that data from.

This is somewhat like the WaitForMultipleObjects operation, just that the set of objects is fixed and they can’t be read from independently of that set relationship.

Thanks for the correction!