read characteristic error BLE with evothings and rPi

401 Views Asked by At

I have rPi setup with node running bleno to advertise a characteristic. With evothings I am testing both Android and iOS and with both I got an error when reading the characteristic.

The code to read the characteristic within evothings is:

device.readServiceCharacteristic(
            'ff51b30e-d7e2-4d93-8842-a7c4a57dfb07',
            'ff51b30e-d7e2-4d93-8842-a7c4a57dfb08',

            function(data)
            {
              console.log('characteristic data: ' + evothings.ble.fromUtf8(data));
            },
            function(errorCode)
            {
              console.log('readCharacteristic error: ' + errorCode);
            });

The first uuid passed in is the service ID that I can see is right on the console log. The second uuid has been checked from the code on the server(rpi) side.

When I run this the console logs on iOS that an unlikely error has occurred. On Android it logs: error 1

For reference on the server I have followed this tutorial: https://www.hackster.io/inmyorbit/build-a-mobile-app-that-connects-to-your-rpi-3-using-ble-7a7c2c

I am trying to use this to learn about BLE but can't google my way out of such general errors.

1

There are 1 best solutions below

0
On

Before you can read a characteristic, you must follow the following steps:

  1. Scan for a device
  2. Connect to the device
  3. Get the service
  4. Read the characteristic

...it appears you're trying to do #4 without having completed the first 3. Here's an example derived from the Evothings API Guide:

var service = [];
var readData;

// Start scanning for BLE devices
evothings.ble.startScan(
    onDeviceFound,
    onScanError);

// This function is called when a device is detected, here
// we check if we found the device we are looking for.
function onDeviceFound(device)
{
    // Stop scanning.
    evothings.ble.stopScan();

    // Connect.
    evothings.ble.connectToDevice(
        device,
        onConnected,
        onDisconnected,
        onConnectError);
}

// Called when device is connected.
function onConnected(device)
{
    console.log('Connected to device');

    // Get service
    service = evothings.ble.getService(device, <insert service UUID>);

    // Read characteristic data
    evothings.ble.readCharacteristic(
        device,
        <insert characteristic UUID>,
        readSuccess,
        readError);
}

// Called if device disconnects.
function onDisconnected(device)
{
    console.log('Disconnected from device');
}

// Called when a connect error occurs.
function onConnectError(error)
{
    console.log('Connect error: ' + error)
}

// Read success callback
var readSuccess = function (data) {
   readData = evothings.ble.fromUtf8(data);
};

// Read error callback
var readError = function (error) {
    console.log('Read error: ' + error);
}