21.04.2020, 01:00
(This post was last modified: 21.04.2020, 01:31 by benanderson_475.)
(14.01.2020, 07:44)admin Wrote: Try this:I am having trouble receiving the correct data from lua code, when i use gatttool all works as below although i need to be fast to send the --char-read request before i get disconnected otherwise response is AA BB CC DD EE FF 99 88 77 66 00 00 00 00 00 00
Code:fertility = x:byte(9) * 0x100 + x:byte(10)
sunlight = x:byte(4) * 0x100 + x:byte(5)
temperature = (x:byte(1) * 0x100 + x:byte(2)) / 10
log(fertility, sunlight, temperature)
gatttool --device=80:EA:CA:89:1D:78 --char-write-req -a 0x33 -n A01F
gatttool --device=80:EA:CA:89:1D:78 --char-read -a 0x35
response is 03 01 00 4a 03 00 00 00 00 00 02 3c 00 fb 34 9b this is example of expected response
from my lua script, result in rx is always AA BB CC DD EE FF 99 88 77 66 00 00 00 00 00 00
i think im not sending the ble.sockreadhnd(sock, 0x35) command fast enough? or sending it before the ble.sockwritereq(sock, 0x33, cmd) has returned or maybe there is something else wrong?
The result from log(x, err) is *arg 1 number: 4 * arg: 2* number: 114 is there any documentation for these codes? or for the ble.sockwritereq() commands?
Many Thanks
Code:
require('ble')
sock = ble.sock()
ble.settimeout(sock, 10)
res = ble.connect(sock, "80:EA:CA:89:1D:78")
if res then
cmd = 0xA0, 0x1F
x, err = ble.sockwritereq(sock, 0x33, cmd)
log(x, err)
if x then
rx = ble.sockreadhnd(sock, 0x35)
rx = string.gsub(rx, ".", function(value) return string.format('%02X', string.byte(value))end)
log(rx)
end