reelyActive Smart Spaces Revisited

If your use case is “Tell me if phone x or phone y is near by” you want the sensor to filter out the tens to hundreds of readings from other devices. I live in a suburban area and on a given day I’d see around 20-50 devices through reelyActive. For someone living in an apartment or an urban area I can’t imagine how many devices would be detected. That is a whole lot of network traffic and a whole lot of processing that needs to take place that doesn’t have to if all you care about is a couple of specific phones.

And indeed, scans take tens of seconds to complete and tie up the BT device during the scan meaning that, IIRC, you cannot receive BTLE broadcasts at the same time you are scanning on the same BT transceiver.

I’ve been running the last couple of days sniffing for bluetooth devices. When I turned on my script, I noticed poor network performance. Tonight I plotted some ping latency with and without the sniffer enabled. I’ve also found a thread on the Raspberry Pi forums confirming the problem, but there’s no official acknowledgement as of yet. Sniffing for legacy bluetooth is on this chart. Sniffing for BTLE results in much better performance, with ping latencies typically below 100ms.

Actual that does remind me. When I used reelyActive and bt scans I had to use a wifi dongle to get reliable networking. I thought it was because the built in wifi on the RPi 3 was just really poor. Perhaps there was interference from the bt.

I tested a one-off compile of hcitool from this thread: https://github.com/raspberrypi/linux/issues/1444
That hcitool does fix the problem.

Fellow openHabians,

I have reelyActive (RA) up and running on an Raspberry Pi3 and through me browser I can see my Ble devices.

I installed RA from the snapshot found on their website so consequently the working directory is located in /reelyActive/pi-suite/node_modules where I created and saved the “server.js” file as described. I can run the file, it works just fine and I see “hlc-server is listening on port 3001 …”

I stopped the server.js with ctl c and then created the reelyActive.service file as described except the WorkingDirectory=/reelyActive/pi-suite/node_modules (this is were server.js is located).

this is what I get after running:
sudo systemctl enable reelyActive.service
sudo systemctl start reelyActive.service
sudo systemctl status reelyActive.service

pi@reelyactive-pi:~ $ sudo systemctl status reelyActive.service
● reelyActive.service - reelyActive
Loaded: loaded (/lib/systemd/system/reelyActive.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-03-18 09:28:26 CDT; 15min ago
Process: 599 ExecStart=/usr/local/bin/node server.js (code=exited, status=210/CHROOT)
Main PID: 599 (code=exited, status=210/CHROOT)

Mar 18 09:28:25 reelyactive-pi systemd[1]: reelyActive.service: Unit entered failed state.
Mar 18 09:28:25 reelyactive-pi systemd[1]: reelyActive.service: Failed with result ‘exit-code’.
Mar 18 09:28:26 reelyactive-pi systemd[1]: reelyActive.service: Service hold-off time over, scheduling restart.
Mar 18 09:28:26 reelyactive-pi systemd[1]: Stopped reelyActive.
Mar 18 09:28:26 reelyactive-pi systemd[1]: reelyActive.service: Start request repeated too quickly.
Mar 18 09:28:26 reelyactive-pi systemd[1]: Failed to start reelyActive.
Mar 18 09:28:26 reelyactive-pi systemd[1]: reelyActive.service: Unit entered failed state.
Mar 18 09:28:26 reelyactive-pi systemd[1]: reelyActive.service: Failed with result ‘exit-code’.

ok I tried to run ~ $ /usr/local/bin/node server.js

this is what was returned:
module.js:549
throw err;
^

Error: Cannot find module ‘/home/pi/server.js’
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:

seems to be looking for /home/pi but it should be /reelyActive/pi ?

Please if you have any idea where I’m going wrong here it would be appreciated.

Thank you in advance!
Mike Anderson

Is it? In the previous paragraph you stated it is in ~/reelyActive/pi-suite/node_modules with the ~ translating to “/home/login” where login is the user you logged into (pi, openhabian, etc). You will want to use the full path in your .service file.

Thank you for the reply!
Man I have a lot to learn…

Sorry the files are in this directory /reelyActive/pi-suite/node_modules

The reelyActive snapshot has all of the supporting files in /reelyActive/pi-suite/node_modules
hlc-server, bluetooth-hci-socket, mqtt, barnowl, barnacles…
If i try to run server.js in any other directory it will not run.
I copied and tried to run it in the home directory and it reports:

pi@reelyactive-pi:~ $ sudo node server
module.js:549
throw err;
^

Error: Cannot find module ‘hlc-server’
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (/home/pi/server.js:17:14)
at Module._compile (module.js:652:30)
at Object.Module._extensions…js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)

Mike

You need to run it from the folder where the server.js file resides. If you look at the .service file in the OP, you will see a WorkingDirectory option. This tells systemd to change to that directory before trying to execute the command listed in ExecStart.

The tutorial in the OP assumes you placed the files in /opt/reelyActive so make sure the paths match where you actually placed the files.

Rich,
Hey Neophyte Here…I can be pretty dense at times, what and where is .service file in the OP?

Mike

Step 5.

Rich,
Here is my service file:

/lib/systemd/system/reelyActive.service

[Unit]
Description=reelyActive
After=network.target iptables.service firewalld.service

[Service]
Restart=always
WorkingDirectory=/reelyActive/pi-suite/node_modules
ExecStart=/reelyActive/pi-suite/node_modules/node server.js

(also tried:)
ExecStart=/usr/local/bin/node server.js
ExecStart=/home/reelyActive/pi-suite/node_modules/node server.js
ExecStart=/reelyActive/pi-suite/node_modules/sudo node server.js

[Install]
WantedBy=multi-user.target

Mike

Honestly, I haven’t done anything with RA in a couple years so I’m not going to be a whole lot of help. You might search for help on how to properly run a node.js service with systemd.

Back when I wrote the above tutorial it all just worked. I never had to deal with any problems like this.

It’s also possible that the code has changed and that 1.5 year old tutorial may no longer work.

Did you abandon using the ble detection or still use it for presence detection?

The problem is that the phones change their advertised MAC address frequently. So I could tell that an iPhone was near by, but never that my wife’s specific iPhone was near by. I suspect my new phone would behave the same. It’s a privacy feature.

Carrying around a key fob or the like really isn’t an attractive option so I stopped messing with BT detection all together.

For what I need, network detection is more than adequate to serve as presence detection.

Rich,

Agreed, my iPhone changes MAC address every time you breath. I was planning on using an Edystone for ble detection; I have one, seems to work great!. I just need to figure out the systemd problem.

Does the iPhone work with network detection if it goes into a deep sleep? I have read Mariuts28’s Tutoria and Example in Hping3 and ARP but it seems like there might be problems with the iPhone? I have an Xs and my wife has a 6s & soon to upgrade.

I am just looking for a way to speed up presence detection compared to the iCloud binding. It works but you can sit in your driveway for 5 minutes before things start happening which is not acceptable to me.

Just want you to know how much your posts have helped me out on the openHab trail. I really enjoy HA and OH has helped me fulfill my goal of localizing my HA system!

Anyway Rich, I really appreciate your input! Thank you!

When my wife had an iPhone it worked great using hping3. The hping3 stuff continues to work well with our Pixels. I run OH in Docker so couldn’t (until recently) use arping but that is reported to work well too. Though most iPhone users these days seem to use the iCloud binding.

Some have also written scripts that run on their wifi routers to report when certain devices join the network.

Hi all!

Coming late to this conversation, and with absolutely zero knowledge about OH and reelyActive, I’m just trying to evaluate if these tools are worth investing in to create the following solution:

  • Environment: schools
  • Equipment: BLE keyfob or custom wearable (under development), we can create a whitelist of authorized devices
  • Goal: determine if/when teachers, staff and children are in the school and in which classroom. The neighbour school director asked me to imagine a system which could be used on emergency conditions to display whether any people in in or out of the school, should the building be evacuated or locked down.

Constraints

  1. Schools are, by definition, installed in public areas, so many BT devices could be detected; whilelist seems mandatory to sort people out…
  2. Need to manage lots of devices: a typical school is 200 children, 15 teachers, 5 to 8 staff
  3. Need to detect several devices concurrently: up to 20 children may enter the school at the same time.
  4. Children are not so quiet when arriving at school :wink:, so the system accuracy should be high enough to discriminate when one or several children have crossed the virtual entry line and are 1m inside the school perimeter (iow “really” entered the school and not swinging across the doorstep)

Questions

I’ve read with great attention the above thread and come with a few questions:

  • I plan to put 3 receivers (Pi 0?) per classroom + 1 central computer (Pi 4?) to create a live map of all positions: is it enough? too much?
  • What’s the accuracy I can expect from such a solution (OH + reelyActive) + hw above?
  • What’s the lowest scan interval I need to achieve constraint #4?

Thanks in advance for any help!

Since these questions are really specific to the reelyActive system and not about OH, you will be better off asking the folks over at reelyActive. I don’t know if they monitor this thread or pay attention to OH much these days. But doing the sorts of things you describe sounds a lot like the sorts of things it was designed to do.

Thanks Rich, this is probably the best way to go! I’ll push my questions on to their developers’ forum…

Hi Jean-Luc and OH community,

We’ve made a lot of progress on our open source platform since this thread was last active, take a look at https://reelyactive.github.io/ which includes detailed tutorials on how to run on a Pi and do real-time location. Ping reelyActive via e-mail or social media if you have specific questions. Thanks!

Jeff

1 Like