Comments (11)
Hi Luis,
Thank you, that solves the problem, now this Python command is successful:
conn = btle.Peripheral("CA:5B:3F:37:1D:A1","random")
However, note that the following command causes an exception:
python btle.py CA:5B:3F:37:1D:A1 random
The error occurs when one requests the characteristics of the service with index 0:
conn = btle.Peripheral("CA:5B:3F:37:1D:A1","random")
services = conn.getServices()
services[0].getCharacteristics()
Is there a reason why this occurs with random addresses only?
Stefano
from bluepy.
Hello Spedemon,
I initially had the same problem. The reason was that the btle.py does not expose the possibility to configure the address type of the device you want to connect to. The good surprise is that the bluepy-helper tool does support it so it was very easy to add it. Here is what I have changed in btle.py:
def connect(self, addr, addrtype="public"):
if len(addr.split(":")) != 6:
raise ValueError("Expected MAC address, got %s", repr(addr))
self._startHelper()
self.deviceAddr = addr
self.deviceAddrType = addrtype
self._writeCmd("conn %s %s\n" % (addr, addrtype))
rsp = self._getResp('stat')
while rsp['state'][0] == 'tryconn':
rsp = self._getResp('stat')
if rsp['state'][0] != 'conn':
self._stopHelper()
raise BTLEException(BTLEException.DISCONNECTED,
"Failed to connect to peripheral %s" % addr)
And when I invoked the Peripheral constructor:
conn = Peripheral(devaddr, deviceAddrType = "random")
and that worked fine. I have also added a few goodies to btle and to the bluepy helper to support disconnection and reconnection to the same device, this is useful to perform test automation. We I get a chance, I will try to post those changes to the development repo.
Have you looked at the Intel Community forum for Edison before posting your question (https://communities.intel.com/community/makers/edison)? If not, it may be worthwile for other Edison users if you could add your experience with bluepy in there (eventually a link to the current forum thread).
Thanks
Louis
from bluepy.
Hi Luis,
Thank you for your help! I will test it tonight at post back here. How do you manage the reconnection? Perhaps it would be useful to start an issue regarding reconnection.
Best,
Stefano
from bluepy.
Ciao Stefano,
The 'random' notion is only used at connection time so if your connection was successful, you should correctly retrieve the services and characteristics.
It is difficult for me with so little information to really help you. A few hints:
- enable the debug logs in btle.py
- use sudo hcidump to catch all the hci commands to your BT controller, this could help you find the source of the problem
Good luck,
Louis
PS: Quando avvrai trovato la soluzione, puoi condividerla sul forum Edison? Grazie
from bluepy.
If you want to share your btle.py with me, I can help you fix it.
Louis
from bluepy.
Hi Luis, thank you very much for your help. With the fix that you suggested, I can do what I need, however something is not right. After modifying btle.py according to your suggestion, the following runs successfully with 'do_get_characteristics_service_0 = False' but fails with 'do_get_characteristics_service_0=True':
import btle
do_get_characteristics_service_0 = False
mac = "CA:5B:3F:37:1D:A1"
conn = btle.Peripheral(mac,"random")
services = conn.getServices()
for i in range(len(services)):
if i==0:
if do_get_characteristics_service_0:
ch = services[i].getCharacteristics()
else:
ch = services[i].getCharacteristics()
Grazie! Nei prossimi giorni cercherò di postare nel forum Edison.
Stefano
from bluepy.
Hello Stefano,Since I do not have your setup, it is difficult for me to have an idea of the problem. But I will try to eventually give you some hints:- what is the size of the "services" returned by conn.getServices(), is it 1 or something else- could there be a permission problem on the service 0 that would require pairing
I suggest again that you capture the full hci logs and study them. I can do it for you if you want if you send them to me.
Louis
Le Jeudi 22 janvier 2015 16h33, Stefano Pedemonte <[email protected]> a écrit :
Hi Luis, thank you very much for your help. With the fix that you suggested, I can do what I need, however something is not right. After modifying btle.py according to your suggestion, the following runs successfully with 'do_get_characteristics_service_0 = False' but fails with 'do_get_characteristics_service_0=True': import btle
do_get_characteristics_service_0 = False
mac = "CA:5B:3F:37:1D:A1"
conn = btle.Peripheral(mac,"random")
services = conn.getServices()
for i in range(len(services)):
if i==0:
if do_get_characteristics_service_0:
ch = services[i].getCharacteristics()
else:
ch = services[i].getCharacteristics()Grazie! Nei prossimi giorni cercherò di postare nel forum Edison.
Stefano —
Reply to this email directly or view it on GitHub.
from bluepy.
I had the same problem with heart rate sensor Tacx (device name: Tacx HRB 04741)
After changing "public" to "random":
pi@occberry ~/bluepy/bluepy $ git diff bluepy-helper.c
diff --git a/bluepy/bluepy-helper.c b/bluepy/bluepy-helper.c
index 26a3dd7..5b102e8 100644
--- a/bluepy/bluepy-helper.c
+++ b/bluepy/bluepy-helper.c
@@ -461,7 +461,7 @@ static void cmd_connect(int argcp, char **argvp)
if (argcp > 2)
opt_dst_type = g_strdup(argvp[2]);
else
- opt_dst_type = g_strdup("public");
+ opt_dst_type = g_strdup("random");
}
if (opt_dst == NULL) {
@@ -963,7 +963,7 @@ int main(int argc, char *argv[])
opt_src = NULL;
opt_dst = NULL;
- opt_dst_type = g_strdup("public");
+ opt_dst_type = g_strdup("random");
printf("# " __FILE__ " built at " __TIME__ " on " __DATE__ "\n");
fflush(stdout);
it seems to work fine:
pi@occberry ~/bluepy/bluepy $ sudo python ./btle.py D6:90:A8:08:F0:E4
Connecting to: D6:90:A8:08:F0:E4
Service <uuid=Generic Attribute handleStart=8 handleEnd=11> :
Characteristic <2a05>
-> Error from Bluetooth stack (comerr)
Service <uuid=Generic Access handleStart=1 handleEnd=7> :
Characteristic <Device Name>
-> 'Tacx HRB 04741'
Characteristic <2a01>
-> 'A\x03'
Characteristic <2a04>
-> '\x90\x01 \x03\x00\x00\x90\x01'
Service <uuid=Battery Service handleStart=18 handleEnd=21> :
Characteristic <Battery Level>
-> 'd'
Service <uuid=Heart Rate handleStart=12 handleEnd=17> :
Characteristic <2a37>
-> Error from Bluetooth stack (comerr)
Characteristic <2a38>
-> '\x01'
Service <uuid=Device Information handleStart=22 handleEnd=65535> :
Characteristic <Manufacturer Name String>
-> 'Tacx'
Characteristic <Model Number String>
-> 'T1994'
Characteristic <Hardware Revision String>
-> 'V1.01'
Characteristic <Firmware Revision String>
-> 'V1.05'
Characteristic <Software Revision String>
-> 'V1.02'
I'm not sure what all those Error from Bluetooth stack (comerr)
mean, but without the changes it was always ending up with time out error
P.S. Those errors are the result of an attempt to read characteristic that doesn't support READ only NOTIFY
from bluepy.
@spedemon - I've merged @PrzemoF 's changes in commit ad2de26.
Could you confirm if this solves the original problem? If so I'll close the issue.
Thanks,
Ian
from bluepy.
Hi Ian,
Thanks a lot. I will try on Saturday and will write back!
Stefano
from bluepy.
Hi,
I am facing issue while using btle.py
Please find below error message while running code on Linux
p = Peripheral("C8:0F:10:77:3C:38","public")
File "/usr/lib/python2.7/site-packages/bluepy/btle.py", line 318, in init
self.connect(deviceAddr, addrType, iface)
File "/usr/lib/python2.7/site-packages/bluepy/btle.py", line 367, in connect
"Failed to connect to peripheral %s, addr type: %s" % (addr, addrType))
bluepy.btle.BTLEException: Failed to connect to peripheral C8:0F:10:77:3C:38, addr type: public
Kindly help
Thank you,
Shruti
from bluepy.
Related Issues (20)
- bluepy.btle.BTLEManagementError: Failed to execute management command 'scan' HOT 1
- How to get PDU Type?
- Passive scan returns weird connectable
- bluepy-helper crashes HOT 1
- Sampling frequency HOT 6
- thon3
- BluePy not compatible with Python 3.10 or newer
- Multiple Instances of a single Service
- Reading Accelerometer Data from SensorTag CC2650
- Try to use timeout HOT 4
- getting temperature data
- unable to make it work on Python 3.7.3
- Failed to connect to peripheral <my mac address>, addr type: random HOT 4
- Select a host Bluetooth device (the one that starts the connection) HOT 7
- ResourceWarning: unclosed file <_io.TextIOWrapper name=6 encoding='UTF-8'>
- Infinite timeout
- HCI Selection Failure HOT 1
- Help! Loaded everything but doesn't see the camera.
- Unable to set connection parameters and advertasing parameters Thingy:52
- Bluepy and Bookworm HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bluepy.