IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.6k stars 490 forks source link

Multiple Peripheral, Single Raspberry Pi #329

Open neal-tommy82 opened 5 years ago

neal-tommy82 commented 5 years ago

@IanHarvey

Any example code, or base level instructions as to how to adjust the code to be able to connect to multiple Thunderboard Sense boards (for sensor data capturing and IoT storage / analysis)?

At the moment I'm running a somewhat brought together code which has this as the connection part:

`def vReadSENSE(): scanner = Scanner(0) devices = scanner.scan(2) for dev in devices: print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)

    for (adtype, desc, value) in dev.getScanData():
        print "  %s = %s" % (desc, value)
num_ble = len(devices)
print num_ble
if num_ble == 0:
    return None
ble_service = []
char_sensor = 0
non_sensor = 0
TVOC_char = Characteristic
eCO2_char = Characteristic
Pressure_char = Characteristic
Sound_char = Characteristic
temperature_char = Characteristic
humidity_char = Characteristic
ambient = Characteristic

count = 15

for i in range(num_ble):
    try:
        devices[i].getScanData()
        ble_service.append(Peripheral())
        ble_service[char_sensor].connect('00:0b:57:36:63:ff',devices[i].addrType)
        #ble_service[char_sensor].connect(devices[i].addr, devices[i].addrType)
        char_sensor = char_sensor + 1
        print "Connected %s device with addr %s " % (char_sensor, devices[i].addr)
    except:
        non_sensor = non_sensor + 1
try:
    for i in range(char_sensor):

        services = ble_service[i].getServices()
        characteristics = ble_service[i].getCharacteristics()

`

Would I need to call the ble_service[char_sensor]... again with a different name in the []? char_sensor_1 perhaps? Or is the ble_service the unique name for each BLE peripheral?

Sorry for the entry-level type questions here however I cannot seem to find an example from the code snippets online. Any help would be most appreciated.

Regards,

Neal Johannesburg

dhruvkakadiya commented 5 years ago

Running multiple instances of the same script(just change peripheral MAC address) works for me which is not ideal thing to do. But you can try that if that fulfills your purpose.