This is an old revision of the document!
Table of Contents
Introduction to IoT - Sensors and Data processing
The first steps into the topic of IoT can be very confusing or even overwhelming. In this article, I want to walk you through an example, where you can see how to gather data, which hardware and software you can use, and how it all connects together in the end. You won't need any programming knowledge whatsoever. But I expect you have some idea what a microcontroller is and maybe have programmed something simple like an Arduino Uno with a blink example. Just so you have a general idea of a microcontroller.
Intro
What is IoT?
IoT, the Internet of Things is a very big topic. So we are going to break a bit down. Even the IEEE has to confess that “looking for a comprehensive definition of Internet of Things is not easy” (IEEE Internet Initiative, 2015). But that doesn't mean it can't be done. The IEEE list 9 features that make up the Internet of Things:
- Interconnection of Things
- Connection of Things to the Internet
- Uniquely Identifiable Things
- Ubiquity
- Sensing/Actuation capability
- Embedded intelligence
- Interoperable Communication Capability
- Self-configurability
- Programmability
If you want to know in detail what all these mean precisely please read the paper I linked below by the IEEE Internet Initiative (May 2015) chapter 5.3 Features and Definition of Internet of Things.
The most important things for us are the Interconnection of Things, the Connection of Things to the Internet, Uniquely Identifiable Things, and the Sensing capability. We will get to all these topics today.
What you will need
You will need some stuff to get started with this little project. If you are a student of Prof. Becker you will get all this stuff from him. If you have just stumbled across this article you, unfortunately, have to set up and buy everything yourself. So what you will need:
- Your NIG (a running and configured instance of Node-Red, InfluxDB, and Grafana)
- A Breadboard with some Jumper wires
- An ESP8266 (here: adafruit HUZZAH)
- An FTDI Programmer (only if your board doesn't come with a USB to serial converter ( eg doesn't have USB-Connector
))
- A USB cable for the programmer (or the ESP8266 directly)
- A DS18B20 (Digital temperature sensor)
- A 4.7k resistor
- A PC with the Arduino IDE and ESP8266-boards installed
NIG
Node-Red, InfluxDB, and Grafana is commonly used tech-stack. To learn more about it, please read this article and follow the instructions to set things up like described: First steps with your NIG
Breadboard
A Breadboard can be used for prototyping. It allows connecting cables by just plugging them into the holes, as you can see in the picture. Many devices like microcontrollers or sensors have a pin spacing that allows them to be plugged directly into the board as well. So you can prototype circuits and test around.
If you want (or need) to learn more you can watch this video:
ESP8266
The ESP8266 is a cheap microcontroller that comes on many different carrier boards. On the HUZZAH board, they are easy to differentiate. The ESP8266 is the black PCB and the carrier board is the blue PCB. The carrier board is just needed so can plug it into a breadboard for example. Most of the time they have some other components on them like LEDs and Buttons. These are sometimes needed for programming and debugging. Some boards even have more components on them, like a camera or a small display.
The ESP8266 has some special functionality, most importantly for us: it has WiFi built-in. We (by that I mean Tasmota) will use WiFi to transmit the data.
A more in-depth guide can be found here:
FTDI Programmer
The FTDI Programmer or more general a USB-to-TTL Adapter is needed for programming some of the more advanced microcontrollers. Some boards already include them on the board, but because it is only needed for programming it is really unnecessary to have it on the PCB during operation. Not that beginner-friendly, I know, but some time ago we had a workshop with students from 7th grade and they managed to do this after a short explanation.
DS18B20
maxim integrated describes their sensors as follows: “The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements […]. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor.” In theory, the sensor could get power over the data line but we will also use the third pin for power. This will result in a more reliable usage.
What you will do
Today we are going to build a simple example with one digital temperature sensor. This temperature sensor will be connected to an ESP8266 which will run an open-source community-driven firmware called Tasmota. We want to use this because we then do not need to code anything. The microcontroller will then send the data periodically to a so-called MQTT broker. This will allow Node-Red to pick up your data and place it in the influxdb where it gets saved. Grafana can then access the data, even historic ones, and display it in a nice graph. This concept can be adapted to many different sensors.
Doing stuff
Allons-y!
Breadboard prepartion
So get all your stuff together and build up the breadboard. Here is the schematic. If your Programmer has male headers, you can plug it directly into the breadboard.
Installing the Tasmotizer
Tasmotizer is “The full-featured ESP8266 flashing tool for Tasmota.” (2019, Ziółkowski). This tool makes it very easy to flash tasmota onto an ESP8266. But before we can use it, we need to install it on our machines. There are multiple options:
- Windows Standalone
- pip
- clone the repo
In this article, I will go with option 3: clone the repo Just follow these few steps:
- Download the repo from Github: Tasmotizer on Github OR clone it with the command line git interface:
git clone https://github.com/tasmota/tasmotizer.git
- For the next steps make sure pip and python3 are installed. To check this, you can use these two commands:
pip -V
andpython3 -V
. On Ubuntu systems, these should be installed by default. Next, go into the folder where you extracted or cloned Tasmotizer into. We need to install some dependencies. For this just use this command:pip3 install -r requirements.txt
. This will install all packages mentioned in therequirements.txt
. - To start Tasmotizer just use this command now:
python3 tasmotizer.py
You are now ready to start tasmotizing!
Tasmota
I now mentioned Tasmota multiple times but never explained what it really is. I think now is a good time to do that.
Tasmota offers “Total local control with quick setup and updates. Control using MQTT, Web UI, HTTP or serial. Automate using timers, rules or scripts. Integration with home automation solutions. Incredibly expandable and flexible.” (Tasmota Community) It all started because someone wanted to hack a device for home automation. Most of the time these are bound to the cloud. This really sucks (to be honest). So he started writing his own firmware for it. Even tho there are many home automation devices out there made by companies, some of them rely on the ESP8266, which is used quite frequently in the maker space. And if there is an ESP8266, then you can flash it (if you want). If you want to learn more about Tasmota take a deep dive into the docs: Tasmota Docs
Flashing Tasmota with Tasmotizer
We are not going to flash some finished product (unfortunately ). We are going to flash our own little ESP8266 with Tasmota just to get started and maybe, just maybe, you like the idea of Tasmota and start to tinker around a bit on your own.
So first plugin in your programmer into your PC where we just installed Tasmotizer. If not already done, open Tasmotizer like mentioned above. You will be greeted with a window like this:
- First select the USB Port, in which you just attached the programmer. On Ubuntu, it will be something like
ttyUSB0
or some other number than0
. - Don't select
Select original firmware
. This is good if you have a real product where you may want to go back to the factory state. We don't need this here. - Under
Select image
We could now download the latest firmware from GitHub ourselves or we just select the optionRelease
. We can leave the option astasmota.bin
. This should be the latest firmware available. There are also other binaries available. These have most of the time some special functions included. We don't need them here right now. If you are interested in all the options you have to take a look at the documentation. - The Huzzah Board we have is not a
Self-resetting device
so we, unfortunately, cannot tick this option. The last optionErase before flashing
can be left as default. - If you did everything correctly, you can now hit
Tasmotize!
. This will then start the flashing process. First, it will download the firmware you selected. Then it will start the erasing process. Because the Huzzah is not a self-resetting device we have to bring it into the programming mode. Therefore you have to keep pressing theGPIO0
Button (on other boards it is sometimes calledPROG
), then hit theReset
(or sometimesRST
) once and then you can let go of the other button. The ESP8266 is now in programming mode. From a technical perspective, you have just pulled theGPIO Pin 0
toGround / GND
which gets detected on start by the ESP8266, and it then goes into programming mode. If you have done that Tasmotizer will erase the current firmware and flash on the one.
Tasmota is now installed on our ESP8266. Hit the Reset
one more time to power cycle the device.
Configure Tasmota - Part 1
We now need to configure Tasmota. This is partly done in Tasmotizer and partly done in a web UI.
With the ESP8266 still attached, you can click on Send config
. A new window will appear.
We are going to use them to set the WiFi credentials. For later use the
Recovery WiFi
-Option could be helpful. When the ESP8266 can not connect to the configured WiFi, it will open up a WiFi-Hotspot. You can then connect to it and make configuration changes. We will not use the other options in the Send config
window.
So for now just activate WiFi
and type in your desired WiFi credentials. Then hit Save
. Tasmotizer will now upload the config to the Tasmota firmware on the ESP. The device will automatically restart after that, to apply the new configuration.
After the restart, the ESP8266 will try to connect to our configured network. If we've done everything correctly this should take only a couple of seconds. Because the rest of the configuration happens in a web UI, we have to find out the IP of our ESP. Tasmotizer has a cool feature for that. Just click Get IP
, and you will get the IP displayed. Copy it to the URL bar in your browser and open up the page.
We will be greeted with this page:
First we need to go into
Configuration -> Configure Module
. Because we are using a generic ESP8266, we have to choose under Module type
the module Generic (0)
. Then we need to save the configuration. The ESP will restart and we then need to go back into the same menu. There, we now have more GPIO options. I attached the DS18B20 to GPIO2. If you don't know which pin is which on your particular board, you will have to google the pinout for it yourself. Either way, I will select for GPIO2
the option DS18x20
and hit Save
. After the ESP has restarted we can go back to the menu. If we've done everything correctly you will get the temperature measured by the sensor displayed in the main menu. All that without coding. Great right?
But wouldn't it be even better if we could have a nice little graph of the temperature on the internet?
Configure Tasmota - Part 2
MQTT
Before we can go on with displaying our data on the internet, we need to configure MQTT with our ESP. All you have to know about MQTT is basically, that it is a TCP protocol where you can publish messages on a specific topic and other machines can subscribe to these. It is commonly used in IoT because of its ease of use. All this communication is handled by an so called MQTT Broker. A Server in simpler terms.