zoukankan      html  css  js  c++  java
  • 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);
    }
    

      

  • 相关阅读:
    ubuntu server 12.04中文显示不了
    hustoj升级
    oj资源
    考试系统
    怎样用DOS命令替换文本里的某段字符
    ubuntu一键安装lamp
    Windows Server 2008官方简体中文正式版下载+序列号
    vsphere ubuntu网速很慢
    前端
    (运维)VMwarevCenterServerAppliance5.0安装与部署
  • 原文地址:https://www.cnblogs.com/kekeoutlook/p/10793367.html
Copyright © 2011-2022 走看看