03.04.2019, 12:24
Why my gateway can only connect to the Xiaomi band 2, but not to other Bluetooth devices
Why my gateway can only connect to the Xiaomi band 2,
|
03.04.2019, 12:24
Why my gateway can only connect to the Xiaomi band 2, but not to other Bluetooth devices
03.04.2019, 12:31
Which other devices?
03.04.2019, 12:31
(This post was last modified: 03.04.2019, 12:33 by 1114752670@qq.com.)
The Bluetooth adapter I use is CSR 4.0. I want to use it to connect other devices, such as CC2541 and CC2640. I can search for the Bluetooth of CC2541 and CC2640 in the BLE interface, but it just can't connect. The code I use is as follows. Hope to come to a big man to point me out, I have been troubled by this problem for a long time.
require('ble') ble.up() sock =ble.sock() log(sock) ble.settimeout(sock, 10) res =ble.connect(sock,"78:04:73:BF:C4:E5",true) log(res) rbattery = ble.sockreadhnd(sock,0x47) or '' battery = rbattery:byte(2) rtime = ble.sockreadhnd(sock,45) or '' time = {hour=rtime:byte(5), minute=rtime:byte(6), second=rtime:byte(7)} log(rtime) log(time) log(rbattery) log(battery) rssi = ble.getrssi("78:04:73:BF:C4:E5") log(rssi) ble.close(sock)
03.04.2019, 12:39
Try connecting without using a random mac:
Code: res, err = ble.connect(sock,"78:04:73:BF:C4:E5")
03.04.2019, 12:46
(This post was last modified: 03.04.2019, 12:53 by 1114752670@qq.com.)
Log it out as follows
* arg: 1 * nil * arg: 2 * string: connect failed Thank you very much. My problem has been solved. But why does printing show that the connection failed。
03.04.2019, 12:59
Maybe you have too many connections open at once?
For more info you can also log error number: Code: res, err, errno = ble.connect(sock,"78:04:73:BF:C4:E5")
03.04.2019, 13:06
(This post was last modified: 03.04.2019, 13:07 by 1114752670@qq.com.)
I've learned that the first time I made a successful connection, and later when I reconnected, because the connection was successful, I would print out the connection failure.
* arg: 1 * bool: true * arg: 2 * nil * arg: 3 * nil Thank you very much. I didn't expect it was because of such a simple question.
09.04.2019, 12:39
(This post was last modified: 09.04.2019, 13:02 by 1114752670@qq.com.)
rbattery = ble.sockreadhnd(sock,0x47) or ''
I want to ask specifically how this function is implemented when extracting the data I want. For example (sock, 0x47) in why 0x47 must be this, what basis. I want to figure out a function x = ble. sockreadhnd (sock, 22) or'' about extracting data from Bluetooth.
09.04.2019, 14:19
0x47 is two byte attribute handle, which is specific to a device to which you are connecting
10.04.2019, 02:26
10.04.2019, 12:00
(09.04.2019, 12:39)1114752670@qq.com Wrote: rbattery = ble.sockreadhnd(sock,0x47) or '' How do I get the two byte attribute handle。For example, I use an BLE Scanner APP,How do I get what the two byte attribute handle I want in this App。
10.04.2019, 13:12
BLE Scanner does not provide handle numbers. You can use Linux with any USB BLE dongle: https://elinux.org/RPi_Bluetooth_LE
11.04.2019, 05:29
(10.04.2019, 13:12)admin Wrote: BLE Scanner does not provide handle numbers. You can use Linux with any USB BLE dongle: https://elinux.org/RPi_Bluetooth_LE Okay, thank you. But I found that if the handle pointed to a notification class of information, as if the data could not be obtained on the gateway, why did this happen? I can get all the other readable data. Is there any special statement about Bluetooth notification in LUA code?
11.04.2019, 06:11
Notification is bit different. First you need to send a subscribe message and then read from device using sockreadnotify. Have a look at ti-sensortag and mio-alpha profiles:
https://forum.logicmachine.net/showthread.php?tid=1199
18.04.2019, 07:54
(11.04.2019, 06:11)admin Wrote: Notification is bit different. First you need to send a subscribe message and then read from device using sockreadnotify. Have a look at ti-sensortag and mio-alpha profiles: require('ble') ble.up() sock =ble.sock() ble.settimeout(sock, 10) res=ble.connect(sock,"00:81:F9:21:B7:AE") err = ble.sockwritereq(sock,39,0x0001) x = ble.sockreadhnd(sock,39) or '' a = x:byte(1) b = x:byte(2) c = x:byte(3) d = x:byte(4) e = x:byte(5) f = x:byte(6) g = x:byte(7) h = x:byte(8) i = x:byte(9) j = x:byte(10) k = x:byte(11) m = x:byte(12) n = x:byte(13) k = x:byte(14) o = x:byte(15) p = x:byte(16) q = x:byte(17) log(sock,err,x,a,b,c,d,e,f,g,h,i,j,k,m,n,o,p,q) ble.close(sock) I now know that to enable notifications, I can get data, such as err = ble. sockwritereq (sock, 39,0x0001). But now there's a question, why do I write and read functions at the same time, print out all the data is nil. I still have data when I only have a read function.
18.04.2019, 09:53
You need to use sockreadnotify instead of sockreadhnd after you've enabled notifications.
28.04.2020, 19:37
(18.04.2019, 09:53)admin Wrote: You need to use sockreadnotify instead of sockreadhnd after you've enabled notifications.After a long time I came back to this problem. I failed to use ble to read the notification information. Can you provide me with a similar code for reference? I can't thank you enough!
30.04.2020, 04:21
As already mentioned, check ti-sensortag and mio-alpha profiles that use notifications: https://forum.logicmachine.net/showthread.php?tid=1199
|
« Next Oldest | Next Newest »
|