Avatar for knolleary

knolleary

Member since Jan 2017 • Last active May 2017
  • 1 conversations
  • 6 comments

Most recent activity

  • in Puck.js
    Avatar for knolleary

    Pretty much, yes.

    I set it to 10, 20 or 30 depending on whether I single, double or triple tap the button, resetting it back to 0 after 3 seconds.

    Need to tidy up the code as it is littered with previous attempts and experiments, but will share it later on.

  • in Puck.js
    Avatar for knolleary

    Not sure about the HID stuff - wasn't running EspruinoHub at the time.

    Have moved over to setAdvertising and got it working well. Took a bit of time to find a succinct example of noble code that showed how to get the data, but once I found it, it was trivial enough. Code below emits changes to any advertised data from my puck. Right now it assumes a single byte payload in the data - sufficient for my needs, but easily extended to do things properly.

    var noble = require('noble');
    
    noble.on('stateChange', function(state) {
        if (state === 'poweredOn') {
            // pass true so duplicate events are emitted
            noble.startScanning([],true);
        } else {
            noble.stopScanning();
        }
    });
    
    var lastData = {};
    noble.on('discover', function(peripheral) {
        if (peripheral.id !== 'f14142b40d3b') return;
        var data = peripheral.advertisement.serviceData;
        for (var i=0;i<data.length;i++) {
            var d = data[i];
            if (lastData[d.uuid] !== d.data[0]) {
                lastData[d.uuid] = d.data[0];
                console.log(d.uuid,d.data[0]);
            }
        }
    });
    
  • in Puck.js
    Avatar for knolleary

    @joakim finally found the mistake I'd made in the node.js code... missed off the subscribe call on the rx characteristic. All working now.

    Next task is, as you've said, figure out if there's a more energy efficient way of doing this.

  • in Puck.js
    Avatar for knolleary

    @joakim thanks for that. A couple questions...

    where is the Bluetooth object documented? It looks like a Serial object, but I don't see it mentioned on the reference page - https://www.espruino.com/Reference

    I've got the node.js code working to the extent it connects to my puck, gets the appropriate characteristic and waits for data to be sent over. However nothing ever arrives from the puck. I've confirmed the puck side is working as, in the web ide, when I press the button, the Bluetooth.write() does result in something appearing in the web console.

  • in Puck.js
    Avatar for knolleary

    Hi,

    I'm trying to figure out the most effective way to trigger an action on a Raspberry Pi when the button is pressed on a puck. It feels like an obvious thing to do, but I couldn't find an example in the forum or the tutorials.

    My first attempt involved turning the puck into a HID keyboard and capture the corresponding key event on the pi.

    I used the first example code from here: https://www.espruino.com/Puck.js+Keyboar­d, verified it worked when connected as a HID keyboard to my Mac. That worked. But then I couldn't get it to pair as a HID keyboard with the Pi. Following various guides, I've got to the point where bluetoothctl reports the devices as follows:

    [bluetooth]# info F1:41:42:B4:0D:3B
    Device F1:41:42:B4:0D:3B
        Name: Puck.js 0d3b
        Alias: Puck.js 0d3b
        Paired: yes
        Trusted: yes
        Blocked: no
        Connected: yes
        LegacyPairing: no
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: Human Interface Device    (00001812-0000-1000-8000-00805f9b34fb)
        UUID: Vendor specific           (6e400001-b5a3-f393-e0a9-e50e24dcca9e)
    

    You can see it is both connected and paired and that it has a HID UUID - but I see no new keyboard events when I hit the button.

    Question #1 - has anyone get the HID Keyboard stuff to work with a Pi (in this instance, a Pi3 and its onboard bluetooth).

    I've also tried EspruinoHub and doing something hacky around NRF.setServices() and overloading the 'temperature' value, but in some quick experiments I couldn't get that to work - the value would never change.

    Question #2 - Is there a better approach I should be using going down the EspruinoHub route?

Actions