LowPowerLab Forum

Hardware support => Moteino => Topic started by: rr_rr on December 16, 2022, 05:11:35 PM

Title: Multiple nodes in network, receive from wrong node
Post by: rr_rr on December 16, 2022, 05:11:35 PM
I'm struggling with trying to run multiple nodes at once, using RadioHead library.  I'm using the unpatched v1.121 from the RH website.  The client nodes seem to talk over each other.
-  I have one server and multiple clients
-  All nodes are MoteinoMega with RF95 RF modules
-  Clients only initiate messages to the Server
-  Clients transmit their packets to Server every number of seconds.
-  Intermittently, I notice that the clients will receive data from other clients.  It shows up while looking for a reply using 'recvfromAckTimeout'
-  The code I'm using for send/receive is from the examples, slightly modified.  I've had it running successfully for a long time.
-  I'm using the RHReliableDatagram for the RF manager on client and server. 
#include <RHReliableDatagram.h>

I had assumed that sendToWait and/or recvfromAckTimeout would automatically sort out the who to/from for the transmission, or maybe have some method to keep from talking over each other; but it doesn't appear that this is the case.  Instead I just get data from the wrong node

Has anyone else seen this issue?  How could a mesh network be made if the to/from is not reliable this way?  Or, maybe someone has a better ideas about how to do this.
I hope this is the appropriate forum; or if someone knows of one for the RadioHead library specifically, can you point me there?

Thank you!


For instance, I have gateway as 0x00
Nodes are addresses 0x01 and 0x02
Both 0x01 and 0x02 sleep and wake after a few seconds, then transmit to 0x00.
Say, node 0x01 sends to 0x00.  USUALLY that goes through just fine.  Occasionally, it receives from 0x02:

QuoteRX from: 0x2
  === wrong address ===


Client:

if (rf_manager->sendtoWait(buf_tx, strlen((char *)buf_tx), to_addr))
{
    Serial.println(F("Packet sent"));

    // Now wait for a reply
    uint8_t from;
    uint8_t len = RH_RF95_MAX_MESSAGE_LEN; // sizeof(buf_rx);

    if (rf_manager->recvfromAckTimeout(buf_rx, &len, 2500, &from))
    {
      Serial.print(F("RX from: 0x"));
      Serial.print(from, HEX);

      if (from != to_addr)
      {
        Serial.println(F("=== wrong address ==="));
      }
    }
}



Server:

if (manager.available())
{
    // Wait for a message addressed to us from the client
    uint8_t len = sizeof(buf_rf);
    uint8_t from;
    buf_rf[0] = 0; // clear buf

    if (manager.recvfromAck(buf_rf, &len, &from))
    {
      Serial.println(F("RX:"));
      Serial.println((char *)buf_rf);
      Serial.print(F(" From: 0x"));
      Serial.println(from, HEX);
      Serial.print(F(" RSSI: "));
      Serial.println(rf95_driver.lastRssi(), DEC);
    }
}