Check for all nodes within range

Started by Asterlux, September 30, 2021, 02:51:56 PM

Asterlux

Hi all, I'm brand new to this but I'm working on a project and am wondering if it's possible for one moteino to ping into the void and see what other moteinos are in range on the same network. In my project, some moteinos could be off at certain times and basically it's a very dynamic network.

Is that what the spy function would be used for? I would want whatever moteinos are active to be aware of all the other currently active moteinos

Thanks

Felix

Easy, for the pinger you would just send a broadcast message, ie to target node ID=1023. Then any other listening (ie RX mode - do this with receiveDone() or setMode(RX)) would receive that packet, and optionally respond with an ACK if you use sendWithRetry().
For receivers, you can also use spy_mode so that a listening receiver can receive packets intended for different targets.

Asterlux

Thanks!

If there are a bunch of moteinos responding to the broadcast, would the broadcaster be able to process all the ACKs? Like do they all get buffered, or would they overwrite each other?

Basically, would the pinger need to send multiple broadcasts until it was sure it processed all the returns or would one broadcast be sufficient? (assuming like 12 moteinos are active)

Also, how do you know who sent the ACK?

Felix

Its more or less like a conversation. You can only receive 1 packet (word) at 1 time. If multiple nodes talk at the exact same instance then you understand nothing. There is a basic listen-before-speak mechanism, but in the case of a broadcast, all the receivers would obviously receive at the same instant, then listen for activity at the same instant when nobody else is talking and think its all clear to speak, then all send and the next same instant, which would then all collide. So you would want to implement some basic delay (maybe based on ID) or worst case a random delay before attempting to respond.

All sent packats have a sender-id field, thats how you know what node a packet came from.

Asterlux

Does sendwithRetry work for broadcast messages? I vaguely remember reading another forum post that seemed to suggest ACKs were not sent for messages received from the broadcast address

Felix

Here is that code:

bool RFM69::sendWithRetry(uint16_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t retries, uint8_t retryWaitTime) {
  uint32_t sentTime;
  for (uint8_t i = 0; i <= retries; i++)
  {
    send(toAddress, buffer, bufferSize, true);
    sentTime = millis();
    while (millis() - sentTime < retryWaitTime)
    {
      if (ACKReceived(toAddress)) return true;
    }
  }
  return false;
}

// should be polled immediately after sending a packet with ACK request
bool RFM69::ACKReceived(uint16_t fromNodeID) {
  if (receiveDone())
    return (SENDERID == fromNodeID || fromNodeID == RF69_BROADCAST_ADDR) && ACK_RECEIVED;
  return false;
}