Good evening everyone, after performing a Scan to see available Wifi networks, I am interested only in a specific network characterizable by its MAC address, the one I want to communicate his RSSI to Thingspeak server in real time, the problem that he declares me that the variable rssi is not declared ...... Do you have remarks Thank you ...
Here is the code
#include <WiFi.h>
#include “esp_deep_sleep.h” //Library needed for ESP32 Sleep Functions
WiFiClient client; // wifi client object
const char *ssid = “ssid”;
const char *password = “xxxxxxxxxx”;
const char *Address_Mac = “AA:BB:CC:DD:EE:FF”;
char ThingSpeakAddress[] = “api.thingspeak.com”; // Thingspeak address
String api_key = “xxxxxxxxxxxxxxxxxxx”; // Thingspeak API WRITE Key for your channel
const int UpdateInterval = 0.33 * 60 * 1000000;
void UpdateThingSpeak(String DataForUpload);
void scanNetworks() {
int numberOfNetworks = WiFi.scanNetworks();
Serial.print(“Number of networks found: “);
Serial.println(numberOfNetworks);
for (int i = 0; i < numberOfNetworks; i++) {
Serial.print(“Network name: “);
Serial.println(WiFi.SSID(i));
if (WiFi.BSSIDstr(i).equals(Address_Mac)){
float rssi = WiFi.BSSIDstr(i));
}
}
}
void setup() {
Serial.begin(115200);
scanNetworks();
WiFi.begin(ssid, password);
Serial.println(“Start WiFi”);
while (WiFi.status() != WL_CONNECTED ) {Serial.print(“.”); delay(500); }
Serial.println(WiFi.localIP());
UpdateThingSpeak(“field1=”+String(rssi)); //Send the data as text
esp_deep_sleep_enable_timer_wakeup(UpdateInterval);
WiFi.disconnect(true);
Serial.println(“Going to sleep now…”);
esp_deep_sleep_start();
}
void loop() {
}
void UpdateThingSpeak(String DataForUpload) {
WiFiClient client;
if (!client.connect(ThingSpeakAddress, 80)) {
Serial.println(“connection failed”);
return;
}
else
{
Serial.println(DataForUpload);
client.print(“POST /update HTTP/1.1\n”);
client.print(“Host: api.thingspeak.com\n”);
client.print(“Connection: close\n”);
client.print(“X-THINGSPEAKAPIKEY: ” + api_key + “\n”);
client.print(“Content-Type: application/x-www-form-urlencoded\n”);
client.print(“Content-Length: “);
client.print(DataForUpload.length());
client.print(“\n\n”);
client.print(DataForUpload);
}
client.stop();
}
Hello, you need to send the RSSI value in the body of the HTTP POST request. After the host, you can do something like this:
client.print(“POST /update HTTP/1.1\n”);
client.print(“Host: api.thingspeak.com\n”);
client.print(“field1=”);
client.print(rssi );
(…)
I hope that helps. Regards,
Rui