Avatar for user155593

user155593

Member since May 2023 • Last active Jun 2023
  • 2 conversations
  • 8 comments

Most recent activity

  • in Bangle.js
    Avatar for user155593

    @Gordon Thanks for pointing this out - moving the code outside the init() function does not require setInterval to keep the program alive, as it is done directly by HRM events. Thank you! Just wanted to as you one last thing - for now the app only runs when it is open - as soon as I get back to the main menu, the advertising stops. Is this an intended way to do it or is there a way to run it in the background? I've tried playing with

    g.clear();
    Bangle.setUI("clock");
    Bangle.loadWidgets();
    Bangle.drawWidgets();
    

    but it recreates the main screen in an arbitrary way. As soon as I want to interact with the menu (press the side button), the program stops.

  • in Bangle.js
    Avatar for user155593

    Thanks everyone! The problem of the app not continuously advertising the data when deployed as an app and not via Espruino IDE was actually the fact that the program would quit before advertising anything. So I needed to implement a keep alive function. The app is functioning now. Thank you!

  • in Bangle.js
    Avatar for user155593

    @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!

  • in Bangle.js
    Avatar for user155593

    @fanoush Thank you for pointing this out!

  • in Bangle.js
    Avatar for user155593

    @user155613 Thank you for your feedback and signalling potential problems!

  • in Bangle.js
    Avatar for user155593

    Hi, I'm struggling with an issue and would really appreciate any help! I'm trying to implement a simple web application that connects to my Bangle.js 2 and visualises the received heart rate data. I would like to advertise heart rate service as as GATT service following all the specifications. I've tried many many versions of the code below (loading it via Espruino IDE for now) but nothing seems to work.. None of the services can be found when using nrFConnect and LightBlue. I've tried both NRF.setAdvertising like so (simplified version):

    function onInit() {
      Bangle.setHRMPower(1);
    
      Bangle.on('HRM', function(hrm) {
        var data = {
          hrmConfidence: hrm.confidence,
          hrmValue: hrm.bpm
        };
    
        NRF.setAdvertising({
          0x180D : [hrm.confidence, hrm.bpm]
        }, {
          discoverable: true,
          connectable: true,
          scannable: true,
          whenConnected: true,
          interval: 600
        });
      });
    }
    
    onInit();
    

    I've also tried a more precise way using NRF set and update services:

    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();
    

    However, when I send my heart rate data using UART (following this tutorial here: http://www.espruino.com/Bangle.js+Data+S­treaming#bonus-2-heart-rate-monitoring-g­raph), it works correctly and I'm able to receive this data on my web app:

    function onInit() {
      Bangle.setHRMPower(1);
    
      Bangle.on('HRM', function(hrm) {
        var data = 'H,' + hrm.bpm.toString() + ',' + hrm.confidence.toString();
        Bluetooth.println(data);
      });
    }
    
    onInit();
    

    I would really appreciate any help regarding this as I'm new to Espruino and Bluetooth in general and struggling to find a solution. Just a quick note: my web app is currently not scanning for the services but I would assume that if advertising works correctly, it should come up on nRFConnect and LightBlue.

    Thanks for your help in advance!

  • in Bangle.js
    Avatar for user155593

    I was able to connect after a full factory reset but I'd be grateful if anyone could explain why something like this might happen? Thanks!

  • in Bangle.js
    Avatar for user155593

    Hey everyone,
    I just got my Bangle.js 2 and was trying to develop a simple app that would advertise my heart rate as a GATT Service (for connection to the browser over Bluetooth Web API). I was trying a few pieces of code in the Espruino IDE. At some point the IDE have me an error: Uncaught Error: ERR 0x12 (CONN_COUNT) (:2550) - it seemed that there were many connections established with Bangle.js. I couldn't find any open connections so I ran NRF.disconnect(); from the IDE, which also disconnected the IDE itself.

    After doing this, I cannot seem to connect to IDE at all. When I select my bangle, the IDE shows this error: Connection Failed: NetworkError: Bluetooth Device is no longer in range.

    More importantly, when I try to connect to the App Loader to reinstall the default apps, once I select my bangle, my macOS prompts a window: Connection Request from Bangle.js b15a. Please enter a passcode shown on remote Bluetooth device. I didn't think Bangle.js 2 had this feature at all and actually the passcode is never shown on the watch.

    The watch is programmable and BLE is enabled.

    Has anyone ever encountered this problem? I have tried rebooting my watch but I continue to run into this problem.

    Thank you so much in advance!

Actions