Skip to main content

IoT Series: Sensors: Utilizing Breakout Garden Hat: Part 1 - Introduction

IoT Series: Sensors: Utilizing Breakout Garden Hat: Part 1 - Introduction
An easy option for adding, removing and prototype sensor reads from a standard Raspberry Pi with no special wiring.
Hardware Component List:
  • Raspberry Pi
  • USB Power Cable
  • Pimoroni Breakout Garden Hat
  • 1.12" Mono OLED Breakout 128x128 White/Black Screen
  • BME680 Air Quality, Temperature, Pressure, Humidity Sensor
  • LWM303D 6D0F Motion Sensor (X, Y, Z Axes)
  • BH1745 Luminance and Color Sensor
  • LTR-559 Light and Proximity Sensor 0.01 lux to 64,000 lux
  • VL53L1X Time of Flight (TOF) Sensor Pew Pew Lasers!
Software Component List:
  • Raspian
  • Python 2.7
  • JDK 8 Java
  • Apache NiFi
  • MiniFi
Source Code:
Our Raspberry Pi has a Breakout Garden Hat with 5 sensors and one small display. The display is showing the last reading and is constantly updating. For debugging purposes, it shows the IP Address so I can connect as needed.
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 TCP/IP over port 5005 to a listener. MiniFi 0.5.0 Java Agent is using ListenTCP 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.
The first thing we need to do is pretty easy. We need to plug in our Pimoroni Breakout Garden Hat and our 6 plugs.
You have to do the standard installation of Python, 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.
Install Python PIP curl -o
cd breakout-garden-master
sudo ./
Running In NiFi

First we build our MiniFi Flow:
We have two objectives: listen for TCP/IP JSON messages from our running Python sensor collector and gather images captured by the PS3 Eye USB Webcam.
We then add content type and schema information to the attributes. We also extract a few values from the JSON stream to use for alerting.
We extract: $.cputemp, $.VL53L1X_distance_in_mm, $.bme680_humidity, $.bme680_tempf
These attributes are now attached to our flowfile which is unchanged. We can now Route on them.
So we route on a few alarm conditions:
We can easily add more conditions or different set values. We can also populate these set values from an HTTP / file lookup.
If these values are met we send to our local Apache NiFi router. This can then do further analysis with the fuller NiFi processor set including TensorFlow, MXNet, Record processing and lookups.
Local NiFi Routing
For now we are just splitting up the images and JSON and sending to two different remote ports on our cloud NiFi cluster.
These then arrive in the cloud.
As you can see a list of the flow files waiting to be processed (I haven't written that part yet). As you can see we are getting a few a second, we could get 100,000 a second if we needed. Just add nodes. Instant scaling. Cloudbreak can do that for you.
In part 2, we will start processing these data streams and images. We will also add Apache MXNet and TensorFlow at various points on the edge, router and cloud using Python and built-in Deep Learning NiFi processors I have authored. We will also break apart these records and send each sensor to it's own Kafka topic to be processed with Kafka Streams, Druid, Hive and HBase.
As part of our loop we write to our little screen current values:

Example Record
  1. {
  2. "systemtime" : "12/19/2018 22:15:56",
  3. "BH1745_green" : "4.0",
  4. "ltr559_prox" : "0000",
  5. "end" : "1545275756.7",
  6. "uuid" : "20181220031556_e54721d6-6110-40a6-aa5c-72dbd8a8dcb2",
  7. "lsm303d_accelerometer" : "+00.06g : -01.01g : +00.04g",
  8. "imgnamep" : "images/bog_image_p_20181220031556_e54721d6-6110-40a6-aa5c-72dbd8a8dcb2.jpg",
  9. "cputemp" : 51.0,
  10. "BH1745_blue" : "9.0",
  11. "te" : "47.3427119255",
  12. "bme680_tempc" : "28.19",
  13. "imgname" : "images/bog_image_20181220031556_e54721d6-6110-40a6-aa5c-72dbd8a8dcb2.jpg",
  14. "bme680_tempf" : "82.74",
  15. "ltr559_lux" : "006.87",
  16. "memory" : 34.9,
  17. "VL53L1X_distance_in_mm" : 134,
  18. "bme680_humidity" : "23.938",
  19. "host" : "vid5",
  20. "diskusage" : "8732.7",
  21. "ipaddress" : "",
  22. "bme680_pressure" : "1017.31",
  23. "BH1745_clear" : "10.0",
  24. "BH1745_red" : "0.0",
  25. "lsm303d_magnetometer" : "+00.04 : +00.34 : -00.10",
  26. "starttime" : "12/19/2018 22:15:09"
  27. }
NiFi Templates
Let's Build Those Topics Now
  1. /usr/hdp/current/kafka-broker/bin/ --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic bme680
  2. /usr/hdp/current/kafka-broker/bin/ --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic bh17455
  3. /usr/hdp/current/kafka-broker/bin/ --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic lsm303d
  4. /usr/hdp/current/kafka-broker/bin/ --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic vl53l1x
  5. /usr/hdp/current/kafka-broker/bin/ --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic ltr559

Hopefully in your environment, you will be able to have 3, 5 or 7 replication factor and many partitions. I have one Kafka Broker so this is what we are starting with.


Popular posts from this blog

Ingesting Drone Data From DJII Ryze Tello Drones Part 1 - Setup and Practice

Ingesting Drone Data From DJII Ryze Tello Drones Part 1 - Setup and Practice In Part 1, we will setup our drone, our communication environment, capture the data and do initial analysis. We will eventually grab live video stream for object detection, real-time flight control and real-time data ingest of photos, videos and sensor readings. We will have Apache NiFi react to live situations facing the drone and have it issue flight commands via UDP. In this initial section, we will control the drone with Python which can be triggered by NiFi. Apache NiFi will ingest log data that is stored as CSV files on a NiFi node connected to the drone's WiFi. This will eventually move to a dedicated embedded device running MiniFi. This is a small personal drone with less than 13 minutes of flight time per battery. This is not a commercial drone, but gives you an idea of the what you can do with drones. Drone Live Communications for Sensor Readings and Drone Control You must connect t

Advanced XML Processing with Apache NiFi 1.9.1

Advanced XML Processing with Apache NiFi 1.9.1 With the latest version of Apache NiFi, you can now directly convert XML to JSON or Apache AVRO, CSV or any other format supported by RecordWriters.   This is a great advancement.  To make it even easier, you don't even need to know the schema before hand.   There is a built-in option to Infer Schema. The results of an RSS (XML) feed converted to JSON and displayed in a slack channel. Besides just RSS feeds, we can grab regular XML data including XML data that is wrapped in a Zip file (or even in a Zipfile in an email, SFTP server or Google Docs). Get the Hourly Weather Observation for the United States Decompress That Zip  Unpack That Zip into Files One ZIP becomes many XML files of data. An example XML record from a NOAA weather station. Converted to JSON Automagically Let's Read Those Records With A Query and Convert the results to JSON Records

Simple Change Data Capture (CDC) with SQL Selects via Apache NiFi (FLaNK)

 Simple Change Data Capture (CDC) with SQL Selects via Apache NiFi (FLaNK) Sometimes you need real CDC and you have access to transaction change logs and you use a tool like QLIK REPLICATE or GoldenGate to pump out records to Kafka and then Flink SQL or NiFi can read them and process them. Other times you need something easier for just some basic changes and inserts to some tables you are interested in receiving new data as events.   Apache NiFi can do this easily for you with QueryDatabaseTableRecord, you don't need to know anything but the database connection information, table name and what field may change.  NiFi will query, watch state and give you new records.   Nothing is hardcoded, parameterize those values and you have a generic Any RDBMS to Any Other Store data pipeline.   We are reading as records which means each FlowFile in NiFi can have thousands of records that we know all the fields, types and schema related information for.   This can be ones that NiFi infers the s