-
• #2
it looks like async/await is not supported, is it?
-
• #3
well, for chaining you can simply continue in same way, before line 23 you can continue like line 12 with another service?
-
• #4
Hmm... well, yes, why not.... I'll try.
-
• #5
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. -
• #6
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); });
-
• #7
The first one is supposed to show temperature, but seems it is not reached as I only see co2 values.
maybe because you commented out line 14 ?
//return characteristic.startNotifications();
-
• #8
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. -
• #9
oh, of course you need to add one more
}).then(function() {
chain between returns like lines 15-19
-
• #10
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); });
Hi.
I've created Android app that serves Location and Navigation service, Device info, and Time service (standard GATT profiles). LNS has 3 characteristics.
Currently in Bangle JS2 client app I can subscribe to one service, one characteristic.
How to subscribe for LNS multiple characteristics, and to Time service, and also query Device info? Each .then() has only one return, I am not getting how to fork or chain it.