Here it is:
Please note DevName,serviceUUID,characteristicUUID and MessageToSend have been replaced in the code below because of confidentiallity agreement.
var devices;
var gatt;
var DevName="MyActuator";
var serviceUUID="2fc3af42-7a4a-1431-d1f1-fs551e3bf022";
var characteristicUUID="32160fb9-5337-4e71-b0f8-ff412e3ae078";
var MessageToSend=[0x00,0x01,0x03];
function scan(){
NRF.findDevices(function(d) {
devices = d;
console.log(devices);
}, 5000);
}
function SendCommandToActuator() {
NRF.requestDevice({ filters: [{ name: DevName }] }).then(function(device) {
return device.gatt.connect();
}).then(function(g) {
gatt = g;
console.log(gatt);
return gatt.getPrimaryService(serviceUUID);
}).then(function(service) {
return service.getCharacteristic(characteristicUUID);
}).then(function(characteristic) {
return characteristic.writeValue(MessageToSend);
}).then(function() {
gatt.disconnect();
console.log("Done!");
});
}
function Bond(){
NRF.requestDevice({ filters: [{ name: DevName }] }).then(function(device) {
console.log("found device");
return device.gatt.connect();
}).then(function(g) {
gatt = g;
console.log("connected");
return gatt.startBonding();
}).then(function() {
console.log("bonded", gatt.getSecurityStatus());
gatt.disconnect();
}).catch(function(e) {
console.log("ERROR",e);
});
}
When I load this script and I call SendCommandToActuator(), I get this log:
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.
Here it is:
Please note
DevName
,serviceUUID
,characteristicUUID
andMessageToSend
have been replaced in the code below because of confidentiallity agreement.When I load this script and I call
SendCommandToActuator()
, I get this log: