Avatar for jnoble

jnoble

Member since Feb 2022 • Last active Feb 2022
  • 1 conversations
  • 2 comments

Most recent activity

  • in Bangle.js
    Avatar for jnoble

    Thanks for getting the comment, that did it!

    I was hoping to connect the Bangle to another app, so I've been testing using BlueSee. My approach is to upload my code via the WebIDE, reboot the device, reboot my Macbooks Bluetooth, start my app from the menu, scan with BlueSee, and then connect to my new service.

  • in Bangle.js
    Avatar for jnoble

    I've been working off of the excellent PuckStream app that AkosLukas ported to the Bangle and I've been running into some trouble.

    Below is my app which uploads fine, but running it seems to crash the BLE entirely. The Bangle isn't visible after I run this app, e.g. I can't see it in NRF connect nor can I connect to it via the Web IDE. After I quit the app sometimes I can reconnect via the Web IDE but sometimes it seems to hang for a long time and I just need to reboot the device entirely. I'm guessing that I'm doing something very wrong in my code which is below. I don't see a way to change the advertised name of the device while using setServices(), so that seems like it might be a problem, but I'm also not entirely sure what else I might be getting wrong here. Thanks for any advice!

    const bluetoothServiceUUID = 'f8b23a4d-89ad-4220-8c9f-d81756009f0c';
    const magCharacteristicUUID = 'f8b23a4d-89ad-4220-8c9f-d81756009f0c';
    const accelCharacteristicUUID = 'f8b23a4d-89ad-4220-8c9f-d81756009f0d';
    
    var count = 0;
    
    var batteryInterval, connected = false;
    
    function onMag(d) {
      if (connected) {
        NRF.updateServices({
          bluetoothServiceUUID: {
            magCharacteristicUUID: {
              value: new Int32Array([d.x, d.y, d.z]).buffer,
              notify: true
            }
          }
        });
      }
    }
    
    function onAccel(d) {
      if (connected) {
        NRF.updateServices({
          bluetoothServiceUUID: {
            accelCharacteristicUUID: {
              value: new Float32Array([d.x, d.y, d.z]).buffer,
              notify: true
            }
          }
        });
      }
    }
    
    function onInit() {
      // on connect / disconnect blink the green / red LED turn on / off the magnetometer
      NRF.on('connect', function () { connected = true;
                                      g.clear();
                                      g.setFont("Vector", 20); // vector font, 80px 
                                      g.drawString("connected", 5, 110);
                                      Bangle.setCompassPower(1); 
                                     });
      NRF.on('disconnect', function () { connected = false; 
                                         g.clear();
                                         g.setFont("Vector", 20); // vector font, 80px 
                                         g.drawString("ready", 5, 110);
                                         Bangle.setCompassPower(0); });
    
      // declare the services
      NRF.setServices({
        // Magneto&accelerometer service
        bluetoothServiceUUID: {
          magCharacteristicUUID: {
            description: 'Bangle magnetometer',
            notify: true,
            readable: true,
            value: new Int32Array([0, 0, 0]).buffer,
            writable: true,
            onWrite: function (evt) {
              var d = evt.data && evt.data[0];
              if ([80, 40, 20, 10, 5].indexOf(d) >= 0) { Bangle.setPollInterval(1000 / d); }
            }
          },
          accelCharacteristicUUID: {
            description: 'Bangle accelerometer',
            notify: true,
            readable: true,
            value: new Float32Array([0, 0, 0, 0, 0]).buffer
          }
        }
      }, 
      {advertise:[bluetoothServiceUUID]});
    
      Bangle.on('accel', onAccel);
      Bangle.on('mag', onMag);
    }
    
    
    onInit(); // set up our new services
    
    g.clear();
    g.setFont("Vector", 20); // vector font, 80px 
    g.drawString("ready", 5, 110);
    
Actions