• @AnotherStranger @Gordon Sorry to bother you again but the issue pointed out by AnotherStranger is actually not allowing me to properly develop an app. The following code, even though makes the heart rate service available, throws this error in the IDE:

    function onInit() {
      Bangle.setHRMPower(1);
      NRF.setServices({
        '180d': {  // Heart Rate Service UUID
          '2a37': {  // Heart Rate Measurement Characteristic UUID
            value: [0x00, 0x00],  // Initial value: HRM not available
            broadcast: false,
            readable: true,
            notify: true,
            description: "Heart Rate Measurement"
          }
        }
      }, { advertise: ['180d'] });  
      Bangle.on('HRM', function(hrm) {
        NRF.updateServices({
          '180d': {
            '2a37': {
              value: [hrm.confidence, hrm.bpm],
              notify: true
            }
          }
        });
      });
    }
    onInit();
    

    Trying to resolve the issue with the need for restart does not seem to resolve the problem. I have tried this:

    function onInit() {
      Bangle.setHRMPower(1);
    
      NRF.setServices({
        '180d': {  // Heart Rate Service UUID
          '2a37': {  // Heart Rate Measurement Characteristic UUID
            value: [0x00, 0x00],  // Initial value: HRM not available
            notify: true,
            description: "Heart Rate Measurement"
          }
        }
      }, { advertise: ['180d'] });
    
      Bangle.on('HRM', function(hrm) {
        NRF.updateServices({
          '180d': {
            '2a37': {
              value: [hrm.confidence, hrm.bpm],
              notify: true
            }
          }
        });
      });
    }
    
    // Restart Bangle.js to apply the updated advertising
    Bangle.on('kill', function() {
      NRF.setAdvertising({}); // Stop advertising
      load(); // Restart Bangle.js
    });
    
    onInit();
    
    

    I have also tried this (introducing a timeout):

    function onInit() {
      Bangle.setHRMPower(1);
      NRF.setServices({
        '180d': {  // Heart Rate Service UUID
          '2a37': {  // Heart Rate Measurement Characteristic UUID
            value: [0x00, 0x00],  // Initial value: HRM not available
            broadcast: false,
            readable: true,
            notify: true,
            description: "Heart Rate Measurement"
          }
        }
      }, { advertise: ['180d'] });  
      Bangle.on('HRM', function(hrm) {
        setTimeout(function() {
          NRF.updateServices({
            '180d': {
              '2a37': {
                value: [hrm.confidence, hrm.bpm],
                notify: true
              }
            }
          });
        }, 500); // Delay in milliseconds before updating services
      });
    }
    
    onInit();
    
    

    This code still resulted in an error:
    in function called from system
    Uncaught Error: Can't update services until BLE restart
    at line 1 col 79
    ...idence,hrm.bpm],notify:true}}});

    Is there an established way to do this that I've missed perhaps? Thank you in advance!

About

Avatar for user155593 @user155593 started