#include "ESP8266WiFi.h"

#include "math.h"
//d = 10^(A-(abs(rssi)) / (10 * n))  信号强度
#define N 45                //N = 10 * n ,其中n为环境衰减因子,3.25-4.5
#define A -35            //接收机和发射机间隔1m时的信号强度



void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
//  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
//  WiFi.softAP("215-wifi","1234567890");
   
  WiFi.disconnect();
  delay(100);
  Serial.println("Setup done");
 
   
}




void loop() {
  Serial.println("scan start");
  // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  
   
  if (n == 0) {
    Serial.println("no networks found");
  } else {
    Serial.print(n);
    Serial.println(" networks found"); 
    for (int i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");

      //接收信号强度指示算法(RSSI)
      //A为定位节点与参考点之间的距离d为 1m 时测得的 RSSI 值;
      //n为信号衰减因子,范围一般为2~4。
/*
double log (double); 以e为底的对数   
double log10 (double);以10为底的对数    
double pow(double x, double y);计算以x为底数的y次幂    
float powf(float x, float y); 功能与pow一致,只是输入与输出皆为浮点数    
*/

    float iu, distance;
    iu = (float)(A-WiFi.RSSI(i) ) / (float)N;  
    distance = powf(10.0, iu);//计算以x为底数的y次幂     功能与pow一致,只是输入与输出皆为浮点数  

    Serial.print("distance:---"); Serial.println(distance);
      
    }
  }
 
       
  
 
   
  delay(3000);
}

  

 

版权声明:本文为gooutlook原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/gooutlook/p/10793367.html