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)
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)