• 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 :

    "F6:A1:EC:AF:EB:0F"
    isConnectable:null
    localName:"MyName"
    manufacturerData:null
    mtu:23
    name:"MyName"
    overflowServiceUUIDs:null
    rssi:-42
    serviceData:{00000019-0000-1000-8000-008­05f9b34fb: "dGVzdA==", 00001076-0000-1000-8000-00805f9b34fb: "AA=="}
    serviceUUIDs:null 
    solicitedServiceUUIDs:null
    txPowerLevel:null
    

    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) {
          loop--;
          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) {
       longPress();
      } else {
        shortPress();
      }
    }
    
    function onDown() {
      downTime = Date().ms;
      setWatch(onUp, BTN, { edge: 'falling', debounce: 50 });
    }
    
    function longPress() {
      ledBlink(LED3, 100, 3);
      IdeConnect();
    }
    
    function shortPress() {
      ledBlink(LED1, 100, presses);
      presses++;
      beaconMode();
    }
    
    function IdeConnect() {
      // reset ble to connect with Espurino web IDE
      ledBlink(LED3, 200, 10);
      NRF.setServices(undefined, { uart: true });
      NRF.setAdvertising({});
    }
    
    function beaconMode() {
      // advertise some data to everyone in range
      distress = !distress;
      if(distress){
        ledBlink(LED1, 200, 3);
      } else {
        ledBlink(LED2, 200, 3);
      }
    
      // from exaple code
      NRF.setServices({
        0x180D: { // heart_rate
          0x2A37: { // heart_rate_measurement
            notify: true,
            value : [0x06, distress],
          }
        }
      }, { advertise: [ '180D' ], uart: false });
    
      NRF.setAdvertising(
        {
         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,
          manufacturerData:[distress],
        });
    }
    
    
    setWatch(onDown, BTN, { repeat: true, edge: 'rising', debounce: 50 });
    
    
    //save();
    
    
About

Avatar for user93296 @user93296 started