Python plugin: Bluetooth Beacon Presence Detection

Python and python framework

Moderator: leecollings

EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by EddyG »

I tried TCP/IP, but the same problem exists with the 127.0.0.1 address.
lamouette
Posts: 37
Joined: Friday 20 January 2017 8:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by lamouette »

works like a charm, many thanks !
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by schulpr »

Hi,

For some reason I can't get auto starting to work after a reboot of my pi (with stretch lite).

After a manual start it works flawless.

I hope that someone can help me further with this.

Kind regards, Rob
mrinner
Posts: 56
Joined: Tuesday 22 August 2017 20:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Belarus
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by mrinner »

@schulpr

ble_scanner.sh added as service?
If yes, try to update locally this line in ble_scanner.py to 10+ attempts.
https://github.com/mrin/domoticz-bt-pre ... er.py#L177
By default ~ 25sec (5 attempts * 5sec sleep) for check hci is RUNNING.
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by schulpr »

@mrinner

I increased the setting to 25 but that doesn't help. I just followed the steps as described. I didn't add any lines to a script. Do I need to?

Thanks for your help!

Rob
mrinner
Posts: 56
Joined: Tuesday 22 August 2017 20:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Belarus
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by mrinner »

Can you see which status when service not started:
sudo service ble_scanner status

Also then try to run "hciconfig" without "sudo" and check string "RUNNING" in output.
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by schulpr »

Hi,

This is the output with "sudo service ble_scanner status":
Dec 10 14:47:08 raspberrypi sudo[389]: pam_unix(sudo:session): session closed for user root
Dec 10 14:47:09 raspberrypi sudo[412]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/local/bin/hciconfig hci0 up
Dec 10 14:47:09 raspberrypi sudo[412]: pam_unix(sudo:session): session opened for user root by (uid=0)
Dec 10 14:47:10 raspberrypi sudo[412]: pam_unix(sudo:session): session closed for user root
Dec 10 14:47:10 raspberrypi sudo[423]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/local/bin/hciconfig hci0 down
Dec 10 14:47:10 raspberrypi sudo[423]: pam_unix(sudo:session): session opened for user root by (uid=0)
Dec 10 14:47:10 raspberrypi sudo[423]: pam_unix(sudo:session): session closed for user root
Dec 10 14:47:11 raspberrypi sudo[481]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/local/bin/hciconfig hci0 up
Dec 10 14:47:11 raspberrypi sudo[481]: pam_unix(sudo:session): session opened for user root by (uid=0)
Dec 10 14:47:12 raspberrypi sudo[481]: pam_unix(sudo:session): session closed for user root

hciconfig gives:
hci0: Type: BR/EDR Bus: USB
BD Address: 00:15:83:EE:93:F0 ACL MTU: 310:10 SCO MTU: 64:8
UP RUNNING
RX bytes:3162 acl:0 sco:0 events:132 errors:0
TX bytes:1932 acl:0 sco:0 commands:99 errors:0

In the domoticz log I see a lot of lines with:
Calling message handler 'onHeartbeat'.

But the switches are staying off.

Does this info tell you something?

Regards, Rob
mrinner
Posts: 56
Joined: Tuesday 22 August 2017 20:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Belarus
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by mrinner »

In logs I see several attempts to startup and seems like hci0 was not ready.
In the domoticz log I see a lot of lines with:
Calling message handler 'onHeartbeat'.
in Debug plugin mode this is ok. Plugin checks timeout expiration on each heartbeat.

I will add debug logging in file as option for ble_scanner, maybe on this week.
mrinner
Posts: 56
Joined: Tuesday 22 August 2017 20:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Belarus
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by mrinner »

@schulpr

Logging in file added. Just git pull updates and uncomment lines in ble_scanner.sh
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by schulpr »

@ mrinner,

My knowledge is between noob and hard learning beginner. Can you please help me a bit further? Were do I add this command? In the folder were the plugin is it doesn't work.

Thanks for your help!

Rob
mrinner
Posts: 56
Joined: Tuesday 22 August 2017 20:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Belarus
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by mrinner »

Go to the plugin folder "bt-presence", then "git pull"
Then "nano ble_scanner.sh" and uncomment lines + check path to log file:

Code: Select all

DAEMON_ARGS="$DAEMON_ARGS --log /home/pi/domoticz/plugins/bt-presence/ble_scanner.log"
DAEMON_ARGS="$DAEMON_ARGS --loglevel debug"
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by schulpr »

Hi again,

That was easy :-). I got an error in the update process because it refused to override my config file. I decided to delete the current version and start all over again. Something strange happened, it worked!

So I tried another reboot and it didn't worked anymore. In the log everything seems fine, the process is running correct.

What it doesn't do is switch the switch that is created. I renamed it but that should be the problem I think? This is the content of the log file:

2017-12-15 11:25:26 - INFO - Ok hci0 interface Up n running !
2017-12-15 11:25:28 - DEBUG - new bt socket
2017-12-15 11:25:28 - DEBUG - Connected to bluetooth device hci0
2017-12-15 11:25:35 - INFO - ed:6a:79:4d:7f:76 RSSI -74 - NUT1
2017-12-15 11:25:35 - INFO - ed:6a:79:4d:7f:76 RSSI -78 - NUT1
2017-12-15 11:25:43 - INFO - ed:6a:79:4d:7f:76 RSSI -69 - NUT1
2017-12-15 11:25:47 - INFO - ed:6a:79:4d:7f:76 RSSI -78 - NUT1
2017-12-15 11:26:03 - INFO - ed:6a:79:4d:7f:76 RSSI -75 - NUT1
2017-12-15 11:26:07 - INFO - ed:6a:79:4d:7f:76 RSSI -75 - NUT1
2017-12-15 11:26:15 - INFO - ed:6a:79:4d:7f:76 RSSI -78 - NUT1
2017-12-15 11:26:23 - INFO - ed:6a:79:4d:7f:76 RSSI -69 - NUT1
2017-12-15 11:26:30 - INFO - ed:6a:79:4d:7f:76 RSSI -75 - NUT1
2017-12-15 11:26:34 - INFO - ed:6a:79:4d:7f:76 RSSI -70 - NUT1
2017-12-15 11:26:38 - INFO - ed:6a:79:4d:7f:76 RSSI -78 - NUT1
2017-12-15 11:26:42 - INFO - ed:6a:79:4d:7f:76 RSSI -75 - NUT1
2017-12-15 11:26:46 - INFO - ed:6a:79:4d:7f:76 RSSI -69 - NUT1
2017-12-15 11:26:50 - INFO - ed:6a:79:4d:7f:76 RSSI -79 - NUT1
2017-12-15 11:26:53 - INFO - ed:6a:79:4d:7f:76 RSSI -75 - NUT1
2017-12-15 11:26:57 - INFO - ed:6a:79:4d:7f:76 RSSI -69 - NUT1

I doesn't grow any further than this.

This is the log when I start the process in terminal:

pi@raspberrypi:~/domoticz/plugins/bt-presence $ sudo ./ble_scanner.py
2017-12-15 11:37:05 - INFO - Ok hci0 interface Up n running !
2017-12-15 11:37:07 - DEBUG - new bt socket
2017-12-15 11:37:07 - DEBUG - Connected to bluetooth device hci0
2017-12-15 11:37:15 - INFO - ed:6a:79:4d:7f:76 RSSI -78 - NUT1
2017-12-15 11:37:19 - INFO - ed:6a:79:4d:7f:76 RSSI -74 - NUT1
2017-12-15 11:37:27 - INFO - ed:6a:79:4d:7f:76 RSSI -74 - NUT1
2017-12-15 11:37:30 - INFO - ed:6a:79:4d:7f:76 RSSI -74 - NUT1
2017-12-15 11:37:38 - INFO - ed:6a:79:4d:7f:76 RSSI -80 - NUT1
2017-12-15 11:37:42 - INFO - ed:6a:79:4d:7f:76 RSSI -69 - NUT1
2017-12-15 11:37:50 - INFO - ed:6a:79:4d:7f:76 RSSI -74 - NUT1
2017-12-15 11:37:54 - INFO - ed:6a:79:4d:7f:76 RSSI -69 - NUT1
2017-12-15 11:37:57 - INFO - ed:6a:79:4d:7f:76 RSSI -78 - NUT1
2017-12-15 11:38:01 - INFO - ed:6a:79:4d:7f:76 RSSI -75 - NUT1
2017-12-15 11:38:05 - INFO - ed:6a:79:4d:7f:76 RSSI -69 - NUT1
2017-12-15 11:38:09 - INFO - ed:6a:79:4d:7f:76 RSSI -78 - NUT1
2017-12-15 11:38:13 - INFO - ed:6a:79:4d:7f:76 RSSI -75 - NUT1
2017-12-15 11:38:17 - INFO - ed:6a:79:4d:7f:76 RSSI -69 - NUT1
2017-12-15 11:38:21 - INFO - ed:6a:79:4d:7f:76 RSSI -78 - NUT1
2017-12-15 11:38:24 - INFO - ed:6a:79:4d:7f:76 RSSI -75 - NUT1
2017-12-15 11:38:28 - INFO - ed:6a:79:4d:7f:76 RSSI -69 - NUT1
2017-12-15 11:38:32 - INFO - ed:6a:79:4d:7f:76 RSSI -79 - NUT1
2017-12-15 11:38:36 - INFO - ed:6a:79:4d:7f:76 RSSI -75 - NUT1
2017-12-15 11:38:40 - INFO - ed:6a:79:4d:7f:76 RSSI -69 - NUT1
2017-12-15 11:38:44 - INFO - ed:6a:79:4d:7f:76 RSSI -78 - NUT1
2017-12-15 11:38:48 - INFO - ed:6a:79:4d:7f:76 RSSI -74 - NUT1
2017-12-15 11:38:51 - INFO - ed:6a:79:4d:7f:76 RSSI -80 - NUT1
2017-12-15 11:38:55 - INFO - ed:6a:79:4d:7f:76 RSSI -80 - NUT1
2017-12-15 11:38:59 - INFO - ed:6a:79:4d:7f:76 RSSI -74 - NUT1

This turns my switch on and doesn't stop.

I hope this helps to find a solution.

Thanks once more!

Rob
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by deennoo »

Have you try to use a synology as a "scanner" ?

Thanks for this plug in, will try it on serval device (rooted android tv box)
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
mrinner
Posts: 56
Joined: Tuesday 22 August 2017 20:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Belarus
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by mrinner »

@schulpr

You can rename created devices as you want, plugin does not relying on name.
First log was immediately after the reboot and log did not grow anymore and "sudo service ble_scanner status" is "active (running)"?
Check what you not run 2 services on the one machine, or some other process maybe use BT.. Discovering can be stopped when hci going down, or bt connecting to some device by other process...
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by EddyG »

At the battery check one of my Nut3 came back with only 2 chars.
I had to add/change:

Code: Select all

        bin_value = gatt_output[gatt_output.find("value:") + 6:]
        if len(bin_value) == 2:
             bin_value = bin_value + "00"
        bin_value = bin_value.decode("hex")
chrispazz
Posts: 81
Joined: Friday 08 July 2016 10:38
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by chrispazz »

Which is the correct configuration for having correct battery charge reporting with a NUT2?

Thanks
chrispazz
Posts: 81
Joined: Friday 08 July 2016 10:38
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by chrispazz »

With latest domoticz beta BLE device are no more updating from BLE Scanner....
chrispazz
Posts: 81
Joined: Friday 08 July 2016 10:38
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by chrispazz »

I am the only using this plugin with latest beta?
mrinner
Posts: 56
Joined: Tuesday 22 August 2017 20:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Belarus
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by mrinner »

@chrispazz

I'm on 3.8805 - my setup works perfect.
Many people have problems with the python plugin system on latest beta...
chrispazz
Posts: 81
Joined: Friday 08 July 2016 10:38
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Bluetooth Beacon Presence Detection

Post by chrispazz »

@mrinner

thank you for answering me :)

I am on 3.8850 and plugin is running ok looking at logs.
It only seems not to update the devices....

2018-01-26 22:32:00.995 (BLE Presence) Update NUT Green: nValue 1 - sValue 100 - BatteryLevel 255
2018-01-26 22:32:01.598 (BLE Presence) Update NUT White: nValue 1 - sValue 100 - BatteryLevel 255
2018-01-26 22:32:04.855 (BLE Presence) Update NUT Green: nValue 1 - sValue 100 - BatteryLevel 255
2018-01-26 22:32:05.459 (BLE Presence) Update NUT White: nValue 1 - sValue 100 - BatteryLevel 255
2018-01-26 22:32:08.717 (BLE Presence) Update NUT Green: nValue 1 - sValue 100 - BatteryLevel 255
2018-01-26 22:32:09.371 (BLE Presence) Update NUT White: nValue 1 - sValue 100 - BatteryLevel 255
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest