You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Wow, that looks awesome! I love the way you got an OLED display in there as well. It'd be great if you could post something up when you're done :)

    Bonding

    That should be fine. New firmwares (cutting edge, and 2v02 when it comes out) actually have the ability to set a passkey (http://www.espruino.com/Puck.js+Security­#passkey-pin-pairing) which might be a good way of locking it down.

    Can I go through the pairing/bonding process, save the characteristic object to a variable (i.e. char = characteristic returned) and just call char.writeValue(data) to update the characteristic?

    There isn't a shorter way at the moment (I have plans to make a module to hide some of it), but you can re-use the service and characteristic.

    For instance:

    NRF.requestDevice({ filters: [{ namePrefix: 'Pixl.js' }] }).then(function(device) {
      return device.gatt.connect();
    }).then(function(g) {
      gatt = g;
      return service||gatt.getPrimaryService("6e40000­1-b5a3-f393-e0a9-e50e24dcca9e");
    }).then(function(s) {
      service = s;
      return characteristic||service.getCharacteristi­c("6e400002-b5a3-f393-e0a9-e50e24dcca9e"­);
    }).then(function(c) {
      characteristic = c;
      return characteristic.writeValue("LED1.toggle()­\n");
    }).then(function() {
      gatt.disconnect();
      console.log("Done!");
    });
    

    Will make the connection next time quite a bit faster.

    Although for what you want, you want to stay connected - so you can just delete everything after characteristic = c; and then when you get a reading you want to transmit, do if (gatt && gatt.connected && characteristic) characteristic.writeValue([throttle_0_to­_255]);.

    Should the reciever read a changing characteristic on the remote or should the remote(transmitter) write a value to a characteristic/service on the reciever?

    I'd say the latter. Make the board itself the peripheral, and make the controller connect to it. That's what most other stuff tends to do and then you could conceivably also use your phone to control it via Web Bluetooth - although god knows why you'd want to when the remote looks so cool :)

    I ought to cover it in more detail, but it's best to do it with a random 128 bit UUID (there are online generators available), then replace the second group of 4 numbers with 0001 for the service, then 0002/etc for the characteristics. Eg, ea1abd0133fc087275554a522b8f56c4 changes to ea1a000133fc087275554a522b8f56c4.

    That's a nice efficient way of doing it as the same basic 128 bit UUID gets re-used.

    You probably also want to add NRF.setConnectionInterval(7.5) on the longboard, to force it to use the fastest Bluetooth speed so you get the lowest latency. It also means you probably want to send the updates from the remote control at no more than 100Hz.

About

Avatar for Gordon @Gordon started