Announcement

Collapse
No announcement yet.

Location Isolation with ESP32 Bluetooth Low Energy

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael McSharry
    started a topic Location Isolation with ESP32 Bluetooth Low Energy

    Location Isolation with ESP32 Bluetooth Low Energy

    A discussion started at https://forums.homeseer.com/forum/li...y-ble-scanning on the subject of BLE scanning. I did some prototype work with ESP32 to address the author's question and have decided that the project is interesting enough to continue. The intent of this thread is for discussion on the design characteristics of the project.

    The development will be targeted to ESP32 which has built-in BLE capability. The interface with HS is via MQTT protocol.

    My prototype was a sketch using Arduino IDE. This was fine for a quick and dirty evaluation, but porting it for use by others would require that each user have development capability using Arduino tools. My next step is to continue porting of Tasmota to ESP32 (from ESP8266) so that the documented capabilities provided by Tasmota can be used. This is primarily associated with setup of the SSID, subsequent OTA updates of firmware and general configuration for each user's environment. It would also allow users to use other capabilities of the ESP32 so the installed devices can serve multiple purposes.

    A user installation will consist of one or more ESP32 development boards which sell for $5 from China shipment such as https://www.aliexpress.com/item/ESP3...7-321be24a2d87 or $10 from USA shipment such as https://www.amazon.com/Xiuxin-Develo...-2-spons&psc=1 . I do not have either of these specific units with links just provided as examples. I have several ESP32/LoRa modules that I will be using for my development.

    The prototype evaluation scanned for whatever BLE devices that were in my or close neighbor's houses. I did not attempt location determination, but only focused on present/not-present reporting. For this development I ordered two Bluetooth tracking beacons. One based upon Apple and one based upon Android. I should be able to determine if both are compatible.

    Position determination will be based upon the RSSI signal reported by the beacon. There is also a TxPower parameter that can be set on the beacons that may be used at a later time. To assess a reasonable X/Y location at least three ESP32 devices will be installed at strategic locations that provide desired range and separation. My current thinking is to define an arbitrary grid of 100 x 100 and each ESP32 position would be characterized as an X/Y location on this grid. Beacon location would then be calculated with respect to the ESP32 locations so would also fall somewhere on the grid.

    I saw much variation of one form or another in the prototype evaluation in the reported RSSI over time. This implies that filtering will be needed. Kalman filter was discussed in the other thread and this is likely a good final solution. Initially I will be doing a simple weighted average which is in effect a low pass filter. Once the project is determined to be viable then better filtering approach can be implemented to improve stability.

    The prototype ran at one minute samples with thirty second scan per sample to find which BLE devices were advertising. While the ESP32 likley will be powered from USB, I do not know what the duty cycle effects are on battery life of bluetooth devices. For example, will it drain the battery of a nearby smartphone?

    The ESP is a powerful microcontroller so should be able to easily handle the computational burden. My intent is that each ESP32 subscribes to the measurements being made by the other ESP32s. Each will then independently calculate every beacon position. While HS can get information from all ESP32s, the information about beacon location should be identical. In essence this is a redundant system where a fallback could be done by HS should the LWT of the primary ESP32 show it going offline.

    Any discussion that will help this project along and be something useful is welcome.

  • Michael McSharry
    replied
    I did some research about tracking smartphones with BLE. What I learned is that Android and IOS randomize the advertised MAC address for security. This explains why I was getting many unrecognized MAC addresses over time during my development. What I am going to do is provide provision to group all unrecognized MAC addresses into a single beacon's MAC address. While it will not be possible to detect one person's phone from another, it will be possible to detect if any smartphone is present. The update I made to mcsMQTT.pdf is shown below as well as adding another configuration item to the API.

    BLE is often used in smartphones, fitness bands, smartwatches, audio equipment and tracking beacons. The BLE protocol provides a means for one BLE device to request that other BLE devices advertise their MAC address. In the Section 15.15 implementation ESP32 devices will periodically make this request and the ESP32 will then listen for the MAC addresses that are advertised. After signal processing by the ESP32, information on changes in advertised locations are published via MQTT. mcsMQTT will provide the visualization and HS interface for this information.

    The BLE MAC address is a crucial element for the tracking beacon and the ability of devices such as fitness bands to recognize what or who is reporting. For smartphones the MAC address presents a security concern so the MAC address being advertised is usually randomized to protect the identification of the smartphone at any given location.

    While discrimination of specific smartphones is not possible, it is possible to determine if the MAC address provided is from a valid supplier and if not then assume it is a randomly generated one and is associated with some smartphone. The ESP32 can be configured to group all MAC addresses without a recognized supplier into a single MAC so that presence can be reported. Location information, however, will not be valid for the case of multiple smartphones being present.

    Leave a comment:


  • NAB
    replied
    Originally posted by Michael McSharry View Post
    I had considered adding a Z axis, but at that time thought the complexity detracted from its usefulness.
    You're probably right. I was working through the maths in my head and got hopelessly lost! Definitely needs a play before any serious tweaks. All my ESP32's are in use, so I have more coming - the idea that I can have PIR, temperature, humidity, pressure and location all in one box for less than USD10 is really quite appealing.

    Leave a comment:


  • Michael McSharry
    replied
    I had considered adding a Z axis, but at that time thought the complexity detracted from its usefulness. My thinking it would be very difficult to select the correct floor as most points in space would be somewhere between the two floors. This would result in a lack of confidence as the user could not believe the floor selected. The physics of it is also problematic. There are very few obstructions in the vertical direction so beacons above would appear closer than beacons on the same floor.

    In my testing with 5 ESP32 and 2 beacons it was often the case that I did not have three-point intersection of the distance radii. This means the calculation was based upon weighted average distance of the ESP32 that at least had visibility. Adding a third axis would make this alternate calculation hard to interpret and suffer from the same floor placement uncertainty.

    After you play with it a little then I am open to suggestions.

    Leave a comment:


  • NAB
    replied
    Been following this for a while and it sounds great. A question, though, about the x:y location - how well does it work in a multi-story building where devices and hosts could be located in any room? Would it be more accurate to have the layout in three dimensions in the location grid rather than two?
    Looking forward to having a play with it.
    NAB

    Leave a comment:


  • MattL0
    replied
    That's very good new Michael ! Thanks .

    Leave a comment:


  • Michael McSharry
    replied
    How many Bluetooth devices do you monitor?
    There is no practical limit. I think I provisioned for 50, but this could easily be changed. I also provisioned for 10 ESP32 that could also be changed.
    And what model are those Bluetooth devices?
    For my development I used two from Amazon. One called iBeacon and one Feasycom. https://www.amazon.com/gp/product/B0...?ie=UTF8&psc=1 https://www.amazon.com/gp/product/B0...?ie=UTF8&psc=1 The iBeacon one it keychain size and uses a coin cell. The Feasycom id 2.1/4 inches diameter and I think it uses a AAA battery.
    Could you provide an hs3 event, of your choice, that use this information
    I am not understanding what you are asking. The Zone parameter is intended for event trigger so when the zone changes the beacon has moved. The Zone can be accepted as a HS device and the numeric value of the zone is stored in DeviceValue to aid in event usage.
    if you monitors phones or any other battery powered device
    Only battery powered devices have been used. I cannot think of an application for a mains-powered device as these do not change location. I guess one could use it to determine if it has malfunctioned or power was removed. I made no attempt to track a phone. Only a beacon. The impression I get is that the phone only sends a advertisement packet when trying to pair. If one just carries it in their pocket I do not think it is broadcasting bluetooth as this would be a battery consumer with no particular value to a smartphone user. I did not research this so I may be totally wrong on my assumptions.
    how is the battery life
    During my development which was a few months the iBeacon coin cell had to be replaced once. The Feasycom with the larger battery did not need replacement.

    Leave a comment:


  • MattL0
    replied
    Hi Michael, I have read the pdf part concerning your project here. If I go this route, ( not this year for sure ) i'll need to read it again for sure!. This is a really well made pdf about mqtt and all it's applications!

    ---

    -How many Bluetooth devices do you monitor? And what model are those Bluetooth devices? Could you provide an hs3 event, of your choice, that use this information?

    -if you monitors phones or any other battery powered device, how is the battery life?

    Thanks you,
    Matthieu


    Leave a comment:


  • Michael McSharry
    replied
    I found the correct bootloader file so issues I described in the prior post are resolved. Download of the binary can be fully accomplished with the download tool referenced in the manual. I updated the manual and the zips for the proper procedure and proper files. Again, upload is slow. I did previously get the source uploaded.

    Leave a comment:


  • Michael McSharry
    replied
    I have packaged up all related files at the following locations
    http://mcsSprinklers.com/mcsMQTT_4_0_0_0.zip (10 MB) - plugin with BLE Scanning page
    http://mcsSprinklers.com/mcsMQTT.pdf (9 MB) - mcsMQTT plugin manual. Sections 13 (Plugin Configuration) and Section 15.15 (ESP32 firmware and API)
    http://mcsSprinklers.com/ESP32_BLE_BinaryAndLoader.zip (1 MB) binary application, bootloader and partition table
    http://mcsSprinklers.com/BLEScanner.zip (75 MB) ESP32 source from PlatformIO folders

    I am not certain of the need to load the partition table on the ESP32. I did not have success when I erased the 4MB flash and started from scratch. I was able to download firmware.bin which is the main ESP32/Tasmota program. I did this only after having already used the PlatformIO IDE to install the bootloader and partition table. Section 13 of the manual describes this. Always able to use the PlatformIO IDE and load via serial. I also did not have success with subsequent OTA. Seems like I did at first, but not able to when I tried more recently. This is not specific to the application, but to the Tasmota and other infrastructure. Tasmota port for ESP32 does not have the timezone implemented. This appears to be a more basic issue with underlying libraries. This does not impact functionality.

    There has been considerable effort with both the ESP32 and the plugin and each have had multiple iterations as I find ways that I feel would be better. My primary objective was learning with ESP32 development, Tasmota for ESP32, BLE and methodologies for location isolation. It has been many years since I got into the math associated with this project. I ended up doing the trilateration by solving for intersection of circles using simultaneous equations. Some of my results where not as expected so I did an approach that translates and rotates the problem space through the origin so that linear match could be used. When I got same results both ways then I was confident of the implementation.

    My internet upload speeds on a good day are 200K (a little better than dial-up telephone line) so there may be some difficulty in getting the source uploaded. At this point the first two have been uploaded and the first also contains the manual. I will keep trying for the others, but right now the connection has issues.

    For those interested at this time look at Section 13 in particular that has getting started paragraphs.

    Leave a comment:


  • Michael McSharry
    replied
    Only one of the two general purpose CPUs are being used for bluetooth. Even it is loafing. The other CPU supports all the other Tasmota functions. Since the ESP32 is an order of magnitude faster than the ESP8266 it has much spare on this CPU.

    For flash I am at 1.74 Mbyte. I have the ESP32 partitioned for two 1.98 MByte segments for application. I should be able to do OTA upload, but I get too-big message when I try. I can do it via USB. I have not looked into the code for OTA to see what it needs to know to recognize the partition size I am using.

    Of course all of the general purpose IO is unused. I have not tried to apply any of the IO pins for other functionality, but it should be able to be setup in a standard Tasmota manner.

    Leave a comment:


  • kideon
    replied
    I can’t wait to start implementing this!!!! So as a project manager I despise scope creep...but...have a question. Are the resources too consumed on the ESP32 as to prevent other functions. I just ask because I’ll have these things across the property and if they can still use the IO pins that would allow for some other functions like controlling LED lights or chimes / alarms. If not it’s cool I can implement with another device just thought it was feasible.

    Leave a comment:


  • Michael McSharry
    replied
    Considerable progress. The past week have been focusing on the plugin side of things and iterating the ESP32 code as I find better ways for the two pieces to interchange. It really is coming along very well. I think I can have something for others to use next week.

    Above was an example of the current location chart. I also have a scatter chart for a selected beacon that shows how it moved around in the past 24 hours. I made all the setup and the reporting done by the ESP32's visible and alterable in a consolidated page with snapshots shown below. This has gone beyond what I had first envisioned but it is cool.

    I also attached the manual that is a work-in-progress for Section 14.15.1. This part describes the ESP32 side of the interface. I have not yet put the plugin side into the manual.

    [ATTACH]n1304215[/ATTACH]
    Click image for larger version

Name:	b1.PNG
Views:	159
Size:	68.3 KB
ID:	1304216

    Click image for larger version

Name:	b2.PNG
Views:	158
Size:	314.3 KB
ID:	1304217

    Leave a comment:


  • S-F
    replied
    I'm finding this to be profoundly interesting. Has there been any more progress made?

    Leave a comment:


  • Michael McSharry
    replied
    Good idea. I looked at the reference and it should be possible to build in access to their API to get the data.

    Attached is some eye candy that I collected during the plugin updates. I have 3 scanners powered and these are shown as yellow squares. My two beacons are correctly located. The Feasycom one is seen by all three scanners so is the largest circle. The BlueCharm one is not seen by the scanner at 90,90 so the smaller circle reflects the lower confidence level.

    Click image for larger version

Name:	plot1.png
Views:	150
Size:	19.2 KB
ID:	1302143

    Leave a comment:

Working...
X