Page 5 of 19

Re: How to check presence of Beacon ?

Posted: Friday 13 May 2016 14:31
by blackdog65
for this purpose there's no need for domoticz, just a running copy of raspian (or flavour of choice). I actually do use a domoticz image by habit because as a non programer I can add to that raspi via gpio or piface or MySensors usb gateway and it can then (as in my poly tunnel) work independantly and communicate 2-way with the master domoticz.

But as I say, for these BT setups it's just there unused for now.

Sean

Re: How to check presence of Beacon ?

Posted: Friday 13 May 2016 19:40
by jmleglise
Hi everyone,

Could you please, resume all the problems you have, (with errors output, and maximum information. distrib of your Linux...) and all the testings you have made without success.

I will have a look this wk.

thank you,

Re: How to check presence of Beacon ?

Posted: Saturday 14 May 2016 12:59
by blackdog65
jmleglise wrote:Hi everyone,

Could you please, resume all the problems you have, (with errors output, and maximum information. distrib of your Linux...) and all the testings you have made without success.

I will have a look this wk.

thank you,
Hi Buddy! :D

Provided that my units run using the cron script, I'm happy. It's what my American friend calls "A $10 call girl. Not pretty, but gets the job done." :lol:
However they work and can either set a variable or switch (depending which version of the .py script I use).

My big desire is to harvest the RSSI into a variable that I can use to mark specific locations reasonably accurately. At the moment, with 4 devices, I have 4 overlapping circles which is not very accurate at all... But still VERY useful :D

Huge thanks for your hard work

Sean (Jean en français) :lol:

Re: How to check presence of Beacon ?

Posted: Saturday 14 May 2016 13:38
by Westcott
What sort of range is everybody getting, using which beacons and receivers?

I've had a look at the Python script, it will take a little bit of work to get it to send both presence and strength.
One way would be to extend a beacon's definition to add an idx for strength.

Re: How to check presence of Beacon ?

Posted: Saturday 14 May 2016 15:31
by blackdog65
Hi Westcott,
I quite agree, though I don't know how.
As I said in a previous post, the signal strength isn't linear i.e. drops by 10 per 2 paces. Also it's affected by obstacles, signal bounce and other factor such as manufacturer.
RSSI-Value-Changes-By-Distance.png
RSSI-Value-Changes-By-Distance.png (11.53 KiB) Viewed 3122 times
From http://blog.bluetooth.com/proximity-and-rssi/

I've found that a stationary Nut Tag's RSSI can fluctuate by about 5 points give or take, although a script could take an average over a given time.
All my RSSI readings are dramatically affected by my crazy thick walls which makes life difficult for all wireless tech :(
I'd like to find the RSSI average for say 3 raspis for a nut being at point "X" and a script, when seeing those parameters met, can say with some confidence that the Nut has reached point "X".

Re: How to check presence of Beacon ?

Posted: Saturday 14 May 2016 19:30
by jmleglise
Hi,

This is version 1.3

Code: Select all

wget https://raw.githubusercontent.com/jmleglise/mylittle-domoticz/master/Presence%20detection%20%28beacon%29/check_beacon_presence.py
- Script takes care of hciconfig. switch down , then UP the bluetooth adapter. And report to log each error. So no need to use any more hciconfig before launching the script.
- script operates now in 2 mode. Choose for each beacon wich one you want :
REPEAT MODE : When beacon is in range, update the uservariable every 3 secondes with the RSSI. And "AWAY" otherwise.
SWITCH_MODE : When beacon is in range, update only 1 time the uservariable with "HOME". And "AWAY" otherwise.

Kind regard,

Re: How to check presence of Beacon ?

Posted: Saturday 14 May 2016 21:29
by Raspberry Piet
jmleglise wrote:Hi,

This is version 1.3
Just tried your excellent script, works great with Nut Beacons. Detection is very fast!
As i understand it will scan only for BLE devices and not also for ordinary bluetooth devices like smartphones?

Thanks for the script!

Re: How to check presence of Beacon ?

Posted: Saturday 14 May 2016 22:18
by woody4165
Thanks!!!
It's working like a charm also with me and without the hciconfig stuff in crontab

Is it correct the in the /etc/init.d/check_presence_beacon I need to have DAEMON=root and not =pi?

I tried with pi and I get the active(exited) instead of active(running) in the status.

Maybe I'm asking too much, but it would be nice to have a switch to get the status instead of HOME/AWAY and an uservariable to get the RSSI.

Thanks

Re: How to check presence of Beacon ?

Posted: Saturday 14 May 2016 22:51
by jmleglise
Thank you, you're welcome !

@ Raspberry Piet : this script is only for BLE 4.0
Bluetooth and bluetooth 4.0 are 2 protocols totally different. For Bluetooth, there are already severals solutions in the forum

Yes, fast detection is a must have. I choose this technology to be fast enough, to enter my house and desactivate my alarm before Alarm detection.

@woody :
Yes, for me too, root owner is needed for the DAEMON. I haven't undestood why.

For the switch, you can do it easily yourself.
Create a LUA script_device : On uservariablechange then : if uservariable=="AWAY" then switch Off else switch On

Re: How to check presence of Beacon ?

Posted: Sunday 15 May 2016 15:00
by Raspberry Piet
jmleglise wrote:I choose this technology to be fast enough, to enter my house and desactivate my alarm before Alarm detection.
What about the possibility of the mac address could be spoofed?

Re: How to check presence of Beacon ?

Posted: Sunday 15 May 2016 23:37
by jmleglise
I think that someone able to spoof macAddress or jam a wireless Alarm has better to rob than my home :lol:

To such a degree that I have let the Mac Address in the source code of my script ! :lol:


(Seriously : you 're right : it's possible to change mac address on some bluetooth adapter).

Re: How to check presence of Beacon ?

Posted: Monday 16 May 2016 0:22
by korniza
jmleglise wrote:I think that someone able to spoof macAddress or jam a wireless Alarm has better to rob than my home :lol:

To such a degree that I have let the Mac Address in the source code of my script ! :lol:


(Seriously : you 're right : it's possible to change mac address on some bluetooth adapter).
Still you can bond the NUT with another device (for example get nfc tag sticker to your NUT). ;) and use it as a second layer of id.

Re: How to check presence of Beacon ?

Posted: Monday 16 May 2016 12:23
by Raspberry Piet
It is possible with the Nut app to make the Nut Beacon beep (find keys when lost), is it somehow possible to do the same through a script?

Re: How to check presence of Beacon ?

Posted: Monday 16 May 2016 20:12
by blackdog65
Hi guys,

I've found time this evening to have a play with the new script (which works beautifully thank you jmeglise!) but as I mainly use blockly I've hit a snag (maybe not for lua) in that the numeric RSSI output (i.e. -74) is a string and needs to be in the " " blockly block and so will not work with operators such as ≥ ≤ etc.

Is there a simple lua method of asking "if string_variable_x ≤ -51 or ≥ -71 then xxxxx" or does the string need to be "converted" to an integer.

Please excuse my ignorance but I speak more Russian than I do Lua :lol:

Sean
PS I agree with the beeping nut idea... my wife will lose hers on day one :roll:

Re: How to check presence of Beacon ?

Posted: Monday 16 May 2016 20:17
by jvdz
This will test the numeric value of the string in LUA:

Code: Select all

if tonumber(string_variable_x) <= -51 or tonumber(string_variable_x) >= -71 then
Should it be between those 2 values ( AND relation) or do you really mean an OR relation here?

Jos

Re: How to check presence of Beacon ?

Posted: Monday 16 May 2016 20:31
by blackdog65
WOW! That was quick!
Hi Jos,

Yes I'm looking for a value between the two values inclusive

Many thanks

Sean

Re: How to check presence of Beacon ?

Posted: Monday 16 May 2016 20:36
by jvdz
blackdog65 wrote:Yes I'm looking for a value between the two values inclusive
So that means you need an and in the logic:

Code: Select all

if tonumber(string_variable_x) <= -51 and tonumber(string_variable_x) >= -71 then

Re: How to check presence of Beacon ?

Posted: Monday 16 May 2016 20:38
by blackdog65
brilliant! I'll soon be writing lua like... well an amateur, but I'm trying. :lol:

many thanks again for your help

Sean

Re: How to check presence of Beacon ?

Posted: Monday 16 May 2016 21:09
by woody4165
I would like to use the new RSSI to trigger based on value what to do, but I don't understand what to trigger and how.

With the AWAY/HOME I had a script based on uservariable event like this:

Code: Select all

commandArray = {}

if uservariablechanged['NutG'] == "AWAY" then
        commandArray['OpenURL']="https://api.telegram.org/botxxx/sendMessage?chat_id=xxx&text=yyyyyy"
elseif  uservariablechanged['NutG'] == "HOME" then
        commandArray['OpenURL']="https://api.telegram.org/botxxx/sendMessage?chat_id=xxx&text=yyyyyy"
elseif  uservariablechanged['NutC'] == "AWAY" then
        uservariables['orauscita'] = os.time()
        commandArray['OpenURL']="https://api.telegram.org/botxxx/sendMessage?chat_id=xxx&text=yyyyyy"
        commandArray['PresaGiu']='Off'	
elseif  uservariablechanged['NutC'] == "HOME" then
        nuovaora=os.time()
        differenza = nuovaora - uservariables['orauscita']
        if ((differenza > 300) and (otherdevices['IsDark']=="On")) then
        commandArray['OpenURL']="https://api.telegram.org/botxxx/sendMessage?chat_id=xxx&text=yyyyyy"
            commandArray['PresaGiu']='On'	
        end
end

return commandArray
Now with a continuos update of the value of the uservariables, I understood, maybe I'm wrong, that the script have to be device event type, and not uservariable.

Then, what I should trigger to have a functionality like the previous one, based this time on RSSI values ?

Thanks

Re: How to check presence of Beacon ?

Posted: Monday 16 May 2016 21:18
by blackdog65
Lolz @ Woody :lol:
I'm in the same position.
I have just tried this with help from Jos

Code: Select all

commandArray = {}
for variableName,variableValue in pairs(uservariablechanged) do
	if (variableName=='Zhenya_SitRm') then
	if tonumber(variableValue) <= -51 and tonumber(variableValue) >= -71 then
            commandArray['ZSitRoomBT'] = "On"
        end
    end
    if (variableName=='Zhenya_SitRm') then
        if variableValue == "AWAY" then
            commandArray['ZSitRoomBT'] = "Off"
        end
    end
end
return commandArray
Where "ZSitRoomBT" is a virtual switch for testing

but it doesn't work (I don't get lua yet :roll: )
In the log I get

Code: Select all

[string "-- script_variable_bt.lua..."]:5: attempt to compare nil with number
Help!!! :cry: