Well, nice try but no difference, gatt is disconnected after the 1000ms delay.
function Connect(dev){ NRF.requestDevice({ filters: [{ name: Devname }] }).then(function(device) { return device.gatt.connect(); }).then(function(g) { gatt = g; console.log(gatt); return new Promise(function(resolve) { setTimeout(resolve, 1000); console.log("delayed for 1000ms..."); }); }).then(function() { console.log("end delay"); return gatt.getPrimaryService(serviceUUID); }).then(function(service) { return service.getCharacteristic(characteristicUUID); }).then(function(characteristic) { return characteristic.writeValue(MessageToSend); }).then(function() { console.log("Done!"); }); }
Which, when executed, gives:
>Connect(MyDev) =undefined BluetoothRemoteGATTServer { "device": BluetoothDevice { "id": "96:05:05:f7:ac:1c random", "rssi": -64, "services": [ ], "data": new Uint8Array([2, 1, 4, 12, 9, 72, 75, 73, 18, 45, 54, 30, 54, 48, 49, 57]).buffer, "name": "MyActuator", "gatt": ... }, "connected": true } delayed for 1000ms... end delay Uncaught Error: Unhandled promise rejection: Not connected >
I really can't understand why it connects THEN disconnects quickly.
@Jean-Philippe_Rey started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Well, nice try but no difference, gatt is disconnected after the 1000ms delay.
Which, when executed, gives:
I really can't understand why it connects THEN disconnects quickly.