Package: bairy
bairyDisplay data from Raspberry Pi.Suppose you have a Raspberry Pi IoT-style device that measures and records data.bairyprovides a framework to share the data across a local network.bairyalso has the ability to combine, centralize, and display results from multiple devices.A screenshot of thebairyweb app.InstallThis 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 thenumpy-pandas-scipysuite.sudoaptupdate
sudoaptinstalllibatlas-base-devInstallbairywithpip3 install bairy. Ifpip3is not recognized, trypython3 -m pip install bairy.Try outbairywith random configurations.# initialize bairy with sensors providing random readingsbairy--set-random-configs# run the appbairyPoint your web browser tolocalhost:8000/status. Thesensor readings(a random walk) update every second. Refresh your browser to get the latest reading. Try otherendpointsas well.To stopbairy, go back to your terminal and press CTRL + C. Simply runbairyagain to continue recording and displaying.To remove stored data and configurations, runbairy --remove all. Runbairy --helpto see other command line options.DetailsConfigurationOnce your Raspberry Pi is equipped with sensors,bairymust be configured to be made aware of those sensors. Runbairy --configs-templateto create a file namedtemplate_configs.jsonwhich can be edited to include details about your sensors. After modifying the template, add the configurations tobairywithbairy --set-configs template_configs.json. Now runbairyto capture sensor readings.App endpointsWhenbairyis initialized, several distinct processes start. Through an asynchronous event loop,bairyreads the values of the sensors at specified time intervals and writes them to adata.csvfile. Concurrently,bairyserves aFastAPI-backed web app with which the user can interact. This web app can be accessed on the Raspberry Pi itself through at least one of127.0.0.1:8000or0.0.0.0:8000orlocalhost:8000.The app includes various endpoints, described below. To navigate to the endpoint/logs, point your browser tolocalhost: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. Seerun at startupto 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/statusendpoint 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 accessThe web app can be accessed on the LAN. Whenbairyis run in the command line, it will print its local IP address. This IP address might take the form192.168.0.17. To access thebairyweb app on a different machine on the network, navigate to192.168.0.17:8000/status. Here/statuscan be replaced with any of the endpoints above.Run at startupTo enablebairyto launch as the Raspberry Pi boots, follow the steps below. This is especially useful inheadlessmode, that is, when the Raspberry Pi is not attached to a monitor. See theofficial documentationfor more information on working withsystemdon Raspberry Pi.Runbairy --create-serviceto put abairy.servicefile in the/etc/systemd/systemdirectory.Runsudo systemctl start bairy.serviceto check if the service works.Runsudo 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 hubIf you have several Raspberry Pis simultaneously collecting and sharing data,bairyallows 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 withbairy. 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
selfRegister these IP addresses withbairy. If the file is namedip.txt, run the command below.bairyhub--set-configsip.txtNow runbairy 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.Runbairy hub --serviceto create a startup service to run the hub. This will override any previously created device service.More screenshots of thedashportion of thebairyapp.LicenseMIT License