Community Articles

Find and share helpful community-sourced technical articles.
Labels (2)
avatar
Master Guru

16718-rainbowhat3.png

16719-rainbowhat1-copy.png

16720-rainbowhat1.png

This is a cool HAT that attaches without soldering to a Raspberry Pi 3. The main use is with Google's Android Things which is an IoT OS based on Android that you can run on Raspberry Pi and other devices.

You can also use this HAT with regular Raspian and Python.

This HAT is cool because it has input and output. As part of our Python script, we ingest data from it's sensor, but we also allow for input to it's A, B and C buttons clearly marked on the top. By selecting one of the buttons you can display the current temperature in Celsius, Fahrenheit or the current altitude. The altitude is some code I found commented out in the Pimoroni Rainbow HAT interface Python script. It determines altitude based on a starting value and pressure readings. Looks kind of cool and is relatively accurate. For point of reference, Princeton New Jersey is pretty close to sea level.

My script is heavily copied and customized from my previous IoT Python scripts and from the RainbowHAT examples.

This hat has 4 digit display, seven multiple color LEDs, BMP280 temperature and pressure sensor and some more goodies in this tiny device. It's available from AdaFruit.

We execute the Python code via a simple shell script wrapper:

python /opt/demo/minifi.py

Source Code:

https://github.com/tspannhw/rpi-rainbowhat

Prepare the Pi

sudo apt-get purge libreoffice wolfram-engine sonic-pi scratch sudo apt-get autoremove

Example Python Debug Output

CPU: 45.0 C
Corrected Temp: 23.7 C
Room Temp: 74.7 F
Pressure:    101598.9 Pa
Altitude:  33.2

16750-rainbowreadminififlow.png

This is the MiniFi flow that I modeled in Apache NiFi, then export as XML. Then use the below shell script to convert into config.yml format to transfer to my device running Apache MiniFi Java agent.

16751-minifirainbowingest.png

This is a simple flow to add a schema name, tell NiFi it's a JSON stream and then query it. If the data has temperatures above a threshold (checked via inline SQL) write the AVRO file to ORC and store in HDFS (automagically building an external Hive table on top of it).

Schema to put in Hortonworks Schema Registry or NiFi AVRO Schema Registry

{"type":"record","namespace":"hortonworks.hdp.refapp.rainbow","name":"rainbow","fields":[{"name": "tempf", "type": "float"},{ "name": "cputemp", "type": "float"},{"name":"ts","type":"string"},{ "name": "pressure","type": "float"},{ "name": "host","type": "string"},{ "name": "tempf2","type": "float"},{"name": "ipaddress","type": "string"},{"name": "temp","type": "float"},{ "name": "altitude","type": "float"}]} 

It's pretty easy to define an AVRO schema (in JSON format), like above). Feel free to use the above as a starting point. Strings and floats work very well, keep it simple and leave out extra whitespace.

Build Your Configuration

minifi-toolkit-1.0.3.0.0.0-453/bin/config.sh transform RainbowForMiniFi.xml config.yml

nifireceiverrainbow.xml

rainbowforminifi.xml

Coming Soon

Raspberry Pi 3 running Android Things and Java Connecting to Rainbow Hat, TensorFlow and MiniFi.

References:

Part of My IoT MiniFi Series (Details Installation and Setup)

1,543 Views