Problems ranging based on the RSSI ESP866

Based ESP866 problem and the RSSI ranging ESP8266

I am currently going to be doing an indoor location devices with multiple phone location ESP8266, (the popular talk is phone open hotspot, ESP8266 connected to the hot spot can be collected RSSI value of the current cell phone, can be calculated by a mathematical formula the approximate distance phone and ESP8266's) is still in beta, now you can do with the RSSI value ESP8266 detection and cell phone signals, but there have been some problems, and now I will share my thoughts to you, hope you can give help.

Arduino serial communication with ESP8266

想要通过Arduino收集ESP8266的RSSI值首先要做到ESP8266与Arduino的串口通信

1. Wiring

Here Insert Picture Description

Here Insert Picture Description
Wiring is as follows

Arduino ESP8266
TX(1) RX
RX(1) TX
3.3V VCC
3.3V CH_PD
GND GND

2. Program

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial)
   {
    ; // wait for serial port to connect. Needed for native USB port only
  }

while(Serial.read()>=0){}   //清空串口缓存
  Serial.println("Goodnight moon!"); // set the data rate for the SoftwareSerial port
  Serial1.begin(115200);
  Serial1.println("AT");
}

void loop() { // run over and over
  if (Serial1.available())         //判断串口1是否接收到数据(这里串口1指的是TX1和RX1)
    {
 	  Serial.write(Serial1.read());   //将串口1读到的数据发送给串口0(串口0指的是RX0)
            
    }
   if (Serial.available())      //判断串口0是否接收到数据
    {
    Serial1.write(Serial.read());  //将串口0读到的数据发送给串口1
  	}
  }

The serial monitor open format and baud rate set as shown below
enter the AT, to see the next step OK

Here Insert Picture Description

ESP8266 connect your phone hotspot

1. Restart ESP8266 module
see OK to return

Here Insert Picture Description
2. AT + SAT ESP8266 convert mode
transmission AT + CWMODE = 3
see the return to OK

Here Insert Picture Description

3. Send AT + CWJAP = "hot name", "hot spots Password"
under the map after the data appears to prove the connection is successful, and now can see after open the phone connected to the phone hotspot ESP8266
Here Insert Picture Description
4. Send the AT + CWJAP? Query information about the current hot spot returned data are SSID, MAC address, channel, RSSI
where RSSI value as long as we

Here Insert Picture Description

Extracting and processing the RSSI value

Here I chose the most simple and crude methods to extract the RSSI value
data extraction I spent two Serial.readBytes () function to extract the value of RSSI, you can study the effect of lower Serial.readBytes () function of the
program is as follows

Serial.write(Serial1.readBytes(buffer1,49));
    Serial.write(Serial1.readBytes(buffer2,5));
    float i1= buffer2[0];
    float i2= buffer2[1];
    i1=i1-48;
    i2=i2-48 ;
    float rssi=i1*10+i2;
    

By calculating formula to convert the RSSI value into distance
distance = (10 ^ ((abs
(-rssi) -A) / (n * 10))) signal strength, wherein A is a transmitting and receiving ends spaced 1 m, n is environmental attenuation factor is an empirical value of these two values, the general reference values given are online (a = 59, n is 2) these two values can be changed according to the actual situation

Complete program

char buffer1[50];
char buffer2[50];
float n=4.00;
float A=48.00;
float distance;
void setup() {
 // Open serial communications and wait for port to open:
 Serial.begin(115200);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
 }

while(Serial.read()>=0){}
 Serial.println("Goodnight moon!");

 // set the data rate for the SoftwareSerial port
 Serial1.begin(115200);
 Serial1.println("AT");
}

void loop() { 
 if (Serial1.available()) 
 {

   Serial.write(Serial1.readBytes(buffer1,49));
   Serial.write(Serial1.readBytes(buffer2,5));
   float i1= buffer2[0];
   float i2= buffer2[1];
   i1=i1-48;
   i2=i2-48 ;
   float rssi=i1*10+i2;
   distance=pow(10,((abs(-rssi)-A)/(n*10)));//将RSSI的值转换成距离
   Serial.println(":");
   Serial.print("RSSI值:");
   Serial.print(rssi);
   Serial.print("距离:");
   Serial.print(distance);
   Serial.print("米");
  
     }
   
 if (Serial.available())
  {
     Serial1.write(Serial.read());
    }
 
}

Enter AT + CWJAP?
Get the distance is 1.26 m
Here Insert Picture Description
After trying a few days after I found this a great value from the error and no shortage of qualitative, because the RSSI value is not a linear relationship with the distance, we can only do a rough calculation of the distance, if you do high-precision distance measurement, it is recommended not to be calculated by the value of the RSSI.

That is more than I get to experience hot and ESP8266 distance by RSSI, to share my experience to everyone, hoping to give you help
if others doubt I can add QQ: 1149484183

Other articles on the ESP8266
about the use of soft Arduino serial data read ESP8266 module unstable solutions
with Arduino and WIFI signal strength detection esp8266

Released three original articles · won praise 2 · Views 351

Guess you like

Origin blog.csdn.net/qq_43892462/article/details/104231699