Powering Edge AI for Sensor Reading with RPI and Breakout Garden (EFM, NiFi, MiNiFi Agents)
Published: 2019-12-03 21:50:08

---
title: Powering Edge AI for Sensor Reading with RPI and Breakout Garden (EFM, NiFi, MiNiFi Agents)
published: true
date: 2019-09-10 16:25:00 UTC
tags: 
canonical_url: 
---

  

### Powering Edge AI for Sensor Reading with RPI and Breakout Garden (EFM, NiFi, MiNiFi Agents)

  

[![](https://1.bp.blogspot.com/-Alji2wnVRd8/XPVzUvoOYiI/AAAAAAAAXrE/bDG6qpomjMMd712iY2qBhKXfmKm6FS7PgCLcBGAs/s640/unnamed.jpg)](https://1.bp.blogspot.com/-Alji2wnVRd8/XPVzUvoOYiI/AAAAAAAAXrE/bDG6qpomjMMd712iY2qBhKXfmKm6FS7PgCLcBGAs/s1600/unnamed.jpg)
  
  

[![](https://1.bp.blogspot.com/-mUcRm__Di90/XXEqiRMFgsI/AAAAAAAAYVE/jtA9uRmXbHYTwrfOevxG_C-WAO-dgadkgCLcBGAs/s640/breakoutgarden2.png)](https://1.bp.blogspot.com/-mUcRm__Di90/XXEqiRMFgsI/AAAAAAAAYVE/jtA9uRmXbHYTwrfOevxG_C-WAO-dgadkgCLcBGAs/s1600/breakoutgarden2.png)
  

[![](https://1.bp.blogspot.com/-8qFhjqoFJIY/XXEqiOyUsJI/AAAAAAAAYVA/mkyYhaCDtv8sPSsFX0fUa-obpkCFpKOGACLcBGAs/s640/garden2bmp280max3010.png)](https://1.bp.blogspot.com/-8qFhjqoFJIY/XXEqiOyUsJI/AAAAAAAAYVA/mkyYhaCDtv8sPSsFX0fUa-obpkCFpKOGACLcBGAs/s1600/garden2bmp280max3010.png)
  
  
**Hardware Component List:**  
  

- Raspberry Pi 3B+
- BMP-280 Temperature, Pressure and Altitude
- ST7735 0.96 SPI Colour LCD 160x80
- MAX-30105 Oximeter and Smoke Sensor
- Sony Playstation 3 EYE USB Web Camera
  

### Software Component List:

- Raspian
- Python 3.5
- JDK 8 Java (Soon Upgrading to JDK 11)
- Apache NiFi 1.9.2
- MiniFi Java Agent 0.6.0
- Cloudera Edge Flow Manager
- Apache Kafka 2.2

### **Summary**

 ![96410-breakoutgardenarchitecture.jpg](https://xgkfq28377.i.lithium.com/t5/image/serverpage/image-id/7451iAE204037258B2FF4/image-size/medium?v=1.0&px=400)

  

Potential Use Cases:   Tracking Environment in a facility that includes webcam detection, temperature, pressure and smoke.

  

  

Our Raspberry Pi 3B+ has a Breakout Garden Hat with 2 sensors and one small display. The display is showing the capture image and is constantly updating. 

We currently run via nohup, but when we go into constant use I will switch to a Linux Service to run on startup.

The Python script initializes the connections to all of the sensors and then goes into an infinite loop of reading those values and building a JSON packet that we send via MQTT over port 1883 to a MQTT Mosquitto broker. MiniFi 0.6.0 Java Agent is using ConsumeMQTT on that port to capture these messages and filter them based on alarm values. If outside of the checked parameters we send them via S2S/HTTP(s) to an Apache NiFi server.

We also have a USB WebCam (Sony Playstation 3 EYE) that is capturing images and we read those with MiniFi and send them to NiFi as well.  We will incorporate TensorFlow lite models into our analysis.

The first thing we need to do is pretty easy. We need to plug in our Pimoroni Breakout Garden Hat and our 3 plugs.

You have to do the standard installation of Python 3, Java 8, MiniFi and I recommend OpenCV. Make sure you have everything plugged in securely and the correct direction before you power on the Raspberry Pi.

Download MiniFi Java Here: [https://nifi.apache.org/minifi/download.html](https://nifi.apache.org/minifi/download.html)

Install Python PIP 

curl [https://bootstrap.pypa.io/get-pip.py](https://bootstrap.pypa.io/get-pip.py) -o get-pip.py

Install Breakout Garden Library 

wget [https://github.com/pimoroni/breakout-garden/archive/master.zip](https://github.com/pimoroni/breakout-garden/archive/master.zip)

unzip master.zip

cd breakout-garden-master

sudo ./install.sh

### NiFi Flow

[![](https://1.bp.blogspot.com/-Y_ac30aIP7s/XXfKSJnWb8I/AAAAAAAAYXc/WejvV-sU2yUKlNRkDQY-WQArnAQGua0UQCLcBGAs/s640/garden2NiFiFlow.png)](https://1.bp.blogspot.com/-Y_ac30aIP7s/XXfKSJnWb8I/AAAAAAAAYXc/WejvV-sU2yUKlNRkDQY-WQArnAQGua0UQCLcBGAs/s1600/garden2NiFiFlow.png)

  

#### We Can Query IoT Events As They Stream In

  

[![](https://1.bp.blogspot.com/-oAA3jbR7GG8/XXfKTbo58uI/AAAAAAAAYXw/h2bQI5R7nCkeOicur0BGqAh9PjbR9QcRQCLcBGAs/s640/queryHightTemp.png)](https://1.bp.blogspot.com/-oAA3jbR7GG8/XXfKTbo58uI/AAAAAAAAYXw/h2bQI5R7nCkeOicur0BGqAh9PjbR9QcRQCLcBGAs/s1600/queryHightTemp.png)

  

#### Add ExecuteProcess to Run Our Shell/Python

[![](https://1.bp.blogspot.com/-0rBZD8RBj24/XXfKQB8vnFI/AAAAAAAAYWw/XY5Lvo6prow-R8MiWjFd6yUit-6FBDAEQCLcBGAs/s640/addExecuteProcess.png)](https://1.bp.blogspot.com/-0rBZD8RBj24/XXfKQB8vnFI/AAAAAAAAYWw/XY5Lvo6prow-R8MiWjFd6yUit-6FBDAEQCLcBGAs/s1600/addExecuteProcess.png)
  

  

  

#### IoT JSON Data
[![](https://1.bp.blogspot.com/-S6Yl7annJ44/XXfKSnw_KoI/AAAAAAAAYXg/mZ48ezxxLxkig0YyPL38bEQ8buwxY_4ywCLcBGAs/s640/garden2jsondata.png)](https://1.bp.blogspot.com/-S6Yl7annJ44/XXfKSnw_KoI/AAAAAAAAYXg/mZ48ezxxLxkig0YyPL38bEQ8buwxY_4ywCLcBGAs/s1600/garden2jsondata.png)  
  

#### IoT User

[![](https://1.bp.blogspot.com/-TeFj88UIVas/XXfKQ1fJRnI/AAAAAAAAYW8/YJPgJzXZzOcKgIbShXyqBpLkLmD3lA94QCLcBGAs/s640/cat.jpg)](https://1.bp.blogspot.com/-TeFj88UIVas/XXfKQ1fJRnI/AAAAAAAAYW8/YJPgJzXZzOcKgIbShXyqBpLkLmD3lA94QCLcBGAs/s1600/cat.jpg)
  
  

#### Cloudera Edge Management - Monitoring IoT Events From MiNiFi Agents on Devices

[![](https://1.bp.blogspot.com/-p2dZ3dkSYjc/XXfKQxn-reI/AAAAAAAAYXA/5MTT9Z-WLtUbUaXBYUj66WasKTA7w_RsgCLcBGAs/s640/cemEventsLog.png)](https://1.bp.blogspot.com/-p2dZ3dkSYjc/XXfKQxn-reI/AAAAAAAAYXA/5MTT9Z-WLtUbUaXBYUj66WasKTA7w_RsgCLcBGAs/s1600/cemEventsLog.png)

  

#### Building an IoT Flow Graphically Is Easy!   It follows the [Hadoop Philosophy](https://medium.com/@acmurthy/hadoop-is-dead-long-live-hadoop-f22069b264ac) to stitch these things together.  
  

[![](https://1.bp.blogspot.com/-umG5dbQf4g0/XXfKRPii8-I/AAAAAAAAYXE/-XhpB8W7TYwLqs_cR_4GOjxrU0wQehOXgCLcBGAs/s640/cemGarden2.png)](https://1.bp.blogspot.com/-umG5dbQf4g0/XXfKRPii8-I/AAAAAAAAYXE/-XhpB8W7TYwLqs_cR_4GOjxrU0wQehOXgCLcBGAs/s1600/cemGarden2.png)

####   
Configure Connection to MQTT Broker
  

[![](https://1.bp.blogspot.com/-y_UWdGdx19E/XXfKRvG-RvI/AAAAAAAAYXQ/X58Qustq6kYNOVVnKzknuQLD-zDcs493wCLcBGAs/s640/consumeMQTT.png)](https://1.bp.blogspot.com/-y_UWdGdx19E/XXfKRvG-RvI/AAAAAAAAYXQ/X58Qustq6kYNOVVnKzknuQLD-zDcs493wCLcBGAs/s1600/consumeMQTT.png)

  

#### MQTT Configuration 2
  

[![](https://1.bp.blogspot.com/-YzbPTRhP7v4/XXfKRzQHXFI/AAAAAAAAYXU/u8OQln5QlAIl1-K-ngHLTxlxaJLg6UyyQCLcBGAs/s640/consumemqttsettings2.png)](https://1.bp.blogspot.com/-YzbPTRhP7v4/XXfKRzQHXFI/AAAAAAAAYXU/u8OQln5QlAIl1-K-ngHLTxlxaJLg6UyyQCLcBGAs/s1600/consumemqttsettings2.png)

  

  

**Cloudera Edge Flow Manager REST API**
  

[![](https://1.bp.blogspot.com/-rUedK4S84hA/XXfKSKeuc7I/AAAAAAAAYXY/PUHRxblRpkALRoTTQgxvkpusmKCT7O_kQCLcBGAs/s640/efmSwagger.png)](https://1.bp.blogspot.com/-rUedK4S84hA/XXfKSKeuc7I/AAAAAAAAYXY/PUHRxblRpkALRoTTQgxvkpusmKCT7O_kQCLcBGAs/s1600/efmSwagger.png)
  

  

  

####   
 Let's Examine those MQTT Messages from Devices

[![](https://1.bp.blogspot.com/-Wpupc3pTCoU/XXfKS_pX1aI/AAAAAAAAYXk/BGnVEOrxvvE5nMAuNkh4TvSzkrKyOfl-QCLcBGAs/s640/mqttExploration.png)](https://1.bp.blogspot.com/-Wpupc3pTCoU/XXfKS_pX1aI/AAAAAAAAYXk/BGnVEOrxvvE5nMAuNkh4TvSzkrKyOfl-QCLcBGAs/s1600/mqttExploration.png)
  

  

  

  

  

  

  

  

As you see we follow the Hadoop Philosophy of keeping things open, extensible, modular, flexible, transparent, composable, using open data standards, open source, diverse and cloud friendly.  In this way we can always bend to the needs of the user and adapt to any environment, any data, any cloud at any time.   If we need to windowing we could easily add Storm or Flink.   For other streaming use cases we can connect our Kafka topics to Spark Structured Streaming or Kafka Streams for additional processing as needed.    We can public our public schemas from our schema registry as open data standards within our enterprise, our ecosystem or world wide.   Data is meant for sharing and utilizing to build knowledge.   Let's make it happen, from any Edge to any data store to any data cloud to any AI / ML / DS / DL model.

  

**Source:**  
[https://github.com/tspannhw/breakoutgardenhat-spi-minifi](https://github.com/tspannhw/breakoutgardenhat-spi-minifi)  
  
**Resources** :  
  

**Breakout Garden Hat**

[https://github.com/pimoroni/bmp280-python](https://github.com/pimoroni/bmp280-python)

[https://github.com/pimoroni/breakout-garden](https://github.com/pimoroni/breakout-garden)  
[https://shop.pimoroni.com/products/bmp280-breakout-temperature-pressure-altitude-sensor](https://shop.pimoroni.com/products/bmp280-breakout-temperature-pressure-altitude-sensor)

[https://shop.pimoroni.com/products/breakout-garden-hat](https://shop.pimoroni.com/products/breakout-garden-hat)

[https://shop.pimoroni.com/products/breakout-garden-hat-i2c-spi](https://shop.pimoroni.com/products/breakout-garden-hat-i2c-spi)
[https://github.com/pimoroni/breakout-garden/tree/master/examples/heartbeat](https://github.com/pimoroni/breakout-garden/tree/master/examples/heartbeat)  

[https://shop.pimoroni.com/products/0-96-spi-colour-lcd-160x80-breakout](https://shop.pimoroni.com/products/0-96-spi-colour-lcd-160x80-breakout)  
[https://datasheets.maximintegrated.com/en/ds/MAX30105.pdf](https://datasheets.maximintegrated.com/en/ds/MAX30105.pdf)  
[https://shop.pimoroni.com/products/max30105-breakout-heart-rate-oximeter-smoke-sensor](https://shop.pimoroni.com/products/max30105-breakout-heart-rate-oximeter-smoke-sensor)  
[https://github.com/pimoroni/max30105-python](https://github.com/pimoroni/max30105-python)  
[https://github.com/tspannhw/minifi-breakoutgarden](https://github.com/tspannhw/minifi-breakoutgarden)  
[https://shop.pimoroni.com/products/0-96-spi-colour-lcd-160x80-breakout](https://shop.pimoroni.com/products/0-96-spi-colour-lcd-160x80-breakout)  
curl https://get.pimoroni.com/st7735 | bash  
[https://github.com/pimoroni/st7735-python](https://github.com/pimoroni/st7735-python)  
  
Using a Different Configuration of Breakout Garden Sensors  
[https://community.cloudera.com/t5/Community-Articles/IoT-Series-Sensors-Utilizing-Breakout-Garden-Hat-Part-1/ta-p/249262](https://community.cloudera.com/t5/Community-Articles/IoT-Series-Sensors-Utilizing-Breakout-Garden-Hat-Part-1/ta-p/249262)  
  
  
**TensorFlow**  
[https://github.com/tensorflow/examples/blob/master/lite/examples/image\_classification/raspberry\_pi/README.md](https://github.com/tensorflow/examples/blob/master/lite/examples/image_classification/raspberry_pi/README.md)  
[https://www.tensorflow.org/lite/guide/python](https://www.tensorflow.org/lite/guide/python)  
[https://github.com/PINTO0309/Bazel\_bin](https://github.com/PINTO0309/Bazel_bin)  
https://github.com/PINTO0309/Tensorflow-bin  
  
sudo apt-get install libatlas-base-dev   
wget https://dl.google.com/coral/python/tflite\_runtime-1.14.0-cp35-cp35m-linux\_armv7l.whl  
pip3 install tflite\_runtime-1.14.0-cp35-cp35m-linux\_armv7l.whl