• 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);
      });
    
  • 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();
    
  • 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.

About

Avatar for fanoush @fanoush started