Closed NitishDeshpande closed 8 years ago
Can you post the rest of your code? And what version of the plugin are you using?
I am using version 3.0.1.
Here is rest of the code which initializes and connects before writing or reading,
$scope.initialize = function(){
$cordovaBluetoothLE.initialize({request:true}).then(null,
function(obj) {
//Handle errors
console.log(obj);
},
function(obj) {
//Handle successes
console.log('success');
}
);
};
$scope.connect = function(){
$cordovaBluetoothLE.connect({address:"C2:A7:51:2C:F1:47"}).then(null,
function(obj) {
//Handle errors
console.log(obj.message);
},
function(obj) {
if (obj.status == "connected") {
console.log(obj);
console.log('Connected');
} else {
console.log('Disconnected');
}
}
);
};
$scope.write =function() {
var params = {
address:"C2:A7:51:2C:F1:47",
service:"713d0000-503e-4c75-ba94-3148f18d941e",
characteristic: "713d0003-503e-4c75-ba94-3148f18d941e",
value:"hello world",
timeout: 3000
};
console.log("Write : " + JSON.stringify(params));
$cordovaBluetoothLE.write(params).then(function(obj) {
console.log("Write Success : " + JSON.stringify(obj));
}, function(obj) {
console.log("Write Error : " + JSON.stringify(obj));
});
};
I am getting a similar error when I am subscribing, (console logs shown below)
Request-
Subscribe : {"address":"C2:A7:51:2C:F1:47",
"service":"713d0000-503e-4c75-ba94-3148f18d941e",
"characteristic":"713d0002-503e-4c75-ba94-3148f18d941e",
"timeout":2000
}
Subscribe Error : {"error":"service",
"message":"Service not found",
"address":"C2:A7:51:2C:F1:47",
"name":"ble-Micro"}
You need to discover the device first. Please check out the plugin's readme: https://github.com/randdusing/cordova-plugin-bluetoothle
Thanks for quick response. Discovery is done mainly to determine the address of the device, the services available and their corresponding characteristic. I already know the address, service uuid and characteristic uuid using another android app (BLE Scanner). Shouldn't this be fine?
Unfortunately no, you must discover the device even if you already know what's on it.
Ohh okay! Will try it and let you know :)
I tried the discovery method before calling the write/subscribe methods.
Can you post the error message when the app closes? Check out the encodedStringToBytes and bytesToString functions to decode the base64 encoded string.
@randdusing Thanks for your support. I was able to do the subscribe() and write() operations successfully. I have used the methods to convert string to bytes and bytes to encoded string and other utility functions. All of these work as expected without any issues. Hence, closing this issue.
Hi I am trying to send a message to a BLE node using GATT connection. I am able to establish a connection but I am not able to send a message. This is the error I am facing, Write Error : {"error":"service","message":"Service not found","address":"C2:A7:51:2C:F2:37","name":"ble-Micro"} My request looks like this,
Any kind of help is appreciated.