forked from EtoTen/radonreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_script.sh
executable file
·63 lines (55 loc) · 1.23 KB
/
read_script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/expect -f
#
## remove output from STDOUT, except for puts
log_user 0
#
set timeout 4
# MAC address of RD200 device
set MAC_A "94:3c:c6:dd:42:ce"
# 1 for new RD200 device, 0 for old RD200 device
set DEVICE_TYPE 1
#command sent to get data
set COMMAND 50
##New device:
#send 0x002a -> notification receive on: 0x002c
if {$DEVICE_TYPE == "1"} {
set SEND_HANDLE 0x002a
set RECIEVE_HANDLE 0x002c
}
##Old device:
##send 0x000b -> notification receive on: 0x000d
if {$DEVICE_TYPE == "0" } {
set SEND_HANDLE 0x000b
set RECIEVE_HANDLE 0x000d
}
spawn gatttool -b $MAC_A -I
#
match_max 100000
#
expect "> "
#
while (1) {
send -- "connect\r"
expect "Connection successful" break
sleep 1
# puts "next attempt\n"
}
#
send -- "mtu 507\r"
expect "MTU was exchanged successfully" {
sleep 1
send -- "char-write-cmd $SEND_HANDLE $COMMAND\r"
set systemTime [clock seconds]
puts "Time [clock format $systemTime -format %Y-%m-%dT%H:%M:%S]"
set message1 ""
expect {
-re "Notification handle = $RECIEVE_HANDLE value: (.+\n)" {
set message1 ${message1}$expect_out(1,string)
exp_continue
}
}
puts "$message1"
}
send -- "exit\r"
#
expect eof