cancel
Showing results for 
Search instead for 
Did you mean: 

Sensortile.boxpro Bluetooth

Frabbit
Associate III

Hello everyone, I'm using a STEVAL-MKBOXPRO connected to an RPi3B+ to receive data via Bluetooth.

The BLESensors code is integrated into Sensortile.

I've tried two approaches and for now I'm stuck:

  • Using the BlueSTSDK library, I've run example_ble_1.py with sudo (Python version is 3.7).
pi@raspberrypi:~/BlueSTSDK_Python/blue_st_examples $ sudo python3 example_ble_1.py 

##################
# BlueST Example #
##################

Scanning Bluetooth devices...

Discovery started.
Discovery stopped.

Discovery started.
Discovery stopped.

No Bluetooth devices found. Exiting...

Trying both synchronously and asynchronously to find the device, but it's not being detected (very strange because I can find it from the RPi3 and also from the Android app).

On the other hand, trying a different approach using the bleak library, writing this code manages to connect to the device.

 

#import asyncio
from bleak import BleakScanner

#async def main():
#    devices = await BleakScanner.discover()
#    for d in devices:
#        print(d)

#asyncio.run(main())
import asyncio
from bleak import BleakClient
from bleak.backends.characteristic import BleakGATTCharacteristic

MODEL_NAME = "BLSenBP"


async def main():
    try:
        print("--- Scanning for device")
        device = await BleakScanner.find_device_by_name(MODEL_NAME,10.0)
        #client = BleakClient(device.address)
        if device is None:
            print("--- Device not found")
        else:
            print("--- Connecting to device")
            async with BleakClient(device.address) as client:
                #connected to device
                #services= client.services
                #print(services)
                while(1):
                    #read battery
                    stringa= await client.read_gatt_char("00020000-0001-11e1-ac36-0002a5d5c51b")
                    print(stringa)
            # Device will disconnect when block exits.    
            print("--- Disconnected from device")
        #model_number = await client.read_gatt_char(MODEL_NBR_UUID)
        #print("Model Number: {0}".format("".join(map(chr, model_number))))
    except Exception as e:
        print(e)
    finally:
        print("end program")

asyncio.run(main())

When I try to read through the battery UUID, it says that I cannot read it.

--- Scanning for device
--- Connecting to device
[org.bluez.Error.NotPermitted] Read not permitted
end program

What can I do? Has anyone else had the same issue and can help me?

0 REPLIES 0