The idea is to use an environmental sensor with BBGW, and deploy an application onto the board with resin.io to signal changes in the environment by using LED blinks.
I've used a Grove BMP180 Pressure Sensor, which also measures temperature. A red and a blue LED signals increasing and decreasing sensor value (e.g. red for increasing temperature - getting hotter, blue for decreasing temperature - getting colder). When the sensor reading is approximately stable blink both LEDs; when it changes blink the corresponding color; when it changes quickly, then do long blinks.
The whole system can be monitored and controlled remotely over the Internet. Resin.io packages software as Docker images, accepts them over git, and takes care of pushing them out to devices whenever there's an update. Devices and fleets (group of many devices) can easily be added on the web or over the command line. All this makes a quite quick hardware/software project development & management environment.
Let's get started with this project!
Sign up for resin.io, add your SSH key, and install git on your computer. See the details in the Beaglebone getting started guide in the documentation.
Once the basic setup is done, create a new app in the dashboard, and select Beaglebone Green Wireless as the device type.
A new application is created and the dashboard shows no devices associated yet with it.
To provision a device, you have to download the device OS first, that will host your application code and and the supervisor system to manage everything.
When downloading the device OS, choose Wifi connection as it is natural with Beaglebone Green Wireless, and add your Wifi network information.
The device OS is quite large, but on modern browsers it downloads quickly, as it is sent compressed from the server.
Once the image is downloaded, it has to be burned onto a Micro-SD card.
Get Etcher, the cross-platform image burning tool from http://www.etcher.io/ and install it on your computer. Start it, select the image, plug in a Micro-SD card into your computer, and then burn. The image will be prepared and verified.
Remove the Micro-SD card, and plug it into the BBGW, but don't power up the board yet! The BBGW uses the internal storage to run usually, and the SD card is used to flash a new OS onto the internal storage.
To do that:
Something like this:
After the blue LEDs start to blink and the switch is released, the device soon should show up in the online dashboard (if the Wifi settings were correct).
Now you can click on the device's name (e.g."spring-forest"above, you can change the name easily in the interface), to see the details of the device, currently flashing onto the internal storage of the BBGW.
Once the flashing is done, the device will turn off.
Remove the SD card, and power on the board again. The device will go into post-provisioning mode, and will be ready to accept code to run.
Now plug in the hardware used for this project:
In the end, looking like this:
Of course, if you have some nicer housing, you can use that too, or some kind of mounting for the LEDs to make it look better. This is a development setup, so things just hang out :)
The code is deployed to the device with resin.io as a Docker image. I wrote the application as a Python script that talks to the pressure sensor and blinks the LEDs as appropriate.
The whole code is available on Github at resin-io-playground/bbgw-environment-leds!
A couple of notes on the code:
Interacting with the pressure sensor was done using another library, Adafruit_Python_BMP that simplifies a lot of I2C communication and data conversion.
To use the digital I/O pins, have to reference them properly in the code. Using the table below, the red LED on GPIO 51 is accessed through the label"P9_16", while the blue LED on GPIO 50 is accessed at"P9_14". Using this table you can reference all the other available GPIO pins as well.
The pins need to be set up in"output"mode, and outputting"low"value means no light,"high"value means light.
The measured data is post-processed a bit to reduce measurement noise. Double exponential smoothing / Holt-Winters algorithm is applied to get an approximate/smoothed trend variable, and being able to tell if the sensor values are increasing or decreasing. The math of that is pretty simple, and can be done with storing just the previous level/trend estimates of the data, and updating it with the new reading.
The code also includes a couple of (software) environmental variables, that can be used to change the behaviour, e.g. monitor pressure instead of temperature, change the update frequency from 1/second, and set the threshold of what rate of change in sensor reading is"large"and should be signalled with the LEDs differently. These environmental variables can be set in the resin.io dashboard of the application or device.
The application code is then pushed to the resin.io server with git. The upstream repository address to push to is shown in the upper right corner in the application view of the dashboard.
When the code is pushed the server takes the instructions from the included Dockerfile and creates the software package to send to the device.
When the image preparation is finished, there should be a unicorn for awesomeness!
After this, the device should start downloading the application, and show that status in the dashboard too:
After the download, the right side of the view shows the logs from the device, so if anything goes wrong with the code pushed, that log window is the first place to start to debug. In this case the code should already work well, so the debug output should show up, listing the sensor reading and the smoothed level & trend variables.
If the code push from the last step worked and the hardware is setup correctly, then the device should be monitoring the environment already, watch out for blinking LEDs!
To test the device, I used the simple trick of turning on the air conditioner in my room, to bring down the current 31-32°C to a more manageable temperature. Before turning the air conditioner on, most of the time the two LEDs blinked together signalling stable temperature. As soon as the cooling kicked in, it was nice blue blinking that reassured my own own feeling of cooler environment too.
The same setup could also be used to monitor atmospheric pressure with this hardware. Pressure is a bit harder to manipulate, though. My test case would be watching a typhoon and its low pressure center pass over my location, but that's not that easy to arrange. :) In the meantime, air conditioning is good for this project.
Even though this project used a specific set of hardware, it should be a good base to create any other Python application on top of BBGW and resin.io, as the hardware control libraries are the same (and work). Anyone then can just clone this project on Github, check the BBGW/Python getting started guide, modify the Dockerfile and the Python code, and build projects!
Resin.io also supports a bunch of other boards if you don't have BBGW, but so far this board works very well for me, the wireless connectivity and ease of adding hardware pieces with Grove is really useful. Unfortunately it looks like that right now resin.io does not work from within China, but hopefully it can be fixed in the future for makers there!
Happy hacking! And keep an eye on those temperature changes!