How to assign service UUID and how to retrieve it
Posted: 07:56, 08 Sep 2014
Hi guys,
I am having a little bit of issue and I was wondering if someone could please help me with that.
I currently know the uuid of the device that I want to connect to and I get connected to it fine. However what I want to do is being able to receive data from the is sent to my mobile phone from the RFDuino.
I am not entirely sure what are the characteristics and how to get services etc. I would highly appreciate if you could please take a look at my code and let me know what I am doing wrong here ? Please see my codes below. for the phone gap part I have only copied the relevant methods.
Many thanks in advance.
Farzan
This is what I have in the phone gap side :
And this is what I have in the RFduino :
I am having a little bit of issue and I was wondering if someone could please help me with that.
I currently know the uuid of the device that I want to connect to and I get connected to it fine. However what I want to do is being able to receive data from the is sent to my mobile phone from the RFDuino.
I am not entirely sure what are the characteristics and how to get services etc. I would highly appreciate if you could please take a look at my code and let me know what I am doing wrong here ? Please see my codes below. for the phone gap part I have only copied the relevant methods.
Many thanks in advance.
Farzan
This is what I have in the phone gap side :
Code: Select all
function connectToBLE(){
// $scope.bleDevice['address'] give me the correct map
evothings.ble.connect($scope.bleDevice['address'],
function(connectInfo){
//I am getting connected correctly
$scope.result = connectInfo.toString();
deviceHandle = connectInfo.deviceHandle;
getServices(deviceHandle);
startReadingBLE();
}
,function(err){
$scope.result = err;
});
}
function getServices(deviceHandle){
// gets here but failes to run this method, any idea ?
evothings.ble.services(deviceHandle, function(service)
{
alert(service.service.uuid);
var characteristic = service.characteristics[ci];
for (var si in services)
{
var service = services[si];
for (var ci in service.characteristics)
{
if (characteristic.uuid == $scope.bleDevice['address'])
{
characteristicRead = characteristic.handle;
startReadingBLE();
}
}
}
},
function(errorCode)
{
$scope.result='Service error: ' + errorCode;
});
}
function stopReadingBLE(){
try{
evothings.ble.disableNotification(
deviceHandle,
characteristic.handle,
function()
{
},
function(errorCode)
{
});
}catch(err){
$scope.result = err;
}
}
function startReadingBLE(){
evothings.ble.enableNotification(
deviceHandle,
characteristicRead,
onSuccess,
function(errorCode)
{
$scope.result ="BLE enableNotification error:" + errorCode;
});
}
And this is what I have in the RFduino :
Code: Select all
#include <RFduinoBLE.h>
bool isconnected = false;
void setup() {
// setup the leds for output
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
RFduinoBLE.advertisementData = “Test";
RFduinoBLE.deviceName ="Amigo";
// start the BLE stack
RFduinoBLE.begin();
}
void loop() {
// switch to lower power mode
RFduino_ULPDelay(INFINITE);
if (isconnected){
delay(3000);
RFduinoBLE.send('hello');
}
}
void RFduinoBLE_onConnect() {
isconnected = true;
}
void RFduinoBLE_onDisconnect() {
}
void RFduinoBLE_onReceive(char *data, int len) {
}