ThomasVikström
Member since Dec 2016 • Last active Jan 2025Most recent activity
-
-
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 :-) -
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(temperatureValue * 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((pressureValue - 800) * 100); Serial.println(pressureValue); float humidityValue = humidity.value(); humidityCharacteristic.writeValue(humidityValue); unsigned int g = gas.value(); gasCharacteristic.writeValue(g); }
-
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 thisBLEFloatCharacteristic temperatureCharacteristic("19b10000-2001-537e-4f6c-d104768a1214", BLERead);
where I've from BLEProperty.h found out thatBLERead = 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[sensor].uuid); // Set up notification if (NiclaSenseME[sensor].properties.includes("BLENotify")) { NiclaSenseME[sensor].characteristic.addEventListener('characteristicvaluechanged', function (event) { handleIncoming(NiclaSenseME[sensor], event.target.value); }); await NiclaSenseME[sensor].characteristic.startNotifications(); } // Set up polling for read if (NiclaSenseME[sensor].properties.includes("BLERead")) { NiclaSenseME[sensor].polling = setInterval(function () { NiclaSenseME[sensor].characteristic.readValue().then(function (data) { handleIncoming(NiclaSenseME[sensor], data); }) } , 500); }
-
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 itNRF.connect("F5:CB:47:42:E3:BB public").then(function(g) { gatt = g; return gatt.getPrimaryService("07e1f0e2-b68f-4f71-8bfc-19b3b0427b68"); }).then(function(service) { return service.getCharacteristic("5d75d722-fce9-471b-93e2-6c625ef6d634"); }).then(function(characteristic) { characteristic.on('characteristicvaluechanged', 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-4f71-8bfc-19b3b0427b68"); }).then(function(service) { return service.getCharacteristic("5d75d723-fce9-471b-93e2-6c625ef6d634"); }).then(function(characteristic) { characteristic.on('characteristicvaluechanged', 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); });
-
-
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-4f71-8bfc-19b3b0427b68"); }).then(function(service) { return service.getCharacteristic("5d75d722-fce9-471b-93e2-6c625ef6d634"); }).then(function(characteristic) { characteristic.on('characteristicvaluechanged', 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-4f71-8bfc-19b3b0427b68"); }).then(function(service) { return service.getCharacteristic("5d75d723-fce9-471b-93e2-6c625ef6d634"); }).then(function(characteristic) { characteristic.on('characteristicvaluechanged', 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); });
-
Partly related to this, I spent some time a couple of months ago in prototyping an app which recognizes different activities. This is using Edge Impulse and thus TensorFlow. The tutorial was now published and can be found here.
Disclaimer: While the app works pretty well for me, it's still only a prototype and the code is partly a mess. I tried to use ChatGPT to clean it up, but I got in an endless loop of it breaking existing functionality, and run out of time.