• Goal: Im trying to create a puck that advertises a distress-call ( panic / sos button) and gets picked up by any phone with the corresponding app installed.
    So simply advertising som data and then change som specific advertising data when the button is pressed.
    While developing a long press will make the puck go back into a state where it can connect to the web IDE.

    I have 2 problems at the moment.
    1 When doing a long press the puck is not able to reconnect with the IDE.

    2 The app finds the puck but the serviceUUIDs list is empty. This list need to have at least one entry for iphone to let it be discovered in the background.
    Data retrived in the app :

    serviceData:{00000019-0000-1000-8000-008­05f9b34fb: "dGVzdA==", 00001076-0000-1000-8000-00805f9b34fb: "AA=="}

    Puck Code:

    var downTime = 0;
    var presses = 1;
    var heartrate = 5;
    var distress = false;
    function ledBlink(ledId, duration, loops) {
      digitalWrite(ledId, true);
      let loop = loops || 1;
      setTimeout(function () {
        digitalWrite(ledId, false);
        if(loop > 1) {
          setTimeout(function () {
            // be off for same amount of time
            ledBlink(ledId, duration, loop);
          }, duration);
      }, duration);
    function onUp() {
      const lengthOfPress = Date().ms - downTime;
      console.log('Button down for ' + lengthOfPress + 'ms');
      if(lengthOfPress > 1000) {
      } else {
    function onDown() {
      downTime = Date().ms;
      setWatch(onUp, BTN, { edge: 'falling', debounce: 50 });
    function longPress() {
      ledBlink(LED3, 100, 3);
    function shortPress() {
      ledBlink(LED1, 100, presses);
    function IdeConnect() {
      // reset ble to connect with Espurino web IDE
      ledBlink(LED3, 200, 10);
      NRF.setServices(undefined, { uart: true });
    function beaconMode() {
      // advertise some data to everyone in range
      distress = !distress;
        ledBlink(LED1, 200, 3);
      } else {
        ledBlink(LED2, 200, 3);
      // from exaple code
        0x180D: { // heart_rate
          0x2A37: { // heart_rate_measurement
            notify: true,
            value : [0x06, distress],
      }, { advertise: [ '180D' ], uart: false });
         0x1076 : [distress], // change bit to filter out distresscalls
         0x19 : ['t','e','s','t'] // some identifier
          name: 'MyName',
          showName: true,
          connectable: false,
          discoverable: true,
          manufacturer: 0x0590,
    setWatch(onDown, BTN, { repeat: true, edge: 'rising', debounce: 50 });
  • What you're doing looks fine. The 180D service might be in a scan response packet - so if the iPhone isn't doing active scanning it wouldn't pick it up.

    I guess another option (especially if you're targeting iPhone) might be to make Puck.js emulate an iBeacon? That could (afaik) directly link to your app.

    Do the LEDs flash as you'd expect? Is the blue one to indicate connection state flashing, so you know IdeConnect is getting called ok?

  • Leds flash as expected. Long press makes it blink blue, but nothing shows up in the "whants to pair" list of the IDE.

    Yes! iBeacon was my first attempt but iBeacon wont provide any method of identifying unique identifiers and separating them.
    e.g When monitoring for iBeacons in the background with uuid=123
    the triggerd event when iBeacon is in range dosen´t contain major or minor.


  • When monitoring for iBeacons in the background with uuid=123 the triggerd event when iBeacon is in range dosen´t contain major or minor.

    Wow, that's annoying - I thought that was the whole point.

    What about switching to iBeacon only when there's an alert?

    If you use something like the nRF connect app on the phone, what does it show for the Puck when it's back in connectable mode?

    I guess it might be worth explicitly setting connectable:true again? Also the IDE works based on an advertised NUS service (in the scan response packet) but also just the name as a fallback. If the name doesn't begin with Puck.js it's possible it may not pick it up if it hasn't been able to read the NUS service UUID.

  • I managed to get it to work by cleaning out all code and using the button press examples from Music Controller. And then just add the advertising code bit. It might have been a problem with the broadcast message being to long.

    function setBleBroadcastingDistress(){
        'b2fb58a0-8452-402a-8435-eedf397464a9' : {
          0x5AFE : {
            value : true,
            readable : true
      }, { advertise: [ 'b2fb58a0-8452-402a-8435-eedf397464a9' ], uart: false });
          0x1815 : pressIdentifier
          name: 'ALERT!',
          showName: true
      digitalWrite(LED1, 1);
        digitalWrite(LED1,0 );
      }, 10000);

    Then advertise another UUID when everything is normal.

    For IDE mode this was enough.

    function ideConnect(){
        NRF.setServices(undefined, { uart: true });
          name: 'IDE',
          showName: true

    I will add the connectable:true as you suggested.

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

Problem with advertising UUID that can later be filtered by react-native-ble-plx

Posted by Avatar for user93296 @user93296