How to hold a task blocked waiting for incoming LoRa message?

Please, any idea for holding a task blocked waiting for incoming LoRa message?

I’m using two small TTGO T3 modules to share information with each other.

I’ve been thinking about using a Notification or even a queue or semaphore.

Is there somehow?

Thank you.
Regards

Please, has someone any idea?

Thank you.

Are you sure don’t want to just react whenever an incoming message arrives? Most LoRaWAN stacks are callback-oriented.

Also, without knowing anything about the used framework and library it’s hard to make recommendations.

No! I guess it should just react whenever an incoming message arrives.

How does it work?

I’m using EXP32 with Arduino Framework and FreeRTOS.

Thank you.
Regards

If you are using LoRa: Check the TTGO-LORA32/OLED_LoRa_Receive.ino at master · LilyGO/TTGO-LORA32 · GitHub example and explore LoRa.onReceive(cbk); via this example.

If you are using LoRaWAN (with e.g. an LNS like TTN): The Arduino-LMIC library is already callback oriented, as you can see in e.g. this example.

Thank you Max.

I’ve been trying the second link you’ve posted (arduino-LoRa/LoRaReceiverCallback.ino at master · sandeepmistry/arduino-LoRa · GitHub).

I found out the “cbk” is actually the call for an interruption. And, moreover, it forwards the package size in bytes. It has been very good for my application, in which I’ve got to run a quite big math procedure with the received message.

So, I call it from within a “setup” task running in Core 0:

LoRa.onReceive(LoRa_Recebe);

Then I implement the ISR calling a task that contains the math proceure, forwarding through a queue the size of the incoming message:

void LoRa_Recebe(int tamanho) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xQueueGenericSendFromISR(vQ_Recepcao, &tamanho, &xHigherPriorityTaskWoken, queueSEND_TO_BACK);
}

Then the task loads the exact number or bytes an handles all necessary processing, while the queue keeps available for receiving new packages sizes from the ISR.

void vT_Recepcao(void *pvParameters)
{
uint8_t tamanho = 0;
while (true)
{
if (xQueueGenericReceive(vQ_Recepcao, &tamanho, portMAX_DELAY, pdFALSE))
{
uint8_t buffer[tamanho];
uint8_t *pct_PTN;

  for (uint8_t i = 0; i < tamanho; i++)
  {
    buffer[i] = LoRa.read();
  }



}

Thank you.
Your tip has helped a lot.
Regards, Ciro