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:
https://forum.logicmachine.net/showthread.php?tid=1199
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.