Announcement

Collapse
No announcement yet.

Raspberry Pi + Bluetooth4.0(Tag/FitnessBand/SmartWatch) = Proximity Sensor Project

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Raspberry Pi + Bluetooth4.0(Tag/FitnessBand/SmartWatch) = Proximity Sensor Project

    This is a continuation of the other thread here .
    The thread started out trying to find out if using iBeacon(Bluetooth 4.0 for iOS & Android- Tile/Tags, smart Watch, Fitness bands) was a realistic possibility as a proximity sensor for HS.
    BLE = Bluetooth Low Energy=Bluetooth 4.0=iBeacon

    Started this thread so as to put everything in one easy spot and define all the terminology which is often misused with regard to iBeacon.

    After a lot of research the best path, as of now, seems to be to use Raspberry Pi + Bluetooth 4.0 Dongle + BLE Transmitter(Tag/Tile/Fitness Band/Watch) => As Proximity Sensor.

    SO
    PiBeacon(A BLE Scanner) = Raspberry Pi + BLE 4.0 Dongle

    BLE Transmitter = Tag/Tile/Fitness Band/Watch.
    All the smartphone watches use BLE so you should be able to detect them too. Apple watch hasn't been released yet so I don't know. But Samsung watch should work.
    Attached is the image file & instructions from my RaspberryPi with all the Bluetooth(Bluez) software installed. Updating the Pi software is SLOW and can be PAINFUL at times. So this will give others a couple of days head start if you want to experiment with this project. I used the Radar Networks files and their free apps(Locate) to start with testing. Radar Networks also has api and other software available to developers.

    I believe Mrhappy(adam) will be heading down the Pibeacon path as some point, if not already. I don't mean to speak for Adam, but just wanted to give credit for his constant contributions and guidance. His knowledge JSON for integrating Python with HS will give a major boost to this project. Furious used switchdocs path and has been successful in using his Pi as a PiBeacon Scanner. The image file below includes switchdoc files also if you'd like to go down that path. The reason I didn't go down the switchdocs path was that their apps aren't free. At this point since we are still just experimenting, I thought I'd follow the least expensive, and more open path.

    The download has Instructions & the Image file has the most updated version Pi software, Bluez software, Bluetooth GUI installed, other extras to make life easier on Pi.

    PiBeacon122014v2.zip
    Last edited by TomTom; December 29, 2014, 11:46 AM.
    Tom
    baby steps...starting again with HS3
    HS3Pro: Z-NET & 80 Z wave Devices,
    HSTouch: 4 Joggler (Android Kitkat), 2 iPhone, 3 iPads
    Whole House Audio: 5 SqueezePlay Jogglers w Bose Speakers
    In The Works: 10 Cameras Geovision, new Adecmo/Envisalink Alarm, Arduinos
    System: XP on Fanless Mini-ITX w/ SSD

    #2
    I could see this as a pretty decent plugin for Homeseer, raspberry PI on the network wherever talking to Homeseer which could set devices up with actions/triggers based on presence. Wonder if we could get it to work with the Pebble.

    Comment


      #3
      Kudos to you for putting it all together.
      If anyone needs any more info, please add to the thread.

      On my implementation, I use 2 BT dongles, one is a version 2 in port 2, and the BTLE in port 0, as I found out the hard way that blues really doesn't like the first BT device as an older type.

      Other nuggets of info....

      I use a bash script to poll BT2 paired devices, and a mix of bash and switchdocs python script for the beacons. The logic basically parses BT devices and then uses a http post to set virtual devices in HS.

      The python script is literally a raw packet capture wrapper. This is fine if you always have one beacon in proximity. However, this is bad for those using it to sense presence when there are no beacons around, as no packets = scripts wait indefinitely for some more data. This means no detecting all away beacons, so I added a timeout around the script so that it can actually return nothing to the bash script, and then the away part can be processed.

      Ideally, it needs a multi threaded script to handle the scanning part separately, and the main script to poll that and act periodically.

      One more thing, the BT stack is not hugely robust, so any scripting should put in a periodic check to see if the device is up and issue a periodic down/up/reset.

      I would advise buying beacons that allow how often it broadcasts, as this will allow the battery to last way longer. I have mine to ping every 3 seconds, as opposed to something like 10 times per second, as I'm going for basic "here/away" sensing. I'd have to try other beacons for anything like distance sensing, but judging by the first device, I don't hold up much hope for sensing anything other than near/far/away.

      Comment


        #4
        I think the reports of my ability are greatly exaggerated! I've been making some BT LE progress with my ANCS reader working apparently OK so I have at least a greater understanding of what BT LE is actually trying to do. I've been using the nRFStudio for the breakout board and I may even contemplate building that as a peripheral device to talk to HS and exchange information but that is a long road ahead. I will await the arrival of the stuff from China and see how I get on...

        Comment


          #5
          Originally posted by kideon View Post
          I could see this as a pretty decent plugin for Homeseer.... Wonder if we could get it to work with the Pebble.
          Yeah, this does look very promising, but only tested it with my iphone as a transmitter(have to keep phone ON constantly though). I'm still waiting for my tag and usb BLE transmitter to arrive from china.

          Originally posted by Furious View Post
          On my implementation, I use 2 BT dongles, one is a version 2 in port 2, and the BTLE in port 0, as I found out the hard way that blues really doesn't like the first BT device as an older type.
          I wish I had asked you. I wasted several hours trying this before I came to the same realization

          Originally posted by mrhappy View Post
          I think the reports of my ability are greatly exaggerated! I will await the arrival of the stuff from China and see how I get on...
          haha. You're modest to say the least. You've learned to code as a hobby and so that's pretty amazing. The ANCS project seems like it has real potential. I'm waiting on a Chinese shipment too, one of the things I ordered seems to have been lost(never happened before). Hoping next shipment will get here.
          Tom
          baby steps...starting again with HS3
          HS3Pro: Z-NET & 80 Z wave Devices,
          HSTouch: 4 Joggler (Android Kitkat), 2 iPhone, 3 iPads
          Whole House Audio: 5 SqueezePlay Jogglers w Bose Speakers
          In The Works: 10 Cameras Geovision, new Adecmo/Envisalink Alarm, Arduinos
          System: XP on Fanless Mini-ITX w/ SSD

          Comment


            #6
            I'm head deep into the ANCS reader (http://i.got.nothing.to/code/on/avr-for-ble-and-ios/) and I think it could also be used as a proximity detection device if you always had your phone on you. I'm still looking at it's reliability (there are some things about pairing that I am not entirely sure will stand up [working earlier when I was walking up and down the drive like a maniac] and I may need to tweak the code for the Nordic board) but I think it could be used to detect your phone being present or not.

            I know there are already tools for this about but I wonder whether the BT LE on the phone side of things uses less power than the classic BT, it at least seems to stay connected permanently.

            In any case I have the notifications coming into HS and I am likely going to use them in events to do some TTS on incoming calls/messages. Unfortunately I do not get the full message like I ever did with Tasker calling into HS. The downside being it is not that straightforward to get working reliably...
            Last edited by mrhappy; January 31, 2015, 05:29 PM.

            Comment


              #7
              Woah, reading that blog.... there is so much more to everything than I realised, and I'm glad the pi and bluez stack abstract all that away from me.

              All that you've done and you're still basically pairing the devices to make it work, and its still not 100% - surely is a labour of love

              It'd be interesting to see how "low energy" it really is compared to the older stuff, especially since it appears to be very chatty. On the newer (3 years and younger android phones), just having BT on seems to not drain much power above average usage anyway, and they seem to have immense range (10m+ through 2 walls to the centre of the house, HS alerts to my wife that I'm home as I pull into the driveway)
              The beacon is slightly shorter range, but can't really tell if its the inherent latency of my current script or just the power of the device. Still thinking of reworking the script as different ways seem to yield better polls, I've seen it take 30+ seconds to "see" a ping from the beacon, even though it should have seen 10 in that time.

              Comment


                #8
                no way you actually got the ANCS reader working!

                Comment


                  #9
                  Originally posted by kideon View Post
                  no way you actually got the ANCS reader working!
                  Not without a fight and not particularly reliably (the pairing is frustrating)! But yes it is working, if I can solve the bonding issue then I am onto a winner.

                  Comment


                    #10
                    Hi, I am new to hs3 and am really interested in getting stable occupancy detection setup. I currently use wifi detection with my phone via my routers arp table to trigger lights and unlock doors when i arrive home. the problem is, the connection times are random, some times not triggering until i am already in the house and by then its too late. From what i have read, bluetooth/ble are almost instant and more accurate. I see the pibeacon installation instructions and i think i understand that portion of it, but i am not sure how to integrate it with homeseer. I see several people mention bash and python scripts, but i see any specific examples. I can setup the pibeacon, but how do i proceed from there?

                    Comment


                      #11
                      glacket,

                      yes BLE has very interesting scope. I've just gotten busy with other automation fixes(maintenance), this has gotten side tracked. I had let my home security and all touch screen(client) lapse for sometime till family pressures finally caused me to attend to them. For me the primary hurdle has been the need to completely under JSON and python to get it integrated with HS. I started during the Xmas break but got busy.

                      I have tested a BLE tile with my piBeacon and got about 20-25 ft detection range. It might be more but might helper(lil son) wouldn't sit there watching the piBeacon anymore( or accurately). I also ordered a usb BLE, which I can plug into my cars usb port, and it gets picked up too. I didn't have a chance check the range with the USB BLE. I think it should probably be better than the tile because of having constant power. The USB BLE connected to the car is great because it turns on when in use and off when I've gotten out of the car.
                      I did take some pics but just can't seem to find them at the moment.
                      Tom
                      baby steps...starting again with HS3
                      HS3Pro: Z-NET & 80 Z wave Devices,
                      HSTouch: 4 Joggler (Android Kitkat), 2 iPhone, 3 iPads
                      Whole House Audio: 5 SqueezePlay Jogglers w Bose Speakers
                      In The Works: 10 Cameras Geovision, new Adecmo/Envisalink Alarm, Arduinos
                      System: XP on Fanless Mini-ITX w/ SSD

                      Comment


                        #12
                        Hi tomtom,

                        that sounds like the kind of detection im looking for. i think i can handle getting the basic pibeacon setup, but not sure how to to tie it to homeseer. would you be able to post the script you use for it, or an example script, or know where i can find one? Thanks.

                        Comment


                          #13
                          This project hasn't been tied to HS is anyway so far.
                          I had read about BLE and tiles used by smartthings home automation hub. So went searching for a way to do it. Adam( mr happy) had been playing with ios notifications, and other ble possibilities.
                          Came across the possibility of using pi with a bluetooth BLE(=scanner). Once I had it up and running on the pi, I wanted to see how accurate and what range I could get. To test this I used different apps(Beacon and iBeacon) to test the range. Therefore my iphone became the "tile"( beacon or BLE transmitter). The range and accuracy was better than I had gotten with the old bluetooth(2.0) stuff. So it has a lot of promise. I believe I put the instruction in the file above.

                          Originally posted by glacket View Post
                          Hi tomtom,

                          that sounds like the kind of detection im looking for. i think i can handle getting the basic pibeacon setup, but not sure how to to tie it to homeseer. would you be able to post the script you use for it, or an example script, or know where i can find one? Thanks.
                          Tom
                          baby steps...starting again with HS3
                          HS3Pro: Z-NET & 80 Z wave Devices,
                          HSTouch: 4 Joggler (Android Kitkat), 2 iPhone, 3 iPads
                          Whole House Audio: 5 SqueezePlay Jogglers w Bose Speakers
                          In The Works: 10 Cameras Geovision, new Adecmo/Envisalink Alarm, Arduinos
                          System: XP on Fanless Mini-ITX w/ SSD

                          Comment


                            #14
                            Can the pibeacon send rest or json commands. I would think that would make it alot easier to tie into homeseer.

                            Comment


                              #15
                              You're not really limited by using the pi, you can use whatever to do the Json part like curl, etc.

                              Comment

                              Working...
                              X