how can I get wifi rssi at faster rate
Posted: Sun Jun 10, 2018 10:15 am
I'm doing a project on lcoalization using wifi RSSI value.
I found some code only it's too slow for me since the rssi value can be interfere and vary very easy , so I need faster rssi value to do a moving avg before use it in my applicaion
code:
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <cmath>
const char* SSID = "wifi";
// Return RSSI or 0 if target SSID not found
double getRSSI(const char* target_ssid) {
byte available_networks = WiFi.scanNetworks();
for (int network = 0; network < available_networks; network++) {
if (strcmp(WiFi.SSID(network).c_str(), SSID) == 0) {
return WiFi.RSSI(network);
}
}
return 0;
}
void setup() {
Serial.begin(115200);
}
double getDistance(double rssi, double txPower) {
/*
* RSSI = TxPower - 10 * n * lg(d)
* n = 2 (in free space)
*
* d = 10 ^ ((TxPower - RSSI) / (10 * n))
*/
return std::pow(10, ((double) txPower - rssi) / (10 * 2));
}
//66.5 , 67.8484848485 ,
void loop() {
unsigned long before = millis();
double rssi = getRSSI(SSID);
unsigned long after = millis();
Serial.print("Signal strength: ");
Serial.print(rssi);
Serial.println("dBm");
//////
Serial.print("Distance: ");
Serial.print(getDistance(rssi,-53));
Serial.println("m");
//////
Serial.print("Took ");
Serial.print(after - before);
Serial.println("ms");
delay(100);
}
I found some code only it's too slow for me since the rssi value can be interfere and vary very easy , so I need faster rssi value to do a moving avg before use it in my applicaion
code:
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <cmath>
const char* SSID = "wifi";
// Return RSSI or 0 if target SSID not found
double getRSSI(const char* target_ssid) {
byte available_networks = WiFi.scanNetworks();
for (int network = 0; network < available_networks; network++) {
if (strcmp(WiFi.SSID(network).c_str(), SSID) == 0) {
return WiFi.RSSI(network);
}
}
return 0;
}
void setup() {
Serial.begin(115200);
}
double getDistance(double rssi, double txPower) {
/*
* RSSI = TxPower - 10 * n * lg(d)
* n = 2 (in free space)
*
* d = 10 ^ ((TxPower - RSSI) / (10 * n))
*/
return std::pow(10, ((double) txPower - rssi) / (10 * 2));
}
//66.5 , 67.8484848485 ,
void loop() {
unsigned long before = millis();
double rssi = getRSSI(SSID);
unsigned long after = millis();
Serial.print("Signal strength: ");
Serial.print(rssi);
Serial.println("dBm");
//////
Serial.print("Distance: ");
Serial.print(getDistance(rssi,-53));
Serial.println("m");
//////
Serial.print("Took ");
Serial.print(after - before);
Serial.println("ms");
delay(100);
}