Is it possible to determine the position of my hotel room with sufficient accuracy using an ESP32 or ESP8266 device? The answer is simple: Yes, it can work if there are enough WiFI access points spread around in the hotel, enough time to walk up and down the floor for hours and don't get kicked out because of acting seriously suspicious.
The hotel problemHanging out in a hotel room can be pretty boring. The TV programs don't give anything to watch and on YouTube everything is already watched. Okay, almost...
Then I discovered that I can detect 14 WiFi access points in my room. Wow, that's a lot. On the stairs to my floor I detected 16 and on the corridor I was able to detect something between 11 and 15 WiFi access points. This is better than TV and YouTube together and the stuff sleepless nights are made of (In front of the computer).
You know how it is: Hotel corridors are long and monotonous. If you frequently change hotels, your own room number often does not make it into the long-term memory. So the question arises: Can my M5Stack and the high number of WiFi access points help me to find my room quickly and easily?
The answer depends a little bit on how you define "quickly" and "easily", but basically it works like this:
Step 1: Map the floorAs a first step, the system has to learn the position of your room on the corridor. To do this, start in front of the room door and move to the left (positive) or right (negative). After every step, let the M5Stack scan for WiFi access points and let him learn the relationship between position and WiFi signal strength.
It is useful to go to the left and to the right in order to represent the corridor as well and as wide as possible. And it's best to walk up and down the corridor twice, but beware of other hotel guests: They would rather expect criminal intentions than useless non-scientific-technical experiments.
The GUI will guide you through the corridor. You only need to take one step at a time and let the device scan at every position. It is important that you always make steps with the same size. Otherwise the result will be inaccurate! I personally find it easier to go sideways, even if I had to go sideways again during the search to avoid measurement differences. It is easier to keep an identical step size by walking sideways. Maybe you will feel like John Cleese in "ministry of silly walks" but remember: It's all for science (or something like that)... And keep in mind: You don't want to wake up in the wrong room with someone else's toothbrush in the bathroom! So maybe you better take the time for a detailed measurement.
Step 2: IILTM: The Inverse Intensity Lookup Table MapInternally the software fits a 5th order polynomial to the learned data. This function maps the relationship between the position in the corridor and the signal strength (RSSI) of each individual detected WiFi access point.
For localization along the corridor, however, exactly the other direction of the formula is required: The position has to be determined from the signal strength of the WiFi access points. To be able to calculate the position on the basis of the signal strengths, an Inverse Intensity Lookup Table Map is created over the length of the corridor:
Don't worry, the software does this all by itself as soon as you have finished wandering around in the corridor (Deatils are described below).
Step 3: Go out for a drinkNow nothing can happen to you! You can switch off the M5Stack and go carelessly to the nearest milk or beer bar to come back late. The system knows where your bed is and helps you find your own room in the endless vastness of the hotel.
Step 4: Let the device guide you homeOK, you should already know what floor your room is on. Otherwise, you're gonna have to go through all of them and you'll lose that from your necessary bedtime. The best thing is to put an old sock on the stairs to mark the right floor (or anything else inconspicuous).
In the corridor you can ask the M5Stack how far you are away from your room. The device scans for WiFi access points and goes through the Inverse Intensity Lookup Table Map (IILTM). For each entry, the sum of the squares of the difference between the expected signal strength and the measured signal strength is calculated. The minimum of this curve indicates where you are most likely located in the corridor. However, if the display shows a large positive number, then you are still far away from the room.
If the display shows a negative number, you have passed it and if the display shows a zero, you should be standing somewhere right in front of your room door.
When a number near zero is displayed, all you have to do is try your key on all the doors around you and voilà, you can brush your teeth with your own toothbrush and go to bed.
How it worksThe classical methods for indoor localization are based on a traingulation approach. But for this you have to know the exact position of the transmitter. In a hotel it can be difficult to measure the exact position of all WiFi access points. If the sideways wandering is already suspicious, what would it look like if you removed the ceiling cover and start looking for electronic devices? In addition, a direct line of sight is necessary to obtain a calculable relationship between distance and signal strength. This contradicts modern architecture, in which no electronic chunks should be visible.
Another common method uses a fingerprint database to deduce the location from the signal strengths based on patterns of signal strengths. My method works similar like that, but differently:
In modern hotels there are numerous WiFi access points to provide Internet access to every guest, wherever they are. In my hotel corridor I am able to detect many access points and when I walk down the corridor, the distance to the access points changes and with it the detected signal strength. In other words: For each position along the corridor there is a more or less unique combination of the signal strengths of the accessible access points. However, it is in the nature of WiFi signals that the signal strength (RSSI) is heavily noisy. This makes accurate positioning difficult. Also a snapshot based fingerprint of the signal strength pattern is also influenced by the noise of the signal. That's the moment when mathematics becomes your helping friend.
The shape of the signalIn general it sounds very simple: The further away from the access point I am, the lower the signal strength. So I should be able to deduce the distance from the signal strength right? Unfortunately, it is a bit more complicated and the noise of the signal does not make it easier. Let's have a look at the correlation between signal strength and distance to understand why it is complicated:
When a single transmitter is in my direct line of sight, there is a clear correlation between distance and signal strength. This correlation is not linear, but still a simple curve:
This looks very promising because I can clearly find the distance for a given RSSI value. It becomes more difficult, however, when I pass the transmitter in order to get to my room. Then there is no longer a clear relation between the signal strength and my position in the corridor. I could be in two places in the corridor at the same time (stupid ambiguity problem):
To exist twice sounds funny, but it can also be a real headache when you are tired and want to go to bed.
If the transmitter is located on a different floor or behind a column or behind some other structural parts, the signal strength along the corridor can become even more complicated. This stuff is no longer a simple function and makes it even more difficult to determine your own position. But if there are many access points in the area of the corridor, which are distributed hopefully randomly, then a more accurate position signal can be calculated from the multitude of data. So the idea is to not count on one access point then count on the picture of many of them. Like in the following example, where the distance of -5 is clearly given by the values of -72dBm for the "red" access point and -45dBm for the "blue" one:
But to do this, for the number of access points along the hotel floor, a functional representation of the measured data for each access point is needed.
A higher-order polynomial could be used to determine a functional relationship between the position and the measured signal strength values. A small micro controller like the ESP32 in my M5Stack is not very good at performing high precision mathematical calculations, but I have made some attempts to create a library that can fit polynomials up to 6th degree with acceptable accuracy. At higher degrees than 6 or 7, the result becomes more and more inaccurate due to the limitations in the floating point operations. OK, fair enough. The test data in my favorite hotel showed that a 5th-order polynomial is quite sufficient.
Signal QualityThe fit-class of the curve-fit library allows you to add new data pairs at runtime. This allows the polynomial representation to "grow" over time without the need to store all data temporarily in the RAM memory. The more data points, the better the fit. If there are too few data points, the result can become chaotic. Therefore, in the following step, after the data collection in the corridor is completed, all data records of access points, for which less than 6 data points were collected, are ignored. In addition, all access points that show a signal level amplitude of less than 15dBm during walking along the corridor are ignored too.
The software has also memorized the maximum positions in the corridor. From this, a table with smaller increments of the positions than the steps you made is now created. With these values the Inverse Intensity Lookup Table Map for the corridor with all usable access points can be created. Since this map is based on a functional representation of the signal strength along the corridor, the typical noise of the signal strength is effectively filtered out.
This map is saved and later used for localization. The map can also be transmitted to other M5Stack devices, so that my friends can find my room, for example, without having to tell them my room number. Well, OK, maybe telling them the room number would be easier, but not that much fun!
Least square position detection methodTo calculate the distance to my room, the device scans the signal strength of the accessible access points at the place where I'm standing. For each entry in the Inverse Intensity Lookup Table Map, it now looks at what signal strength the access point would have to have if I were standing at the corresponding position. The difference to the measured signal strength is calculated and squared. The same is done for all access points and the values are summed.
If I am far away from a point on the intensity map, then the sum of the squares of the differences gives a high value. But for the position where I am, the sum is small because the differences between the measured signal strengths and the ideal ones is small. Thus the smallest value of this calculation over the intensity map indicates most likely where I am.
That's it. That's all: A device with a WiFi chip, a little bit of math, a small GUI and a few hours to walk up and down the hall. Nothing more! In my favorite hotel it works fine, but in an old shed where WiFi is only available at the bar, it's better to take a picture of the room door, or just look at the room key to get the number. Or one asks at the reception and writes down the room number on a piece of paper. But in a modern hotel with a lot of access points, the system is very easy to use. Even if it is totally senseless.
FeedbackI hope you enjoy reading as much as I enjoyed the development, the testing and writing down the stuff. Maybe you'll try it out for yourself during your next hotel stay? Then I would be very interested to know if you were able to find back to your own room, if you ended up in a room with a gang of mafiosi or if the security guys kicked you out of the hotel.
Comments