Just wondering if anyone has experimented with Bluetooth presence detection on the HAH? I searched the forums and found that although the LiveBox may have Bluetooth it cannot be used due to lack of drivers?
Could an external Bluetooth dongle be added via the USB host port (and a USB hub as this port is already used for CurrentCost and JeeNodes)?
Member for
15 years 1 monthSound interesting
Would the iPhone geofencing attribute be able to be used instead?
Member for
15 years 7 monthsInteresting idea. I have
Interesting idea. I have often thought presence detection would be useful but not thought of how to implement it. Must admit though Bluetooth is over my head at the moment but I would love to see it implemented.
Is this something your capable of testing? Would be willing to beta test for you :)
sure Brett will have some thoughts on the feasability of this.
garry
Member for
15 years 7 monthsAnother option
How about putting this project on a jeenode.
http://www.fritz-hut.com/2012/08/26/bluetooth-presence-detection/
This will allow really simple integration via the existing hardware. Would just need a bluenode applet writing.
this might be my Xmas project I think!
There are cheap bluetooth serial devices available too
http://www.ebay.co.uk/itm/1x-Wireless-Bluetooth-Serial-Transceiver-Modu…
cheers
G
Member for
16 years 10 monthsA bluetooth node would be the
A bluetooth node would be the way to go. This way it keeps the hardware out of the HAH system, and makes it more independent of the control head.
Much like the serial relay board I coded up recently. Its a complely self contains xAPBSC compliant node.
http://www.dbzoo.com/livebox/ethrelay
I would do the same sort of thing with bluetooth. A bluetooth unit mounted onto top of some motherboard carrier which recieves the signal and pumps out some xAP packet to let you know when another bluetooth device is in range. That xAP packet would be pushed straight down an ethernet cable, or out via RF if you wish so you could HahNode enable it.
After that its just LUA scripting on the HAH to decide what to do next.
Brett
Member for
13 years 7 monthsiPhone geofence
To allanayr. I have not looked in to this but believe this is a function that runs on the phone. A app can launch or be sent a message on arrival or leaving a defined zone. This would require an iPhone app to perform an action (e.g. Connect via iServer and post a message in?). The advantage of the Bluetooth address solution is it should work with any Bluetooth device you carry.
Member for
13 years 7 monthsHi Garry, Brett, Thank you
Hi Garry, Brett,
Thank you both for your input. Sounds like a Bluetooth node may be the way to go. I'm going to check whether a HC-05 is required as opposed to HC-06 (fuller AT command set). The link I posted uses l2ping to check if a known Bluetooth address is in range rather than just performing a Bluetooth discovery. Devices respond to the ping even if the device is not discoverable, you don't need to leave your phone/device discoverable.
Presumably you can connect a basic I2C EEPROM or similar to a JeeNode to persist the list of Bluetooth addresses to poll/report or alternatively just use the list of paired devices from the Bluetooth device?
I'll post again if I get anywhere with this over Christmas, I still have to build my HAHNode and room node and get them running first.
Member for
17 yearsEEPROM in jeeNodes
The AVR 328 chip has 1K bytes of EEPROM - a few of these are used by the roomNode code but loads of space left.
It would be easy enough to modify the hardware on the etherRelay to hold a bluetooth device, there are spare I/O pins exposed on unpopulated connector pads.
Cheers,
Derek.
Member for
15 years 1 monthYou're quite right that
You're quite right that bluetooth is probably more flexible and reliable.
This project:
http://www.automatedhome.co.uk/new-products/hack-your-heating-using-an-…
is something that I found which uses an interesting take on geofencing to control heating.
As my heating is already controlled by the HAH the hardware extension would be unnecessary and therfore just a bit of lua scripting would probably achieve the same result. (OK I admit it, I don't really do hardware so I'm always looking for a software only solution:-)
Member for
13 years 11 monthsGreat idea using BT for
Great idea using BT for general presence detection, if you wanted to step it up a gear and have more refined presence detection you could also look into NFC
technology, I plan to use this at home to direct music streaming to specific bluetooth speakers using my Galaxy S4 which is NFC enabled.
NFC module
Cheers
Andrew
Member for
13 years 7 monthsAllan,I guess if the app
Allan,
I guess if the app could send a tweet on geo change you have everything you need as the xap twitter can get you to lua. IFTTT may convert an email to a tweet if not?
Derek,
Thanks for the info. I've ordered a HC-05. I'll experiment with the AT commands first and then if that works go for a relay module to convert to xap.
Andrew,
Could you just program an NFC tag at each speaaker? You can program them to perform Bluetooth pairing or to visit a URL when scanned by your phone?
Member for
13 years 11 monthsHi Bob, yep exactly the idea.
Hi Bob, yep exactly the idea.
Member for
15 years 7 monthsYour are quite right, hc05
Your are quite right, hc05 required rather than hc06.
i now have one on the way from china, in the meantime I'll have a go at coding a jeenode and lua applet up based on the data sheet and test via dummy serial commands from a PC. Due to existing hardware being present on my system I am opting to integrate via jeenode rf back to the HAHcentral/serial route.
I'll post if I have any success.
Garry
Member for
16 years 10 monthsThese hc05's look fun I'll
These hc05's look fun I'll buy one as well and we can all have a hack fest on it.
Brett
Member for
14 years 5 monthsordered :) let the hack fest
ordered :) let the hack fest begin
Member for
13 years 11 monthsOrdered - will pass the time
Ordered - will pass the time over the holidays when im eating Turkey :)
...maybe i should have chose a UK seller...
Member for
15 years 1 monthWhew! What a big subject
Whew! What a big subject presence detection is. I (and Mr Google) have had a look at a few things over the last
couple of days and there's a lot of stuff about how difficult it is to make sense of.
I'm sure that you hardware guys will have a good time hacking the HC-05 and that may be the best route, but perhaps
an alternative is to use a Raspberry Pi. I have one sitting next to my HAH anyway so I've had a look at doing stuff
with a blue tooth dongle inserted in it.
Here's a few observations:
This site:
http://www.perceptiveautomation.com/userforum/viewtopic.php?f=4&t=4894&…
uses a cron setting and a couple of bash scripts to detect phones using wifi
cron:
# detect iPhone on network
*/1 * * * * ~/bin/iphonecron &> /dev/null
iphonecron
#!/bin/bash
for((i=1; $i<=12; i=$(($i+1)))); do
~/bin/iphonecheck
sleep 4
done
iphonecheck
#!/bin/bash
IPHONELASTONLINE=`cat /tmp/iphonestate 2>/dev/null`
ISONLINE="false"
/sbin/ping -t 1 -c 1 192.168.1.117 &>/dev/null && ISONLINE="true" && sleep 1
if [[ "$ISONLINE" != "$IPHONELASTONLINE" ]]; then
osascript -e "tell application \"IndigoServer\" to set value of variable \"PresenceiPhone\" to \"$ISONLINE\""
fi
echo $ISONLINE > /tmp/iphonestate
I don't think that wifi really works but the ping can be changed to l2ping and the bluetooth MAC address and it seems
to work OK. Also with bluetooth it's not required to do the check every 5 seconds because bluetooth will get a response
more reliably than wifi. That said, not all bluetooth pings are reliable, iPhone's don't respond to l2ping when asleep
but my old motorola seems fairly reliable.
Obviously I don't do the "Indigoserver" stuff above. I'm working on a python script which just reads /tmp/iphonestate
and serves it up to a socket which the HAH could listen on.
The python script will probably be something like this:
from subprocess import *
import os
import socket
# new style - subprocess
phonecheck = Popen("cat /tmp/iphonestate",shell=True, stdout=PIPE).stdout
while 1:
line = phonecheck.readline()
if not line: break
lastword = line
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(('192.168.0.2', 8089))
clientsocket.send(lastword)
After that it would be just a lua script on the HAH to decide what to do with the information.
Member for
15 years 7 monthsAnother equally valid method
Another equally valid method if you have the pi and bluetooth dongle available.
Bit concerned to hear iphone won't respond to bluetooth ping when asleep though. What about a device scan? I'll have to have a play, as device scanning was the basis of the hc05 integration.
Member for
15 years 1 monthNot 100% sure, so other views
Not 100% sure, so other views would be welcome, but neither my iPhone 3GS nor the wife's 4S respond to a scan or a ping when asleep. Perhaps I'm doing something wrong and (like you) I'd kinda hoped that the iPhone could be the basis of the presence detection.
When I switch bluetooth on on the iphones and they are discoverable they show up on a scan and also respond to a ping but when they are asleep I can't seem to get any response.
I haven't tried yet but it looks like it might be possible to setup the iPhone "Find My Friends" app to generate an email notification which could then be converted to a tweet by IFTTT. An issue with that would be the reliability of the app and the time lag between the notification and the tweet actually doing anything useful on the HAH. The site I mentioned above does discuss the possibility of forcing the iphone to wake up by sending some kind of push notification to it, but at that point I feel it's becoming to cumbersome to be useful. Having said that, if it's a case of adjusting a thermostat when the house is empty then even a 20 minute delay wouldn't really be an issue.
Look forward to hearing anyone else's experience of pinging sleeping iPhones.
Just found this on the Dreamgreenhouse site:
iPhones don't enable Bluetooth unless they are paired to one or more devices. The iPhone 3GS doesn't respond to pings and always appears off-line though.
I don't think either of the iPhones I've tried is paired to anything (is there actually anything that you can pair to that is worthwhile?? :-(. So perhaps that is part of the issue.
Member for
13 years 7 monthsSounds like you've gone down
Member for
15 years 1 monthMy iPhone is a 3GS on iOs 6
My iPhone is a 3GS on iOs 6 and my wife has a 4S on iOs 7. I've just dug out an old bluetooth headset to see if I can get it to pair with the 4S (it'll need a couple of hours charging first though). The pi can certainly send UDP data though whether it's possible to make them into xap packets I'm not sure. The HAH example lua scripts have a tcpRelayApplet which I thought could be used as the basis for an applet to pick up a tcp message from the pi and convert it to a xap message.
I'll see what a charged up bluetooth headset achieves tomorrow.
Member for
15 years 1 monthGood news. Having paired the
Good news. Having paired the iPhone 4S with a bluetooth headset it looks as though it now responds to pings when asleep. Even better news is that the 3GS also appears to respond to pings when asleep having also been paired to the headset. They seem to have reasonable range though the ping time seems fairly meaningless, in my house at least, it can vary quite considerably even within the same room.
Slightly less encouragingly the Raspi seems to hang up if left for long periods pinging the phones every minute. This may be partly due to the cheapo bluetooth dongle and the fact that the USB ports on the pi are not that reliable. I'll have to see how it goes over the longer term.
Member for
15 years 1 monthAs a second option I now have
As a second option I now have a python script working on th pi that handles both the pinging
and transmitting to the HAH just in case the cron/bash script combo proves to be too flaky.
The python script pings the phones and then transmits the result as a UDP datagram. This is
picked up by the udp2xap.lua program running on the HAH and converted to an xap message which
in xfxviewer looks like this:
xap-header
{
uid=FF00CC00
source=dbzoo.lua.socket
hop=1
class=udp.data
v=12
}
body
{
port=41737
data=3GS away
ip=192.168.0.3
}
It looks like presence detection using bluetooth is very doable.
The next stage of actually deciding how to use the information might be more challenging!
Member for
13 years 7 monthsHi Allan,Sounds like you have
Hi Allan,
Sounds like you have been busy. Good news that the iPhone issue is resolved and you have communication to xap. Would the python library used here run on the PI http://www.dbzoo.com/livebox/hah_xap_python ?
Member for
15 years 1 monthI'm sure that that's the
I'm sure that that's the intention, thought I have no experience of using Python on the HAH. Lua seems to be the scripting language of choice on the HAH because it runs natively and is probably as flexible as Python. I'm pretty sure that the simple Python script that I'm using on the pi will be easily translated into Lua.
Member for
13 years 7 monthsI thought the python xap
Member for
15 years 1 monthSorry misunderstood
That might be worth a look although basically as long as the info gets to the HAH it can be processed there just as easily in whatever plugboard applet is going to be used to deal with it.
Member for
15 years 1 monthA few observations
After a few days playing about with the Raspi/bluetooth dongle combination, here are a few things I've learnt:
My dongle (cheapo chinese I think) isn't all that reliable and sometimes completely hangs up the Pi. I've
reset the Pi's USB ports to operate in USB 1.1 mode only; and this seems to have helped a bit in the
Raspbian Wheezy config but in my Arch Linux config it's still very flaky. I'm sure that you'll probably find
that the HC05 module setup will be much more stable.
Having said that this setup does seem to detect and relay bluetooth ping to the HAH on a reasonably steady basis.
My old Motorola L6 is fairly good at responding to pings. On the iPhone front, the 4S is much more reliable than
the 3GS when in sleep mode.
I've also had a play around with WiFi detection. I installed arp-scan and use the following in the python script
to ping the phones using WiFi: "arp-scan 192.168.0.1-192.168.0.20 | grep 5c:95:ae:xx:xx:xx; echo command returned $?"
I'm not sure how long it takes to detect a newly arrived iPhone or how long the MAC stays in the arp table, I'll have
to spend a bit more time on it, but when asleep the iPhone 4S seems to reliably respond to arp-scan. On the other hand
when asleep the 3GS seems to go completely "off grid" sometimes.
Truth is that for long term presence monitoring (such as when the house has been unoccupied for several hours or even
several days) a combination of bluetooth and WiFi probably give a fuller picture. Though I've still not decided how
to use the information yet. I'll be interested to hear how people get on with their HC05's in due course.
Now back to monitoring those UDP packets!
Member for
15 years 7 monthsHC05 and Jeenode example
I have added my initial attempt using the jeenode and HC05 in the example scripts forum.
Here: /content/bluetooth-presence-hc05-and-je…