/*
Forum: https://forum.arduino.cc/t/esp32-esp-now-with-auto-pairing-loop-through-peer-list-help/1199296
Wokwi:https://wokwi.com/projects/383917653106828289
The following declarations and functions handle a mac address list
*/
#include "dummyESPFunctions.h"
constexpr int maxPeers {20};
uint8_t totalPeerList[maxPeers][6];
int noOfPeersInList = 0;
esp_now_peer_info_t slave;
void setup() {
Serial.begin(115200);
populateList();
printList();
}
void loop() {
}
void populateList() {
boolean from_head = true;
int count = 0;
while (esp_now_fetch_peer(from_head, &slave) == ESP_OK) {
from_head = false;
memcpy(totalPeerList[count],slave.peer_addr,6);
count++;
}
noOfPeersInList = count;
}
void printList() {
for (int i = 0; i<noOfPeersInList;i++){
Serial.printf("MAC ADRESS %2d: ",i+1);
printMAC(totalPeerList[i]);
Serial.println();
}
}
// ---------------------------- esp_ now -------------------------
void printMAC(const uint8_t * mac_addr){
char macStr[18];
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
for (int i=0;i<18;i++){
macStr[i] = toupper(macStr[i]);
}
Serial.print(macStr);
}