xreef / LoRa_E32_Series_Library

Arduino LoRa EBYTE E32 device library complete and tested with Arduino, esp8266, esp32, STM32 and Raspberry Pi Pico (rp2040 boards). sx1278/sx1276
https://www.mischianti.org
Other
357 stars 73 forks source link

Monitor node with multiple responses at the same time #61

Closed bpstermometria closed 7 months ago

bpstermometria commented 8 months ago

I have a hub node that sends a broadcast command to all nodes. It waits for responses to check whether all devices responded correctly, however, devices respond at the same time, and the ReceiveMessage method only captures the response from one device, discarding responses from all others. I would like to know what is the correct way to have a monitor node to handle multiple messages at the same time.

NOTE: The nodes are far from the monitor node.

NOTE: I didn't post the code because it's a simple example, I send a broadcast message to all devices, and all devices respond at the same time, but only the response from one device is processed.

NOTE 3: The host device is an ESP32.

xreef commented 8 months ago

Hi BPS, The monitor does not discard all others. It receives the message and puts It on the buffer. The buffer is 512 bytes, and the message size is 58, so It can receive 512/58 messages without reading the buffer. It's a best practice to read the buffer as soon as possible. Bye Renzo

bpstermometria commented 8 months ago

Hello, I don't understand how my code simply ignores the messages. I checked your library code and the command to clear the buffer is commented. However, my code only receives the response from one node. The two nodes are at the same distance and the message is less than 58k, the body of the message is a simple "ok". Below I leave my code to present my approach.

while (true)
    {
        while (_rf_driver.available() > 1)
        {
            _msg_count += 1;
#if DEBUG
            Serial.println("\n");
            Serial.println("[DEBUG]: **********************************************************");
            Serial.println("[DEBUG]:\t\t *** Message on the Broadcast monitor ***");
            Serial.print("[DEBUG]:\t\t Message number[");
            Serial.print(_msg_count);
            Serial.println("]");
#endif
            ResponseContainer rc = _rf_driver.receiveMessage();

            if (rc.status.code != 1)
            {
#if DEBUG
                Serial.print("[DEBUG]:\t\t Falha --> ");
                Serial.println(rc.status.getResponseDescription());
#endif
            }
            else
            {
#if DEBUG
                Serial.print("[DEBUG]:\t\t Dados --> ");
                Serial.println(rc.data);
#endif
            }
#if DEBUG
            Serial.println("[DEBUG]: **********************************************************");
            Serial.println("\n");
#endif
        }
        vTaskDelay(10);
    } 

Note: the code above is running in a separate Task, only with the while running

I am using the code below to send a command to all nodes at the same time, they receive it and return "ok"

 bool sendComand4All(String _cmd)
{
    ResponseStatus _response = _rf_driver.sendBroadcastFixedMessage(LORA_BROADCAST_CHANEL, _cmd);
    Serial.println(_response.getResponseDescription());
    if (_response.code == 1)
    {
        return true;
    }
    else
    {
        return false;
    }
} 
xreef commented 8 months ago

Try to use a delimiter and use receiveMessageUntil to do a check. Bye Renzo