Building an InfluxDB IoT Edge Data Collection Device (Part 1)
Building an InfluxDB IoT Edge Data Collection Device (Part 1)
Want to learn how to build an InfluxDB IoT edge data collection device? Check out part one of this tutorial where we get started with the necessary hardware!
Join the DZone community and get the full member experience.Join For Free
Read why times series is the fastest growing database category.
I've been saying that I was going to write this whole project for some time now, but it has been such a daunting task that I've been putting it off, starting, stopping, and, generally, not getting it done for a few months. But, finally, I have it! This is both a hardware build and a software build, and there are a lot of moving parts, so be prepared!
I wanted to build a demonstration system that would show off the capabilities of using InfluxData — the entire TICK Stack-on the extreme edge of an IoT Architecture. While a lot of companies are betting on the cloud for IoT data collection, I understand that, for some, especially in the industrial IoT space, a cloud-first strategy is simply a non-starter. Furthermore, with a wide variety of network connectivity modalities — WiFi, BLE, LoRAWAN, etc. — being deployed, at some point, you simply have to have an edge device to connect to your end-sensors. In essence, I wanted to pull this architecture diagram together in real life.
So, I had to build a bunch of sensors and build an edge data collection box. Then, I had to hook it up to the Internet and have it back-haul data to the cloud. Let's start with the sensor builds.
As stated above, I wanted to incorporate as many sensors and communication protocols as I could in order to cover the widest possible deployment scenario. I ended up building a CO2 sensor connected over the BlueTooth Low Energy (BLE), temperature, humidity, pressure, visible light and an Infrared sensor connected over Wi-Fi and a radiation sensor connected over LoRAWAN and a contactless temperature sensor also connected over LoRaWan. That's a lot of sensors to build and a lot of RF protocols to incorporate.
The WiFi Sensor
Let's tackle this one first, shall we? Here are the parts list that you need to build this one:
I used I2C to hook them up, since it used the fewest pins, and I could share the pins. Here's the wiring diagram:
I wired them to my Particle Photon and wrote a little bit of software. We'll get to that in the Software Section, but it was fairly trivial to do given that Particle devices are programmed in an Arduino-like language and are fairly straightforward to handle.
Here, I 3-D printed a nice box for it and used super-thin, ceramic-coated wire to solder it all together. It came out in a nice package:
The sensor boards are hung from the insides and in front of the ventilation holes so that they can get accurate readings.
The BLE CO2 Sensor
This one was a bit more of a challenge for a few reasons. But first the parts list:
- Nordic nRF52DK developer Kit (I got mine from DigiKey)
- SenseAir K30 CO2 sensor
- 4700µF Capacitor (Adafruit to the rescue again!)
- 9v Boost Converter (I got mine from Pololu)
To make things a little less complicated, I wired the Boost to the nRF52 and, then, put the capacitor on the vout of the boost like this:
I'm not certain it made things easier per se, but this is how I did it. If you're an electrical engineer, you are probably laughing right now. Feel free to leave a comment and point out any errors.
I'll get into it more in the software sections, but this one was a bit of a beast to control. First off, DO NOT use this sensor wired directly to an Arduino! It absolutely will eat your voltage regulator. It requires 5v-12v and 500mA, and, according to the manufacturer, there isn't an Arduino out there with a regulator that can handle it. The nRF52DK board claims that they can, but I'm skeptical of that claim to some degree.
Again, I 3-D printed a nice box with vent holes in the top to allow for airflow.
I keep looking for a smaller BLE-based board to drive this thing — one that does not run Arduino. But, I've yet to find the right one.
The LoRa Radiation Sensor
This one was super fun to build. I grew up in Los Alamos, NM (The Atomic City!), so there's that. But, I had been invited to present at a workshop in Italy hosted by the United Nations International Atomic Energy Agency on "Radiation Monitoring over LoRaWAN," so I just had to build a radiation sensor! (It was really neat, and I blogged about it here).
Here's what I used:
- Pocket Geiger Radiation Sensor (from SparkFun Electronics)
- Wemos D1 Mini (I do not recommend the D1 Mini Pro as all the ones I bought had faulty Wi-Fi and were unusable, though I did not use the Wi-Fi for these parts)
- LoRa Radio Board (from Adafruit, of course)
- A White LED
You're probably asking yourself why I used a Wemos D1 (which has Wi-Fi) inside this thing that is using a LoRa radio. And, I'll tell you why — I couldn't find a cheaper board to control the LoRa Radio Board and the sensor board. At $3.00, it was just the right thing. I just turned the Wi-Fi off and went with it.
For the LED, I just used one I had lying around. I have no idea where it came from, but this one came out really nicely!
As you can see, it took a fair amount of work to get everything in the box, with all the wires, etc. But, it all managed to fit snugly.
The Contactless Temperature Sensor
Again, super simple. Here is what you need:
- Wemos D1 Mini (see above)
- LoRa Radio Board (see above)
- Melexis MLX90614 sensor (You can get one from Adafruit)
- A green LED
I'll admit that you can't get the same Melexis sensor that I used, but that's because — way back in the day, back in the Project Sun SPOT days — we built a little sensor board for the MLX90614 that made it easy to use over I2C. I happen to have a few of those lying around (from 2006!), so I used one. Again, I used the Wemos D1 Mini, with the Wi-Fi radio turned off, to control both the sensor and the LoRa Board simply because it was cheap (and I had a bunch of Wemos D1 Mini Pros lying around with Wi-Fi that didn't work anyway. Remember, don't buy those.)
It is the same thing with the Green LED — I just had one lying around.
Here's the temperature sensor board that you can't have:
And, here's the final package:
Again, getting all the wires in took some nifty soldering and packaging, but it all managed to fit in the end:
So, that concludes the sensor hardware. Now, on to the Edge Data Collection Node Hardware!
Building the Edge Collector
I admit that I could have used a Raspberry Pi. But, honestly, I'd backed the Pine-64 on Kickstarter, and I hadn't used the board for anything, so I decided to use it. Also, finding screens and cases for Raspberry Pis is easy — I guess. But, there are so many of them that it was hard to choose, and Pine64 has it all in one place.
Here's what I needed for the build:
Optional but Recommended
I actually used a 64GB MicroSD card in mine, but the location of the card slot is so awful that I ended up breaking one and having to replace it. If I had to build another one, I'd use the EMMC Module for sure.
I'm sure you're scratching your head and thinking: "why is there a Wemos D1 in this bit of kit?" And, I'll tell you! Again, it's just to control the LoRa board. Yes, I absolutely could have controlled it from the Pine64, but I already had all the working code to control the LoRa board from a Wemos. It's small and takes up very little space, so I just powered it off the 5v pin on the RPi header, and it was good to go. I wired its UART Tx pin to the RPi header's Rx pin and simply wrote any data coming in over the LoRa Radio to the Pine-64's incoming serial port, where I could then pick it up and store it.
I think it came out pretty nice!
Again, all the wires were a bit much. I had to drill an extra hole, in case, to mount the LoRa antenna but even the inside looked nice:
There's actually a ZWave module in there, too. But, this is only because it came with my Kickstarter Bundle. I'm not actually using it yet.
Now, how did I get that slick-looking dashboard of all my sensor data on there? Well, that's actually the easiest part of the software build.
Stay tuned for tomorrow's post where we take a closer look at the software!
Published at DZone with permission of David G. Simmons , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.