Wipy + CC2650 - Bluetooth connection fail / return closed GATTCConnection
I'm trying to connect to a TI CC2650 sensor using bluetooth from Wipy 2.0
I'm using the release 1.6.12.b1.
Here is my code
bt = Bluetooth() print("Scanning devices (press ctrl+c to stop scanning)") bt.start_scan(-1) advertisements =  ### Scanning devices ### try: while True: time.sleep(1) print(".", end="") register_device(advertisements, bt.get_adv()) except KeyboardInterrupt: print("\nScan finished :\n") bt.stop_scan() if len(advertisements) > 0: ### Print detected devices ### print(str(len(advertisements)) + " devices detected :") for adv in advertisements: print("\tRaw advertisement : " + str(adv)) print("\t\tMac address : " + str(binascii.hexlify(adv.mac))) print("\t\tData : " + str(binascii.hexlify(adv.data))) name = bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) manufacturer = bt.resolve_adv_data(adv.data, Bluetooth.ADV_MANUFACTURER_DATA) print("\t\tName : " + str(name)) print("\t\tManufacturer : " + str(manufacturer)) print() print() ### Ask user to select device ### print("To which device do you want to connect?") i = 0 for adv in advertisements: print(str(i) + " - " + str(bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL)) + " : " + str(binascii.hexlify(adv.mac))) i+=1 chosen_device = input() ### Connecting to the selected device ### dev_mac = advertisements[int(chosen_device)].mac print("Connecting to " + str(bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL)) + " : " + str(binascii.hexlify(adv.mac))) connection = bt.connect(dev_mac) if connection.isconnected(): print("\tConnection succesful") else: print("\tConnection failed") print(connection) services = connection.services() print(services) else: print("No device detected")
The problem I'm facing is I can't connect to the sensor. Or I can connect but with a closed connection.
Here is the execution of the code
PYB: soft reboot
Scanning devices (press ctrl+c to stop scanning)
Scan finished :
1 devices detected :
Raw advertisement : (mac=b'\xb0\xb4H\xc9Q\x86', addr_type=0, adv_type=3, rssi=-39, data=b'\x02\x01\x05\x03\x02\x80\xaa\x06\xff\r\x00\x03\x00\x00\x11\tCC2650 SensorTa')
Mac address : b'b0b448c95186'
Data : b'020105030280aa06ff0d0003000011094343323635302053656e736f725461'
Name : CC2650 SensorTa
Manufacturer : b'\r\x00\x03\x00\x00'
To which device do you want to connect?
0 - CC2650 SensorTa : b'b0b448c95186'
Connecting to CC2650 SensorTa : b'b0b448c95186'
Traceback (most recent call last):
File "main.py", line 86, in <module>
OSError: connection already closed
MicroPython v1.8.6-593-g8e4ed0fa on 2017-04-12; WiPy with ESP32
Type "help()" for more information.
When it succeeds to connect, it returns me a GATTCConnection but when I try a .isconnected(), the connection is always closed yet.
If I understood well, if the connection failed I should not have a GATTCConnection object but a NoneType object. So I conclude the connection work but for an unknown reason the connection is closed.
As you can see I also try to access a service on this connection but as predicted it fails.
I've read that it could come from the firmware version here : https://forum.pycom.io/topic/791/bluetooth-wipy-client-connecting-to-wipy-peripheral
Does anyone already had a similar problem or know from where it could come from ?
@berni I don't know if the bug was solved in new firmware releases, You should try the same code on the 1.4.0.b1 version, maybe it'll solve your problem.
I'm trying to talk to the SensorTag with the LoPy and I have the same issues with the latest firmware. Anyone has made any progress or could create a connection and retrieve data from a SensorTag?
@jmarcelino Hi, I was running the TI demo code as I just programmed the Wipy, I didn't modify the sensor or added a DevPack if that's what you're asking for.
Sorry to bring up this older topic but what are you running on your Sensortag? Is it just the TI demo code or something custom?
@Arkaik Finally the firmware version was the problem, after downgrading it to 1.4.0.b1 everything worked fine.
Does someone know why it doesn't work with new releases? Will this bug be fixed?
Even if the program works now I woud like to be able to upgrade the firmware later.