I am playing around with a sketch to use an ESP32 (main/sender board) to auto-pair with all the ESP32 (receiver) boards in the area.
- When I try to look up the official espressif.com docs.. the syntax is still a bit overwhelming for me.. so I am not clear on how to actually 'execute' some of these functions/methods I see.
(all the & and * and _t stuff.. still throws me off) - enlightenment in that area would also be nice/helpful!
Anywho...
Looking for some help to loop through the 'peer' list after all auto-paring is complete.
I have the auto-pairing done..and I do get the (updated) total number of peers after each auto-pair completion.. but I am not clear on how to access/display the mac addresses saved in this peer list?
I'm basically just stuck at the loop now?
//esp 'peer' info
esp_now_peer_info_t slave;
bool addPeer(const uint8_t *peer_addr) { // add pairing
memset(&slave, 0, sizeof(slave));
const esp_now_peer_info_t *peer = &slave;
memcpy(slave.peer_addr, peer_addr, 6);
slave.channel = chan; // pick a channel
slave.encrypt = 0; // no encryption
// check if the peer exists
bool exists = esp_now_is_peer_exist(slave.peer_addr);
if (exists) {
// Slave already paired.
Serial.println("Already Paired");
return true;
}else{
esp_err_t addStatus = esp_now_add_peer(peer);
if (addStatus == ESP_OK) {
// Pair success
Serial.println("Pair success");
//esp_err_t currentPeerCount = esp_now_peer_num.total_num;
esp_now_peer_num_t pn;
esp_now_get_peer_num(&pn);
Serial.print("Total Peer Count: ");
Serial.println(pn.total_num);
Serial.print("MAC Address Added To List: ");
printMAC(peer_addr);
Serial.println("");
//output peer list
Serial.print("Current Peer List: ");
Serial.println("");
if((pn.total_num) > 0){
for(i=0; i < pn.total_num; i++){
//Serial.println("");
Serial.print("MAC ADDRESS ");
Serial.print(i);
Serial.print(": ");
Serial.println(slave.peer_addr[i]);
//Serial.println(peer.peer_addr[i]);
//Serial.println("");
}
}
}
}
}
but my current out put is -not- mac addresses?
Current Peer List:
MAC ADDRESS 0: 8
MAC ADDRESS 1: 209
I tried to use peer vs slave.. (but it threw an error?)
Wrong array/object? Wrong approach to access it?
I saw the esp_now_fetch_peer () function.. but not really clear how its executed (returns status..not clear on how to get info?) (or if its even needed?)
Any (real/helpful) feedback is appreciated!
Thanks