Hi Guys,
I hope all of you in good health
I am working on sample of ESP multi slave with ESP8266 module, I am using a code that discover slaves and add it as a peer in the Master, but the problem I have that the master is normally see the MAC address of Slave correctly but under "processing:" the mac address change like this the output:
1: Slave:BC:DD:C2:30:7F:77 [BE:DD:C2:30:7F:77] (-26) 1 Slave(s) found, "As you see here the MAC address is correct"
processing..
Processing: EE:DE:2E:E:FE:7E Status: Already Paired "As you see here the MAC address changed"!
Sending: 3 Send Status: Success 0 {0xEE,0xDE,0x2E,0xE,0xFE,0x7E}; ESPNOW: SEND_FAILED
the part of the code I am using:
// Scan for slaves in AP mode
void ScanForSlave() {
int8_t scanResults = WiFi.scanNetworks();
//reset slaves
memset(slaves, 0, sizeof(slaves));
SlaveCnt = 0;
Serial.println("");
if (scanResults == 0) {
Serial.println("No WiFi devices in AP Mode found");
} else {
Serial.print("Found "); Serial.print(scanResults); Serial.println(" devices ");
for (int i = 0; i < scanResults; ++i) {
// Print SSID and RSSI for each device found
String SSID = WiFi.SSID(i);
int32_t RSSI = WiFi.RSSI(i);
String BSSIDstr = WiFi.BSSIDstr(i);
delay(10);
// Check if the current device starts with `Slave`
if (SSID.indexOf("Slave") == 0) {
// SSID of interest
Serial.print(i + 1); Serial.print(": ");
Serial.print(SSID); Serial.print(" [");
Serial.print(BSSIDstr); Serial.print("]");
Serial.print(" ("); Serial.print(RSSI);
Serial.print(")"); Serial.println("");
// Get BSSID => Mac Address of the Slave
char macPart[4];
macPart[0] = '0';
macPart[1] = 'x';
macPart[2] = (char)BSSIDstr[0];
macPart[3] = (char)BSSIDstr[1];
slaves[SlaveCnt].peer_addr[0] = strtol(macPart,0,16);
macPart[2] = (char)BSSIDstr[3];
macPart[3] = (char)BSSIDstr[4];
slaves[SlaveCnt].peer_addr[1] = strtol(macPart,0,16);
macPart[2] = (char)BSSIDstr[6];
macPart[3] = (char)BSSIDstr[7];
slaves[SlaveCnt].peer_addr[2] = strtol(macPart,0,16);
macPart[2] = (char)BSSIDstr[9];
macPart[3] = (char)BSSIDstr[10];
slaves[SlaveCnt].peer_addr[3] = strtol(macPart,0,16);
macPart[2] = (char)BSSIDstr[12];
macPart[3] = (char)BSSIDstr[13];
slaves[SlaveCnt].peer_addr[4] = strtol(macPart,0,16);
macPart[2] = (char)BSSIDstr[15];
macPart[3] = (char)BSSIDstr[16];
slaves[SlaveCnt].peer_addr[5] = strtol(macPart,0,16);
SlaveCnt++;
}
}
}
if (SlaveCnt > 0) {
Serial.print(SlaveCnt); Serial.println(" Slave(s) found, processing..");
} else {
Serial.println("No Slave Found, trying again.");
}
// clean up ram
WiFi.scanDelete();
}
// Check if the slave is already paired with the master.
// If not, pair the slave with master
void manageSlave() {
if (SlaveCnt > 0) {
for (int i = 0; i < SlaveCnt; i++) {
const esp_now_peer_info_t *peer = &slaves[i];
u8 *peer_addr = slaves[i].peer_addr;
Serial.print("Processing: ");
for (int ii = 0; ii < 6; ++ii ) {
Serial.print((uint8_t) slaves[i].peer_addr[ii], HEX);
if (ii != 5) Serial.print(":");
}
Serial.print(" Status: ");
// check if the peer exists
bool exists = esp_now_is_peer_exist((u8*)peer_addr);
if (exists) {
// Slave already paired.
Serial.println("Already Paired");
} else {
// Slave not paired, attempt pair
int addStatus = esp_now_add_peer((u8*)peer_addr, ESP_NOW_ROLE_CONTROLLER, CHANNEL, NULL, 0);
if (addStatus == 0) {
// Pair success
Serial.println("Pair success");
} else {
Serial.println("Pair failed");
}
delay(100);
}
}
} else {
// No slave found to process
Serial.println("No Slave found to process");
}
}
If any one can help for this issue!