Cheap Bluetooth antenna with raspberry pi zero

Please see my post about propagting USB Devices to the net and pick them up in openHAB

1 Like

That sounds like what I am looking for. I will test it thanks. Out of this context, would it work with Gpio ?

Find3 or ReelyActive might already do what you want but like others 'm struggling to understand what your goal is.

:joy: I try my best to explain. So imagine I have 3 raspberry pi zero with Bluetooth and wifi. I put one in the kitchen, one in the living room and the third somewhere else. First they all can see each other and so can approximate their location using rssi. My Nut can be detected by any of those raspberry pi zero and same I can approximate his position with rssi against each one. I don’t want those raspberry pi to have more logic than sending the information to openhab where I manage the automations. Does it sounds stupid ?

I don’t want my nuts to be detected!! :laughing:

1 Like

Either of those should allow you to achieve what you want to achieve. Find3’s goal is to work out which room or area a person/object is in via triangulation with the combination of signal strength bluetooth and wifi MACs. I think ReelyActive is more focused on generic presence i.e. which bluetooth MACs can I detect in my area.

Either way you’d need to run their nodes (your Raspberry Pi Zeros) and servers (maybe your OH box) but as there is no native binding for these you would probably have to write a script to query their API.

Thanks for all your answer. I will explore those solution. I really though it is a common case to do such a thing. Anyway I will do by step… Maybe first any presence near one of those node and then better location.

In addition, if have no clue if GPIO will work. But if there is a way to adress GPIO as serianl ports …

and you should have a loot at the bluetooth binding from the marketplace from @vkolotov

There is a Bluetooth binding but I don’t know how mature it is.

Have you reported the error on github (I haven’t looked at my email this morning). I can’t fix or help with problems if I don’t know they exist.

Did you install the prerequisites? In particular the MQTT connection would only report an error along those lines if you haven’t installed Paho.

From the readme

MQTT depends on the Paho library.

Have you looked at reelyActive Smart Spaces Revisited which will probably give you better results anyway? This system is designed to solve exactly this problem and the post I linked to shows how to integrate it with OH over MQTT.

Actually it will report which client the BT device is closest to and report as it moves around. The drawback is if you are trying to track a specific iPhone and some Android phones it doesn’t work because these phones spoof their BT MAC address and change them frequently so all you can really know is that AN iPhone is near a given sensor, not that a specific iPhone is near that sensor.

Honestly, I think most of us come to the realization that the benefits are not worth the effort to get it to work. Many of us also reject the requirement of having our home automation depend on the physical presence of some device on our persons at all time. Personally, I’m mostly concerned in knowing that a phone is on the premises which is a good indication that that person is home. Knowing which room the device is in might be useful only in finding where I misplaced my phone, not to drive the actual home automation.

Thanks for all your work. I did not open an issue because I felt it was me having issues because of my Python knowledge. It happen to me every time I try to use a Python library, I think I spend 80% to understand how to get the right lib and where. I still can open an issue if you wish.

First issue was about I need to change:
logger.error("%s.%s is not supported on this platform" % module_name, class_name) to logger.error("%s.%s is not supported on this platform" % (module_name, class_name)) at https://github.com/rkoshak/sensorReporter/blob/master/sensorReporter.py#L176 and L188

I installed the Paho library pip list:

bluepy (1.1.4)
chardet (2.3.0)
cryptography (1.7.1)
enum34 (1.1.6)
idna (2.2)
ipaddress (1.0.17)
keyring (10.1)
keyrings.alt (1.3)
paho-mqtt (1.3.1)
pip (9.0.1)
pyasn1 (0.1.9)
PyBluez (0.18)
pycrypto (2.6.1)
pygobject (3.22.0)
pyOpenSSL (16.2.0)
pyserial (3.4)
pyudev (0.21.0)
pyxdg (0.25)
requests (2.12.4)
RPi.GPIO (0.6.3)
scapy (2.4.0)
SecretStorage (2.3.1)
setuptools (33.1.1)
six (1.10.0)
subprocess32 (3.5.2)
urllib3 (1.19.1)
wheel (0.29.0)

But here is what I get:

2018-06-20 22:59:48,057 ERROR - mqttConn.mqttConnection is not supported on this platform

And

Jun 21 15:05:28 blea sensorReporter.py[20142]: Traceback (most recent call last):
Jun 21 15:05:28 blea sensorReporter.py[20142]:   File "/opt/sensorReporter/sensorReporter.py", line 230, in <module>
Jun 21 15:05:28 blea sensorReporter.py[20142]:     main()
Jun 21 15:05:28 blea sensorReporter.py[20142]:   File "/opt/sensorReporter/sensorReporter.py", line 71, in main
Jun 21 15:05:28 blea sensorReporter.py[20142]:     loadConfig(sys.argv[1])
Jun 21 15:05:28 blea sensorReporter.py[20142]:   File "/opt/sensorReporter/sensorReporter.py", line 222, in loadConfig
Jun 21 15:05:28 blea sensorReporter.py[20142]:     sensors[section] = createDevice(config, section)
Jun 21 15:05:28 blea sensorReporter.py[20142]:   File "/opt/sensorReporter/sensorReporter.py", line 164, in createDevice
Jun 21 15:05:28 blea sensorReporter.py[20142]:     devConns.append(connections[connStr])
Jun 21 15:05:28 blea sensorReporter.py[20142]: KeyError: 'MQTT'

So since this morning I first try what suggested Dibbler42 at the beginning. I have now in my docker container a /dev/ttyNET0 without garantie it is working. I have as well the 3rd Party Bluetooth Binding which I configured with direct regex (/dev/ttyNET0) I add an Adaptor as Thing but this last one stay offline.

I have some errors I need to check or directly try the reelyActive solution.

Did you check if the /dev/ttyNET0 gets data? If yes see if the java engine gets the port and the if the serial transport is installed. If these things are working it is a good idea to restart openHAB

Hmmm. How are you running sensorReporter?

The error is definitely caused by its inability to import paho. There are two ways to install a python library, globally or for the specific user. You might be installing it as a specific user but sensorReporter is running as a different user and that user doesn’t have paho available.

If you are not going to use sensorReporter (I’d recommend reelyActive instead anyway) don’t worry about an issue. I think the problem is a configuration problem, not something I can fix in code anyway.

Sorry I needed to take care of my kids. What is the best way to check ?

I run feature:install openhab-transport-serial in the console… Can I check there something else ?

Until now I just could check on my OH server host (not the docker container):

clement@NAS:~$ ./bled112_scanner.py -p /dev/ttyNET0
================================================================
BLED112 Scanner for Python v2013-04-07
================================================================
Serial port:	/dev/ttyNET0
Baud rate:	115200
Scan interval:	200 (250.00 ms)
Scan window:	200 (250.00 ms)
Scan type:	Passive
UUID filters:	None
MAC filter(s):	None
RSSI filter:	None
Display fields:	- Time
		- RSSI
		- Packet type
		- Sender MAC
		- Address type
		- Bond status
		- Payload data
Friendly mode:	Disabled
----------------------------------------------------------------
Starting scan for BLE advertisements...

Still fighting with the socat thing because I will need to get other bluetooth device, not only for presence.

Not sure what I will do further… I am not sure docker see correctly the socat device passed as device to the container.

After several try I face 2 issues.

  1. Make socat run in docker either by sharing device (not possible because socat use symlink). I tried with privileged to true to eliminate any isolated issue. I try to make run as a service. But exemple was given with Systemd which is a pain to make running in docker at least for me.
  2. Let’s say I went to the docker machine and manually start socat with the necessary configuration. I tried to run the Bluetooth python tool to check it works. It is looking good. But then come openhab third party Bluetooth binding where I set the device path directly instead of general regex. But the adapter I manually add stay offline. I can share the log when back to my computer.

I am taking any advice, really interested to make raspberry pi gateway using ser2ner…

PS: Location exact is only a bonus. Main purpose is like the first post shared, to be able to have deported Bluetooth or zwave using raspberry pi.

If you want to run this inside Docker you are going to have to get good at building your own custom Docker images. If you are using the official OH dinner image you need to added installation of all the stuff you need and add starting the socat stuff to entrypoint.sh. Docker images, almost as a rule, do not include systemd or upstart.

I firmly believe that pretty much every other suggestion in this thread will be less work to get working than getting socat and the Bluetooth binding working in Docker.

I believe as well that the other solutions are easier. But won’t work if I want to connect other devices.

But with perseverance I now able to run socat and openhab thanks to supervisord in the container. Openhab run but cannot connect to the bluetooth when this works within the container:

root@NAS:/openhab# ./bled112_scanner.py -p /dev/ttyNET0
================================================================
BLED112 Scanner for Python v2013-04-07
================================================================
Serial port:	/dev/ttyNET0
Baud rate:	115200
Scan interval:	200 (250.00 ms)
Scan window:	200 (250.00 ms)
Scan type:	Passive
UUID filters:	None
MAC filter(s):	None
RSSI filter:	None
Display fields:	- Time
		- RSSI
		- Packet type
		- Sender MAC
		- Address type
		- Bond status
		- Payload data
Friendly mode:	Disabled
----------------------------------------------------------------
Starting scan for BLE advertisements...

Does not find anything but at least no errors.

And I have this in the container:

root@NAS:/openhab# ls -al /dev/ttyNET0
lrwxrwxrwx 1 root root 10 Jun 26 01:59 /dev/ttyNET0 -> /dev/pts/0

while writing it I realise it creates it under root:root… I specified openhab:dialout in socat command there: (still work if I login as openhab and run ./bled112_scanner.py -p /dev/ttyNET0

[program:socat]
command=/usr/bin/socat -d -d pty,link=/dev/ttyNET0,raw,user=openhab,group=dialout,mode=777 tcp:192.168.178.84:3001
autorestart=true

But on openhab side with the third party bluetooth binding I get the following:

01:52:48.903 [WARN ] [er.transport.bluegiga.BluegigaHandler] - Timeout has happened while sending a transaction, retry one more time: BlueGigaEndProcedureCommand
01:52:58.904 [WARN ] [er.transport.bluegiga.BluegigaHandler] - Timeout has happened second time, giving up: BlueGigaEndProcedureCommand
01:52:58.931 [WARN ] [er.transport.bluegiga.BluegigaFactory] - Error occurred while creating a new adapter for port: /dev/ttyNET0, Could not initialize blugiga handler for port: /dev/ttyNET0

On the pi the netstat command gives

tcp6     233      0 192.168.178.84:3001     192.168.178.29:35734    ESTABLISHED -

Going forward…

???

reelActive has a central server and clients. Each client uses its own BT device and reports the signal strength of all the BT devices that it sees. The server looks at all the reports from all the clients and reports to OH which client has the strongest signal and therefore telling you which room the BT device is in. It solves EXACTLY your problem.

Similarly, sensorReporter is designed to run on more than one Raspberry Pi (or other computers) and report to OH when it can see a BT device. Slight modifications will let it report the RSSI (I’d even make the modifications for you). So sensorReporter nearly solves EXACTLY your problem, though determining which RPi the BT device is closest to will have to be done by Rules.

Somewhat differently, FIND triangulates the location of your phone based on the signal strength of all the wifi APs the phone can see. So this solves your problem, but uses wifi instead of BT.

There is no limitation to connecting to only one BT device in ANY of these solutions.

Just so you know guys @rlkoshak @clempat, the 3rd party bluetooth binding is supposed to do indoor positioning as well. It accumulates RSSI readings from all adapters and calculates shortest distance from bt device to installed adapters. Obviously you will need to have an adapter in each room.

What kind of adapters you are using? Generic USB or BlueGiga?