Display data from Raspberry Pi.
Project description
bairy
Display data from Raspberry Pi.
Suppose you have a Raspberry Pi IoT-style device that measures and records data. bairy provides a framework to share the data across a local network. bairy also has the ability to combine, centralize, and display results from multiple devices.
A screenshot of the bairy web app. |
Install
This package requires at least Python 3.7. The following instructions work for Raspbian 10 running on a Raspberry Pi 3 B+.
-
Install the dependencies for the
numpy-pandas-scipysuite.sudo apt update sudo apt install libatlas-base-dev
-
Install
bairywithpip3 install bairy. Ifpip3is not recognized, trypython3 -m pip install bairy. -
Try out
bairywith random configurations.# initialize bairy with sensors providing random readings bairy --set-random-configs # run the app bairy
-
Point your web browser to
localhost:8000/status. The sensor readings (a random walk) update every second. Refresh your browser to get the latest reading. Try other endpoints as well. -
To stop
bairy, go back to your terminal and press CTRL + C. Simply runbairyagain to continue recording and displaying. -
To remove stored data and configurations, run
bairy --remove all. Runbairy --helpto see other command line options.
Details
Configuration
Once your Raspberry Pi is equipped with sensors, bairy must be configured to be made aware of those sensors. Run bairy --configs-template to create a file named template_configs.json which can be edited to include details about your sensors. After modifying the template, add the configurations to bairy with bairy --set-configs template_configs.json. Now run bairy to capture sensor readings.
App endpoints
When bairy is initialized, several distinct processes start. Through an asynchronous event loop, bairy reads the values of the sensors at specified time intervals and writes them to a data.csv file. Concurrently, bairy serves a FastAPI-backed web app with which the user can interact. This web app can be accessed on the Raspberry Pi itself through at least one of 127.0.0.1:8000 or 0.0.0.0:8000 or localhost:8000.
The app includes various endpoints, described below. To navigate to the endpoint /logs, point your browser to localhost:8000/logs.
/docsShows endpoint schemas and API documentation./dataReturns a streaming response of thedata.csvfile. Optionalselectionargument can be used to access preprocessed data./logsReturns thebairylogs as plaintext./statusDisplays a json object showing active configurations and device status. See the json example below./remote/updateUpdate thebairysoftware withpip. Requires the Raspberry Pi does not prompt forsudopassword, which is the default setting./remote/rebootReboot the Raspberry Pi. See run at startup to ensurebairyrestarts./remote/remove-dataRemove device data from Raspberry Pi./remove/remove-logsClear log file on Raspberry Pi./set-configsAn HTTP POST endpoint for setting device configurations./tableRenders a Dash table showing resampled data. The resampling window depends the overall size of thedata.csvfile. Raw data should be obtained through the/dataendpoint./plotRenders an interactive Dash plot showing resampled data.
As an example, the json response of a /status endpoint appears below.
{
"device_configs": {
"name": "eye of sauron",
"sensors": [
{
"sensor_type": "air",
"i2c_address": 18
},
{
"sensor_type": "digital",
"bcm_pin": 17,
"header": "ir_state"
}
],
"update_interval": 1
},
"data_details": {
"file_size": "1.44 MiB",
"n_rows": 33994
},
"latest_reading": {
"time": "2021-01-17 21:46:40",
"pm_1.0": 3,
"pm_2.5": 5,
"pm_10": 5,
"ir_state": 1
}
}
LAN access
The web app can be accessed on the LAN. When bairy is run in the command line, it will print its local IP address. This IP address might take the form 192.168.0.17. To access the bairy web app on a different machine on the network, navigate to 192.168.0.17:8000/status. Here /status can be replaced with any of the endpoints above.
Run at startup
To enable bairy to launch as the Raspberry Pi boots, follow the steps below. This is especially useful in headless mode, that is, when the Raspberry Pi is not attached to a monitor. See the official documentation for more information on working with systemd on Raspberry Pi.
-
Run
bairy --create-serviceto put abairy.servicefile in the/etc/systemd/systemdirectory. -
Run
sudo systemctl start bairy.serviceto check if the service works. -
Run
sudo systemctl stop bairy.serviceto stop the service. When you restart the Raspberry Pi,bairyshould automatically start in the background. You can runps -aux | grep bairyto verifybairyis working.
A central hub
If you have several Raspberry Pis simultaneously collecting and sharing data, bairy allows you to merge and share the data through a common web app. This central hub can be run on one of the Raspberry Pis, or on an independent device that is not capturing sensor data.
-
You will need to the know the IP addresses of the Raspberry Pi devices which are capturing data with
bairy. Create a simple text file with these IP addresses. If the hub host is also acting as a sensing device, include the wordselfin this file.192.168.0.17 192.168.0.34 self
-
Register these IP addresses with
bairy. If the file is namedip.txt, run the command below.bairy hub --set-configs ip.txt
-
Now run
bairy hubto launch the hub web app. Data is periodically requested from devices (every hour), then merged into a singleplotlyplot. Point your browser tolocalhost:8000to view the app. Use the/docsendpoint to view other available endpoints. -
Run
bairy hub --serviceto create a startup service to run the hub. This will override any previously created device service.
More screenshots of the dash portion of the bairy app. |
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bairy-0.1.8.tar.gz.
File metadata
- Download URL: bairy-0.1.8.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3212109120be72dc3dce1a0dfe50b709c5e0abbdd9bd9dbb63ce2cc2bfb030b5
|
|
| MD5 |
fbceeaf9ce669150ce673dd1c355a01b
|
|
| BLAKE2b-256 |
b54e6382011ffe0bd05a5f2202457493ef7860af753f1845a6286ef58ac3ffb5
|
File details
Details for the file bairy-0.1.8-py3-none-any.whl.
File metadata
- Download URL: bairy-0.1.8-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2671b60cf102bc909d3646ed4f111c98fa5ccceb253d6acf49e56ab6680cd3a7
|
|
| MD5 |
f0acb04627ccf8e5a3c68f7c1011c64e
|
|
| BLAKE2b-256 |
e18735e582644be0c047b6267b83514677087ea0411f730c1c350507b8bde126
|