schollz / find-lf

Track the location of every Wi-Fi device (:iphone:) in your house using Raspberry Pis and FIND
https://www.internalpositioning.com/plugins/#using-find-without-an-app
GNU Affero General Public License v3.0
994 stars 123 forks source link

Is it possible to run find-lf on a single RPi? #10

Open boonhapus opened 7 years ago

boonhapus commented 7 years ago

schollz,

I am hoping to use find-lf for two purposes, in order of importance above. I am running HomeAssistant and as I'm sure you're already aware, reliable presence detection has always been a challenging problem to solve. To my understanding, FIND works by allowing an Android user to connect to the platform via an app. find-lf works much the same, but without the app. Please correct me if I am wrong!

If this is the case, find-lf seems more attractive, as it would work better with both Android and iPhone users.. however I know the intention is to emulate the LF sonar system which implies multiple polling devices. So, in saying all of this..

Is it possible to run find-lf on a single RPi?

schollz commented 7 years ago

@SupahNoob

Yes, depending on your priorities. If your main priority is Presence Detection (which I assume you mean to monitor who is on the network), then you don't need FIND-LF at all, but you could simply use nmap to scan which devices are currently connected and report that to HomeAssistant.

You listed a second priority as Internal positioning - which is what FIND-LF is designed for and good at. Yes, you can run it on a single RPi, but with one caveat: you can only classify a few locations (maybe ~3) with any confidence in their gelocating resolution. I.e. you can classify one location as being "close" to the Pi,, one as being "kind of close" and one as being "far away". With 2+ RPis you can do more triangulation and classify more locations with precision. However, if learning ~3 location is good enough, I'd say one RPi will work well.

Don't hesitate to let me know if you need more explanation!

boonhapus commented 7 years ago

This is a great explanation. nmap is slow and not as reliable as I'd like it to be, especially with iPhones -- granted there are plenty of ways to defer automation rules from going off in various situations. Additionally, nmap is timed-based, whereas find-lf is event-based which makes it vastly superior.

The second priority is more of an "icing on the cake" feature for me, but still extremely useful and interesting. I don't know that it is responsive enough to be able to completely replace motion sensors, and certainly not with it relying on web I do live in a fairly small apartment, and has 4 total rooms in it so while 1 RPi would still work, it's also not the ideal situation either. Have you tested find-lf on the RPi Zero w/ adapter that can be put into monitor mode? This could work very well in my situation as it's not cost prohibitive in multiples and still a lightweight solution (ie. I can hide the suckers just about anywhere!).

schollz commented 7 years ago

I didn't realize the reliability of nmap is not optimal. In that case I think find-lf would work well for you.

Yes, I've tested find-lf on a RPi Zero with adapter in monitor mode. It works well but has a drawback because it only has a single WiFi card. The drawback is that, in order to send the information to the server with a single WiFi card, a Pi has to stop tshark and then reset the WiFi adapter back to managed mode so it can connect to the network and upload the data. Then it switches the WiFi adapter to monitor mode and re-engages tshark. This means that there is an added ~5-10 s delay for sending fingerprints for the switching to take place. Currently scan.py automatically will determine if this is the case and perform single-wifi tracking.

boonhapus commented 7 years ago

My understanding is that nmap only scans the IPs. If your router doesn't consistently tie the same device to the same IP, then tracking a user is not a sure thing. In order to make sure you're recording the correct device's presence on the network, you'd have to then ping the device for it's MAC address and add it to a registry of sorts and refresh this every time you scan the network. This could also be done with ARP requests, but I don't how how reliable this is comparatively.

How does RPi Zero differ from using find-lf on a RPi2 or 3 - I assume it doesn't? Are we assuming that the documented scenario were using a Pi cluster of 3s that also have a WiFi adapter?

Thanks for all the insight here! This is really useful information.

schollz commented 7 years ago

The only difference between RPi Zero and RPi2/3 are the number of USB slots. On the Zero, you only have the one USBmicro (which you can adapt to USB for the WiFi monitor adapter). On the RPi2 you have more USB slots, so you can have the WiFi monitor adapter AND another cheap USB WiFi adapter so that you can be connected to the internet so scanning/uploading can occur at the same time. RPi3 is the best in these terms because its got built-in WiFi so you can use the built-in for being connected, and then you can connect the WiFi monitor adapter for the scanning.

boonhapus commented 7 years ago

So, find-lf is doing both scanning and uploading simultaneously, whereas find does them individually, is that correct? If so, I think I will likely go forward with find-lf and build multiple RPi3 with adapters as this seems like a great solution for my needs.

boonhapus commented 7 years ago

@schollz Your documentation looks like it's to set up on a server of some sort, then issue commands to the pis via SSH. In which case, following the instructions would not work if I wanted to run something like cluster.py locally. I suppose I'll just look at your code and learn it, and modify it for my needs :)

I just looked through scan.py and it makes enough sense. However I'm unable to see my dashboard, for whatever reason. Eventually I'll want to either do comms based on who is home, or matching MAC addr to a username of sorts -- so I think I'll need to use your MQTT setup which I assume requires the dash to be active?

schollz commented 7 years ago

If you can't see your dashboard it means that fingerprints haven't been learned yet. Make sure that you set your system to "learning". I.e. Goto https://lf.internalpositioning.com/, enter your group name, and enter a device and where the device is and click Learn.

boonhapus commented 7 years ago

@schollz Got my dash, got everything the way I like in python. Scans run and locally maintain a whitelist of macs I'm trying to keep track of... but now I'm stuck on the MQTT aspect. I keep getting ConnectionedRefusedError -- assuming due to user/pass restrictions.

import paho.mqtt.client as mqtt

self.client = mqtt.Client()
self.client.on_connect = self.on_connect
self.client.on_message = self.on_message
self.client.username_pw_set(username='not sure what this should be', password='<generated via find-lf dash>')
self.client.connect('ml.internalpositioning.com', 1883, 60)
self.client.loop_start()
...
self.client.loop_stop()

When setting up a mqtt client in python via paho ... what would my username be?

pedrolucasoliva commented 6 years ago

Have you tested with Raspberry Pi Zero W? (Embedded wifi and USB wifi)

schollz commented 6 years ago

@pedrolucasoliva No I have not. That certainly should work though!

schollz commented 6 years ago

@SupahNoob Your username is your groupname. You will also need a password. To get your MQTT password, you just need to make a request:

curl -X PUT "https://ml.internalpositioning.com/mqtt?group=YOURGROUP"
mmsylvester commented 6 years ago

Any update on using pi zero W? I'm planning to get an additional monitoring mode capable USB adapter and then use the built in wnet to communicate back to the server? Should this just work or changes are necessary? Thanks, this is a very interesting project!

boonhapus commented 6 years ago

@mmsylvester Pi0w should work fine in terms of computational power. What you're asking about should do pretty well! I don't use find-lf anymore but that seems completely do-able.