Closed don41382 closed 8 years ago
You can try to connect using GattTool (How to use manually with Gatttool) to see if you get disconnected after the second command.
If this is the case then there's probably a compatibility problem with your bluetooth device It may also be a problem with bluetooth library (libbluetooth-dev).
I can't investigate further, I'm moving out of the country in a few months and right my bulb is thousand miles away from me... unfortunately bluetooth 4.0 isn't that powerful!
Good luck, keep me in touch if you find anything
Hey Betree,
Thanks for your fast response. I tried using the GattTool and it works like charm!
gatttool -i hci0 -b 'DE:0C:59:91:F3:81' -t random -I
[DE:0C:59:91:F3:81][LE]> connect
Attempting to connect to DE:0C:59:91:F3:81
Connection successful
[DE:0C:59:91:F3:81][LE]> char-write-req 0x000c 56FFFFFF00f0aa
Characteristic value was written successfully
[DE:0C:59:91:F3:81][LE]> char-write-req 0x000c 56FF000000f0aa
Characteristic value was written successfully
Do you think it might be the pygattlib? I would appreciate any further help with this! By the way, where you going? Just moved to Australia and exchanged my HUE lights to Magic Blue :-) So, thanks for you project!
Not so far away from you actually, I'm moving to New Caledonia :)
Pygattlib hasn't been updated since I last tested it so I doubt it came from this lib. Maybe a difference in libbluetooth-dev version ? I can't tell which one I use to have installed, it would be nice if someone who has a working installation can provide the info.
Another possibility is that they changed some stuff in the bulb API in the newest versions (i bought mine around September 2015). It can also be a bug in my code but again I can't really test it right now.
So, what can you do ?
I had the exact same problem on the same platform (Raspbian, RPI-B 256mb). Adding more pauzes between commands seemed to lower the freezing frequency, but my scripts remained unstable. The issue was with the pygattlib and was beyond my technical capabilities. I could not use Benjamin's library and had to fall back to running shell commands, which have not failed even once.
Thanks @b0tting for the reply! I found a solution. I switched to bluepy python interface (https://github.com/IanHarvey/bluepy). Using this library solved the problem. I could change the current code to use this library. @Betree: Would that be okay for you?
import bluepy.btle bulb_id = 'DE:0C:59:91:F3:81' p = bluepy.btle.Peripheral(bulb_id, bluepy.btle.ADDR_TYPE_RANDOM) p.writeCharacteristic(0x000c,b'\xCC\x23\x33',True) #TURN ON p.writeCharacteristic(0x000c,b'\xCC\x24\x33',True) #TURN OFF
Bluepy looks a lot more maintained than pygattlib, that seems great !
@Betree alright, I am going to update your code to the bluepy project on the weekend :-)
And I guess, I am going to implement some of your new functionality @b0tting
After starting magicblueshell, connecting to my Magic Blue Bulb and firing the second command, magiblueshell hangs for a while and stops without any further output.
Hardware / Software Raspberry PI Model B Revision 2.0 256 MB
Execution
Do you have any idea why this happens?