Avatar for ThomasVikström

ThomasVikström

Member since Dec 2016 • Last active Jan 2024
  • 7 conversations
  • 82 comments

Most recent activity

  • in Bangle.js
    Avatar for ThomasVikström

    If you mean where on your iPhone the files are, they might perhaps be found in "Files". On your phone, open your Files app and check if they are there.

    • 5 comments
    • 619 views
  • in Bangle.js
    Avatar for ThomasVikström

    Thx!

    If you didn't have that, you could set Bangle.js to just do a read every so often to get the latest data (rather than having it 'pushed')

    My "use case" (actually only proof of concept) is to run inference (using Tensorflow Lite) on the Nicla-device and push the results to Bangle, perhaps also pushing some sensor data. To save power on both devices, I'm thinking of starting the Bluetooth-connection every 5 minutes or so. This is something I haven't looked into yet how to do, using setInterval perhaps?
    Anyhow, so far this use case is more of a solution searching for a problem instead of a clear requirement, so not sure yet what I'm going to do, need to brainstorm a bit :-)

  • in Bangle.js
    Avatar for ThomasVikström

    Ok, success! Not that I know why it did not work in the first place, but by getting rid of the cccd-handle altogether, I'm now able to receive data from 6 sensors to Bangle + calculating altitude from the barometer.

    31.54c co2:554 IAQ:56 Hum:25 1001.64 pa Gas:34170 Alt:-0.17m

    For the benefit of others, here's what I did:

    On Bangle side:
    Nothing, i.e. no need to handle_cccd = ...,

    On Arduino side:

    Changed to:

    BLEShortCharacteristic temperatureCharacteristic(BLE_SENSE_UUID­("2001"), BLERead | BLENotify);
    
    

    from:

    BLEShortCharacteristic temperatureCharacteristic(BLE_SENSE_UUID­("2001"), BLERead);
    
    

    ...and put this in the loop function:

    void loop(){
      while (BLE.connected()){
    
        static auto printTime = millis();
    
        BHY2.update();
        nicla::leds.setColor(blue);
    
        if (millis() - printTime >= 1000) {
    
          printTime = millis();
    
          float temperatureValue = temperature.value();
          temperatureCharacteristic.writeValue(tem­peratureValue * 100);
          Serial.println(temperatureValue);
    
          uint32_t co2 = bsec.co2_eq();
          co2Characteristic.writeValue(co2);
    
          float airQuality = float(bsec.iaq());
          bsecCharacteristic.writeValue(airQuality­);
    
          float pressureValue = pressure.value();
          pressureCharacteristic.writeValue((press­ureValue - 800) * 100);
          Serial.println(pressureValue);
    
          float humidityValue = humidity.value();
          humidityCharacteristic.writeValue(humidi­tyValue);
          
          unsigned int g = gas.value();
          gasCharacteristic.writeValue(g);
        }
    
    
  • in Bangle.js
    Avatar for ThomasVikström

    Sorry, but I'm again a bit stuck with BLE, my issue is actually same/similar as this one, but that's 2 years old and perhaps for another device than Bangle.

    As posted here, I've been able to connect and transmit data from an Arduino-device (Nicla Sense ME), but the Arduino-program crashes with an ambigous message "Out of memory" when I want to transmit data from more sensors, this even if only approx. 50% of the memory is used. As this is for me very challenging to troubleshoot, I thought I'd instead use this Arduino-code, that is transmitting to a WebBLE dashboard. The web dashboard works fine.

    However, when trying to connect from Bangle, a connection is established, but I initially got CCCD Handle not found. The Arduino advertising code is using this BLEFloatCharacteristic temperatureCharacteristic("19b10000-2001­-537e-4f6c-d104768a1214", BLERead); where I've from BLEProperty.h found out that BLERead = 0x02. Thus I tried using the same on the Bangle side:

        ch.handle_cccd = 0x02;
        return ch.startNotifications();
    

    but I'm still not receiving any data. nRFConnect is very seldom able to connect to the Nicla-device, but the few times it has been, I've not seen anything related to this cccd-handle.

    To further troubleshoot, I've tried to replace BLERead with 0x00 on the Arduino-side and use same cccd-handle on Bangle, did not help, a connection is established but no data is flowing.

    I also dived in the WebBLE-dashboard JS-code to understand how that works, and on line 11 below (line 450 in the dashboard code) this same BLERead property is used. But as said, when I'm using the same concept in the Bangle-code, I'm not getting anywhere.
    I've also tried many other permutations, too many to list here, but either I get "CCCD handle not found" or no data.

        // Set up the characteristics
        for (const sensor of sensors) {
          msg('characteristic ' + sensor + "...");
          NiclaSenseME[sensor].characteristic = await service.getCharacteristic(NiclaSenseME[s­ensor].uuid);
          // Set up notification
          if (NiclaSenseME[sensor].properties.include­s("BLENotify")) {
            NiclaSenseME[sensor].characteristic.addE­ventListener('characteristicvaluechanged­', function (event) { handleIncoming(NiclaSenseME[sensor], event.target.value); });
            await NiclaSenseME[sensor].characteristic.star­tNotifications();
          }
          // Set up polling for read
          if (NiclaSenseME[sensor].properties.include­s("BLERead")) {
            NiclaSenseME[sensor].polling = setInterval(function () {
              NiclaSenseME[sensor].characteristic.read­Value().then(function (data) { handleIncoming(NiclaSenseME[sensor], data); })
            }
              , 500);
          }
    
  • in Bangle.js
    Avatar for ThomasVikström

    Yes, this works! It makes sense now when I added it and see the whole code.
    Thx a lot @fanoush !
    Posting the whole code here so others may benefit from it

      NRF.connect("F5:CB:47:42:E3:BB public").then(function(g) {
        gatt = g;
    
        return gatt.getPrimaryService("07e1f0e2-b68f-4f­71-8bfc-19b3b0427b68");
      }).then(function(service) {
        return service.getCharacteristic("5d75d722-fce9­-471b-93e2-6c625ef6d634");
      }).then(function(characteristic) {
        characteristic.on('characteristicvaluech­anged', function(temperature) {
          temp = temperature.target.value.buffer;
          temp = (temp[1] * 256 + temp[0]) / 100;
          console.log("Temp: ", temp);
        });
        return characteristic.startNotifications();
      }).then(function(){
        return gatt.getPrimaryService("07e1f0e2-b68f-4f­71-8bfc-19b3b0427b68");
      }).then(function(service) {
        return service.getCharacteristic("5d75d723-fce9­-471b-93e2-6c625ef6d634");
      }).then(function(characteristic) {
         characteristic.on('characteristicvaluech­anged', function(co2) {
          co2 = co2.target.value.buffer;
          co2 = (co2[1] * 256 + co2[0]);
          console.log("co2 : ", co2);
      });
          return characteristic.startNotifications();
      }).then(function() {
        console.log("Done!");
      }).catch(function(e) {
        E.showMessage(e.toString(), "ERROR");
        console.log(e);
      });
    
  • in Bangle.js
    Avatar for ThomasVikström

    Thx, but I've tried that as well. If I uncomment it, I get a message on next line Unreachable 'return' after 'return', and this time only the temperature is being shown, not the co2 value. So I assume a function can only return one "thing", not several.

  • in Bangle.js
    Avatar for ThomasVikström

    Slight progress as I was able to chain two characteristics, but only the second one showing co2 values is doing something. The first one is supposed to show temperature, but seems it is not reached as I only see co2 values. I've read up on JS promises but haven't found out how to receive and show several values.

      NRF.connect("F5:CB:47:42:E3:BB public").then(function(g) {
        gatt = g;
    
        return gatt.getPrimaryService("07e1f0e2-b68f-4f­71-8bfc-19b3b0427b68");
      }).then(function(service) {
        return service.getCharacteristic("5d75d722-fce9­-471b-93e2-6c625ef6d634");
      }).then(function(characteristic) {
        characteristic.on('characteristicvaluech­anged', function(temperature) {
    
          temp = temperature.target.value.buffer;
          temp = (temp[1] * 256 + temp[0]) / 100;
          console.log("Temp: ", temp);
        });
        //return characteristic.startNotifications();
        return gatt.getPrimaryService("07e1f0e2-b68f-4f­71-8bfc-19b3b0427b68");
    
      }).then(function(service) {
        return service.getCharacteristic("5d75d723-fce9­-471b-93e2-6c625ef6d634");
      }).then(function(characteristic) {
         characteristic.on('characteristicvaluech­anged', function(co2) {
     
          co2 = co2.target.value.buffer;
          co2 = (co2[1] * 256 + co2[0]);
          console.log("co2 : ", co2);
      });
          return characteristic.startNotifications();
      }).then(function() {
        console.log("Done!");
      }).catch(function(e) {
        E.showMessage(e.toString(), "ERROR");
        console.log(e);
      });
    
  • in Bangle.js
    Avatar for ThomasVikström

    I'm in a bit of similar situation, did you get it working? Able to share the code?
    Trying myself but as I'm not understanding everything, it's a hit-or-miss if I succeed.

Actions