• I added a setInterval to process the code ever 10 secs, the behaviour is now like this:

    • sometimes it is processed "OK" with the overshoot and the "uncaught error BLE task .... progress"
    • sometimes it result just in an "uncaught error ........ promise rejection", no data received

    Maybe you know the source of the "uncaught error ........ promise rejection"?

    Code and selection of output for reference below.

    
    setInterval(function() {
    
    
    var gatt;
    
    print("Getting data from server");
      
    NRF.connect("30:ae:a4:5d:b3:f2 public").then(function(g) {
      gatt = g;
      return gatt.getPrimaryService("6e400001-b5a3-f393-e0a9-e50e24dcca9e");
    }).then(function(service) {
      return service.getCharacteristic("6e400003-b5a3-f393-e0a9-e50e24dcca9e");
    }).then(function(characteristic) {
      characteristic.on('characteristicvaluechanged', function(event) {
        
        buf =E.toString(event.target.value.buffer);
        console.log("RX: "+buf);
        if(buf.includes("Quit")){
          print("Quit received, disconnecting now");
          gatt.disconnect();
        }
        
      });
      return characteristic.startNotifications();
    }).then(function() {
      console.log("Done!");
    });
    
    }, 10000);
    

    Output like this:

    Getting data from server
    Uncaught Error: Unhandled promise rejection: Disconnected
    Getting data from server
    Uncaught Error: Unhandled promise rejection: Disconnected
    Getting data from server
    Uncaught Error: Unhandled promise rejection: Disconnected
    Getting data from server
    RX: D07-06-2020 12.23
    RX: SAAPL,311.01,+11.5%
    RX: SASML,299.45,-4.5%
    RX: Hottentottententente
    RX: Quit
    Quit received, disconnecting now
    RX: D07-06-2020 12.23
    Uncaught Error: BLE task 4 is already in progress
     at line 1 col 149
    ...ting now");gatt.disconnect();}
                                  ^
    in function called from system
    RX: SAAPL,311.01,+11.5%
    RX: SASML,299.45,-4.5%
    RX: Hottentottententente
    Uncaught Error: Unhandled promise rejection: Disconnected
    Getting data from server
    Uncaught Error: Unhandled promise rejection: Disconnected
    Getting data from server
    RX: D07-06-2020 12.23
    RX: SAAPL,311.01,+11.5%
    RX: SASML,299.45,-4.5%
    RX: Hottentottententente
    RX: Quit
    Quit received, disconnecting now
    RX: D07-06-2020 12.23
    Uncaught Error: BLE task 4 is already in progress
     at line 1 col 149
    ...ting now");gatt.disconnect();}
                                  ^
    in function called from system
    RX: SAAPL,311.01,+11.5%
    RX: SASML,299.45,-4.5%
    RX: Hottentottententente
    Uncaught Error: Unhandled promise rejection: Disconnected
    Getting data from server
    Uncaught Error: Unhandled promise rejection: Disconnected
    Getting data from server
    Uncaught Error: Unhandled promise rejection: Disconnected
    Getting data from server
    RX: D07-06-2020 12.23
    RX: SAAPL,311.01,+11.5%
    RX: SASML,299.45,-4.5%
    RX: Hottentottententente
    RX: Quit
    Quit received, disconnecting now
    
About

Avatar for gerardwr @gerardwr started