• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MKT-porter
博客园    首页    新随笔    联系   管理    订阅  订阅
wifi测距

 

 

#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);
}

  

 

posted on 2019-04-29 22:41  MKT-porter  阅读(1170)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3