So, I'm getting started on bringing in radon data from an Ecosense RD200.
My current plan is to get a-hold of a Raspberry Pi Zero 2 W (when they're finally in stock), and pull the data with gatttool, maybe a few times a day, then transfer that data to Hubitat and plot with Hubigraphs. I might need to use something like pygatt instead, since expect might have a problem when it starts responding with more data (up to about 29000 characters maybe).
So far, I have an expect script I can run from a Linux PC, which returns the data I'm interested in receiving via gatttool:
#!/usr/bin/expect -f
log_user 0
## That removes the output from STDOUT, except for puts
set device "94:3C:C6:DE:31:7A"
spawn gatttool -b $device -I
expect "> "
sleep 1
send -- "connect\r"
expect "Connection successful"
sleep 1
send -- "mtu 507\r"
expect "MTU was exchanged successfully"
sleep 1
#match_max 10000
## Might need to increase match to receive all the response once it stores more data. Maybe this won't work once a year of data is stored.
send -- "char-write-cmd 0x002a 41\r"
set message1 ""
expect {
-re "Notification handle = 0x002f value: (.+\n)" {
set message1 ${message1}$expect_out(1,string)
exp_continue
}
"^\[.+\]\[LE\]> $" {
send -- "disconnect\r"
}
}
puts "$message1"
So here's what I get:
$ ./test-gatttool.sh
41 02 01 fa 19 00 30 00 30 00 26 00 2e 00 2e 00 2d 00 23 00 20 00 1d 00 2a 00 17 00 17 00 12 00 1d 00 1d 00 2b 00 34 00 2e 00 37 00 27 00 21 00 30 00 37 00 3a 00 2d 00 2b 00 1a 00 30 00 16 00 10 00 13 00 12 00 0f 00 17 00 16 00 24 00 19 00 16 00 26 00 1c 00 20 00 34 00 3f 00 26 00 35 00 3f 00 30 00 31 00 38 00 3f 00 44 00 38 00 26 00 19 00 24 00 2a 00 2e 00 21 00 20 00 1c 00 24 00 1c 00 26 00 38 00 2e 00 48 00 34 00 35 00 37 00 38 00 44 00 44 00 31 00 41 00 44 00 3b 00 27 00 2b 00 27 00 1d 00 17 00 2d 00 2b 00 27 00 26 00 2e 00 3b 00 44 00 44 00 3e 00 45 00 4e 00 37 00 34 00 44 00 2e 00 24 00 30 00 24 00 2b 00 2d 00 2a 00 30 00 1c 00 30 00 23 00 23 00 1c 00 23 00 31 00 20 00 3a 00 3e 00 3f 00 38 00 45 00 55 00 45 00 3a 00 42 00 2a 00 37 00 42 00
41 02 02 42 26 00 26 00 10 00 1a 00 13 00 20 00 2b 00 31 00 3e 00 34 00 19 00 35 00 35 00 2e 00 30 00 37 00 24 00 2a 00 30 00 21 00 26 00 23 00 1c 00 19 00 1d 00 17 00 21 00 20 00 1d 00 2a 00 3b 00 24 00 20 00 26 00 24 00 30 00 2e 00 26 00 38 00 30 00 31 00 2a 00 2d 00 2b 00 2b 00 2b 00 26 00 2a 00 1d 00 24 00 1a 00 23 00 2e 00 30 00 45 00 41 00 2e 00 2b 00 34 00 38 00 3e 00 45 00 2d 00 42 00 35 00 2d 00
The first line is the first set of 250 Radon measurements as 2-byte int (in Bq/m^3), following x41 x02 x01 xFA.
The first four bytes will be (I think): x41; x??; x01-x24; and x01-xFA. The first byte returns the value of the request (send -- "char-write-cmd 0x002a 41\r"
). I don't know about the second, the third byte is the number of the measured data response, starting from x01 (oldest) to newest, then the fourth byte contains the number of measurements in that response.
The second line contains up to an additional 250 measurements. In this case, it contains x42
(66) measurements. Every time x41
is sent to 0x002a
I will get up to a year of measurements in responses of up to 250 (one per hour saved for up to a year).
I know @iharyadi has done some bluetooth integration, but I'm wondering what things I'll need to watch for. Has anyone else used a Raspberry Pi for integrating bluetooth? I'm also considering using an old Android phone instead of a Raspberry Pi, but I don't know if I can manage that without root.
I'm really hoping to find some code for requesting data from a Pi doing something like this a few times a day that I can hack, since I'm not an actual developer.
Thanks for any help/pointers!