I am trying to obtain the RSSI of an ESP32 client and send it to the master.
I am getting the following error.
'esp_now_get_peer_rssi' was not declared in this scope
Any help is appreciated.
Attached is the code:
#include <esp_now.h>
#include <WiFi.h>
// Replace with your own MAC addresses
uint8_t receiverMAC[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; // MAC address of the receiver (master) ESP32
uint8_t senderMAC[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; // MAC address of the sender (slave) ESP32
// Callback function to handle received data
void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
Serial.print("Received data from MAC: ");
for (int i = 0; i < 6; i++) {
Serial.print(mac_addr[i], HEX);
if (i < 5) Serial.print(':');
}
Serial.print(" Data: ");
Serial.print(*data); // Assuming you are sending a single number
Serial.print(" RSSI: ");
Serial.println(esp_now_get_peer_rssi(*mac_addr)); // Print the received signal strength
// Send the RSSI value back to the master ESP32
if (esp_now_send(senderMAC, (uint8_t*)&esp_now_get_peer_rssi(*mac_addr), sizeof(int)) != ESP_OK) {
Serial.println("Failed to send RSSI data");
}
}
void setup() {
Serial.begin(115200);
delay(1000);
// Initialize ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("ESP-NOW initialization failed");
ESP.restart();
}
// Register the callback function for receiving data
esp_now_register_recv_cb(OnDataRecv);
// Add the receiver (master) to the peer list
esp_now_peer_info_t peerInfo;
memcpy(peerInfo.peer_addr, receiverMAC, 6);
peerInfo.channel = 0; // Set the channel (0-13)
peerInfo.encrypt = false; // No encryption
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
Serial.println("Failed to add peer");
ESP.restart();
}
}
void loop() {
// The slave can perform other tasks in the loop if needed
}