• The goal here is for her to maybe tuck the Puck.js into her bra strap of something. Sounds weird but evidently women use their bra straps as a sort of pocket :-)

    Core principle.. on an alert, use the Espruino Hub to convert the BLE advertisement of the alert to MQTT and use Node-Red to take action on that button press with a Twilio webhook to send the kids a SMS.

    First draft - the button sends the alert right away. But then I thought it might be good to have a cancel feature for x seconds.

    Second draft - button sets the red LED flashing for 10 seconds during which time the whole shooting match can be cancelled. If not cancelled, send the alert.

    var pressCount = 0;
    var batt = 0;
    
    var alertQueued = 0;
    
    digitalWrite([LED3,LED2,LED1], 0);
    
    var flasherID;
    var timeoutID;
     
    function showAlert() {
      pressCount++;
      batt = Puck.getBatteryPercentage();
      clearInterval(flasherID);
      alertQueued=0;
    
      NRF.setAdvertising({
        0x1812 : [pressCount],
        0x180f : batt,
        });
      LED1.write(1);
    }
    
    function delayedAlert() {
      timeoutID = setTimeout(showAlert, 10000);
      alertQueued=1;
    }
     
     
    function clearAlert() {
      clearTimeout(timeoutID);
      clearInterval(flasherID);
      alertQueued=0;
      LED1.write(0);
    }
    
    
    setWatch(function() {
      if (alertQueued) {
        clearAlert();
      } else {
        delayedAlert();
        flasherID = setInterval("digitalWrite(LED1,redLEDOn=­!redLEDOn);",200);
      }
    }, BTN, { edge:"rising", repeat:true, debounce:50 });
    
    

    The LED will stay on after the alert is set. To clear it, just cycle it again but cancel during the delay.

    Next Steps -
    I tried to get the gyro/accel to help me determine a fall.

    I tried the tilt>35 interrupt and I could get that to work on its own but not in conjunction with the button press.

    Even if I did get them to work together it seems like there would need to be a LOT of tuning to get it right. The detector seems like by default it tests all axis. So turning left or right is no different than falling flat.

    Maybe one of the other detection mechanisms could work. But she is nearly 90 so her baseline activity level is pretty slow.

    https://youtu.be/MCevqAU_b64