You will need a dongle/adapter that supports at least Bluetooth 4.0 or higher and host stack that supports BLE features.
- Install BLE stack and bluepy:
sudo apt-get update
sudo apt-get install libgtk2.0-dev libglib2.0-dev build-essential bluez
sudo pip2 install bluepy
sudo pip2 install requests
- Make sure that
bluetoothd
is running with--experimental
. On systemd (sigh), try this:
sudo sed -i 's#/bluetoothd$#/bluetoothd --experimental#' /lib/systemd/system/bluetooth.service
sudo systemctl daemon-reload
sudo systemctl restart bluetooth
- Pair device:
- Open bluetoothctl:
sudo bluetoothctl
- Enable passcode support:
agent KeyboardOnly
- Enable adapter:
power on
- Scan devices:
scan on
- When found your device, stop scan:
scan off
- Pair device:
pair <DEVICE_ADDRESS>
- Disconnect if automatically connected:
disconnect <DEVICE_ADDRESS>
- Exit from bluetooth ctl:
exit
- Open bluetoothctl:
Run script: python aranet.py <DEVCE_ADDRESS> [OPTIONS]
Options:
-n Print current info only
-o <file> Save history to file
-l <count> Get <count> last records
-u <url> Remote url for current value push
You can use this in your own project by adding aranet4 folder to your project and in main code just import it:
import aranet4
device_mac = "00:00:00:00:00:00"
ar4 = aranet4.Aranet4(device_mac)
current = ar4.currentReadings()
print "Temperature:", current["temperature"]
print "Humidity:", current["humidity"]
print "Pressure:", current["pressure"]
print "CO2:", current["co2"]
Input: python aranet.py AA:BB:CC:DD:EE:FF -n
Output:
--------------------------------------
Connected: Aranet4 00000 | v0.3.1
Updated 51 s ago. Intervals: 60 s
5040 total readings
--------------------------------------
CO2: 904 ppm
Temperature: 19.9 C
Humidity: 51 %
Pressure: 997.0 hPa
Battery: 96 %
--------------------------------------
History file format: Id;Date;Temperature;Humidity;Pressure;CO2
History file example:
0;2019-09-09 15:11;25.00;43;1015.2;504
1;2019-09-09 15:12;25.00;43;1015.2;504
...