Using bluetooth as a proximity sensor.

Posted on
  • Hi all,

    I was wondering if it was possible to have the puck to act as a proximity sensor.

    I have Philips Hue bulbs in my office (which can be controlled via a REST API) and a Tessel 2.
    I was wondering the puck could see my phone BLE (can it measure the strength of the BLE signal?) and send an event to the Tessel over Bluetooth. Could someone point me in the right direction?

    The tessel could then control the bulbs over WiFi.

    Thanks,

    Jan

  • I think your phone would have to be 'advertising' in order to be 'discoverable' for Puck to be able to detect it and evaluate the RSSI. The Tessel 2 has native WiFi. Another option, perhaps, is to give your phone a static IP on your WiFi LAN, and then Tessel can detect your phone's 'arrival' and control the bulbs. Just thinking out loud.

  • RSSI is an indicator for that - look at proximity-and-rssi

    Puck can do a find devices

    NRF.findDevices(function(devices) {console.log(devices);},1000);
    
    [
      BluetoothDevice {
        "id": "f4:38:88:d0:bc:5c random",
        "rssi": -55,
        "services": [  ],
        "data": new ArrayBuffer([2, 1, 5, 13, 9, 80, 117, 99, 107, 46, 106, 115, 32, 98, 99, 53, 99]),
        "name": "Puck.js bc5c"
       }
     ]
    
    

    there are some nice cell-phone apps like "BLE Scanner" for Android

    It defines three zones

    • immediate rssi > -50,

    • near, rssi between -50 and -75

    • far, rssi between -75 and -90

  • Thanks to you both.

    I had considered the wifi option, but the reason that I want to use bluetooth is so I can more or less scope it to a room (== a particular puck).

    the rssi property on the objects returned byNRF.findDevices() seems useful, though I'm not seeing the Bluetooth MAC from my iPhone (Settings>General>About) in the list of devices returned. Is the iPhone hiding? Any way around it?

  • Ok good point. But I think you will find that your phone doesn't advertise itself continuously like the Puck does. My android phone, for example, only advertises when the bluetooth settings page is open. So the iPhone maybe isn't hiding, per se, but is just not advertising. Another possible issue as I also have with my phone, is it doesn't advertise as a BLE device. EspruinoHub for example doesn't see it. But from my PC I was able to add the phone as a Bluetooth device and send files and play music from it. Maybe you could do it in reverse and detect the Puck proximity from the phone, and then take some action.

  • Thanks—Yeah, I think you're right it doesn't advertise itself. At first glance, it looks like on my mac I'm not seeing my iphone appear under "Open Bluetooth Preferences..." unless I open the bluetooth settings on my phone. So that supports your advertising theory...

    I didn't have any luck with the puck with my bluetooth setting open—even when I set changed the scantime for NRF.findDevices() to 5000ms from 1000ms.

    It's an annoying thing to google, because no matter how I phrased my query, I just kept getting results about bluetooth devices not connecting to an iPhone.

    I didn't see the pucks show up as bluetooth devices on my iPhone either (or on my mac, though it did work through web bluetooth). I'm not sure what's going on there.

    I bought the make:bluetooth book, which has a project for a BLE doorlock which unlocks with an iOS/Android phone, but it involves creating a phonegap app, etc. However, it uses the phone to require the user to enter a security code, while I just want to use proximity. I also don't want to have to take my phone out and start up an app: at that point I might as well open the Philips Hue app and turn on the lights that way :)

    It'd be so much easier if I could just have the puck see the iPhone and contact the Tessel over bluetooth. Anyway, looks like I'll have to gain a better understanding of BLE. Seemed like this would be easy, but nothing... ever... is... sobs

  • Uncle Google finally had some words of wisdom to impart, I suppose this might be the reason?

    It's fun when I get to repeat myself.

    1. The iPhone doesnt stay in discoverable mode unless initiated by the settings screen.
    2. The iPhone doesn't support the serial profile, so your device won't automatically see your the >phone when it is in range.

    If you can use a Bluetooth device that supports the HID profile, you might have better luck...

    http://forum.arduino.cc/index.php?PHPSES­SID=ltukrr9ec6v8gi0l4na82jhsu3&topic=100­026.msg750645#msg750645

  • If you can use a Bluetooth device that supports the HID profile, you might have better luck...

    On the puck.js kickstarter page it says HID is supported though... Oh well, I'll stop posting and see what I find...

  • @JanDW do you think about something like this?

  • @Spocki Thanks, that looks useful. I'll hopefully have time to experiment next week.

  • Without an app on the iPhone, the best solution might be to use HID as you say. Just turn it into a keyboard and when you get the NRF.connect or disconnect events you can see when the iPhone thought it was in range enough to try and connect.

    It might work - otherwise you'd need an app I'm afraid... Or you might be able to do something by turning the Puck into an iBeacon?

  • I had thought of iBeacons but wasn't quite sure what they can do. Thanks for pointing out some directions. I'll look into it and will report back if/when I get it working.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Using bluetooth as a proximity sensor.

Posted by Avatar for JanDW @JanDW

Actions