IoT: Temperature logger

The objective of this post is to explain the architecture of a simple temperature logger using the ESP8266 and a web server deployed on the cloud.


In order to implement the smart node that measures the temperature and sends it to the server, we simply used a microcontroller with the capability of connecting to the Internet and a temperature sensor.

The microcontroller is the ESP8266, integrated in a NodeMCU board, shown in figure 1. The advantage of the NodeMCU board in comparison to other simpler ESP8266 based boards is that this one already has a usb header and the usb-serial converter device in the PCB. So, it’s a plug and play solution.


Figure 1 – NodeMCU board.

The programming of the Node MCU board was done using the Arduino based IDE.

The sensor used to measure temperature was the DHT11, shown in figure 2. This is a cheap sensor that allows to measure not only temperature but also humidity. In this example, we only send temperature to the server, but the architecture would be the same to also measure humidity.


Figure 2 – DHT11 integrated in a ready to use board. Taken from [1].

It’s important to take into consideration that the DHT11 has a 1ºC resolution [2], meaning that it may not be suitable for more precise applications. Nevertheless, the objective was  to create a proof of concept of the whole system and thus, changing the sensor to a more precise one, is a simple and easy solution.


Server platform

The main objective of this project was to make the temperature measurements available at a server, where a user could access them in a dashboard style (in this case, a temperature chart).

In this project, we used the OpenShift Platform to deploy the application. Openshift is a Platform-as-a-Service from RedHat that allows for quick development, hosting and scaling of applications in the cloud [3] and has a free plan [4], which is perfect for this kind of tests.

Openshift allows the development of applications in typical languages such as Python, Java, Ruby and PHP, and even in more recent ones, such as Scala and Go [5], amongst others. In terms of databases, it supports MongoDB, MySQL, PostgreSQL and SQLite [5].

One down side of this platform is that the configuration process is not trivial and is mainly performed using the command line, which may not be easy for everyone. Although there are many installation tutorials, some configurations are not so easy as they seem. Personally, I had a really hard time configuring the remote access using SSH. Nevertheless, once everything is properly configured, it becomes a very easy to use and powerful platform.



The backend of the application was developed using the Flask web framework for Python. This is a very easy to use framework which allows the creation of a simple application with very few lines of code (see the “hello world” example here).

In a very succinct way, in Flask we define functions that are triggered by a specified URL. In those Python functions, we define the backend behavior of the application for each URL, such as accessing databases, validating user credentials or serving the frontend files. Of course, this is a very reductive description of the wide range of possibilities that can be implemented using this framework, which are outside the scope of this post.

In this concrete case, we implemented two distinct URLs on our application. The first one receives HTTP requests with a temperature value as parameter. For each request, the application puts a timestamp on it and inserts it in a database.

Naturally, this is the entry point where the ESP8266 connects and posts the measurements from the DTH11.

The other URL is the one the user accesses to check the data in the format of a chart. So, the handling function accesses the database to retrieve the last measurements stored (we limited the maximum number of measurements retrieved) and using Flask’s template engine it passes those values to the HTML template (more about template engines here), which is returned to the user’s browser.

In the HTML file, the chart is created using Charts.js, which is an Open Source chart library [6].


Architecture of the system

The architecture of the system is summarized in figure 3 and contains all the elements described before. Although the system was created to log temperature, it is easly scalable to work with other types of information from sensors (ex: humidity, luminosity).

IoT temperature logger

Figure 3 – Architecture of the system.

Figure 4 shows the chart that is presented to the user and contains the temperature measurements performed. It’s important to refer that the frontend was note one of the main preoccupations and thus we used a very simple chart type, just to illustrate the concept.

iot temperature chartFigure 4 – Temperature chart.

Final Notes

As stated before, this is just a proof of concept project, with the objective of demonstrating the interaction between an ESP8266 board and a web server, in order to materialize the concept of IoT. So, the application just simply stores and retrieves data  from a database, and there is not user authentication or any other implementations needed for a full web service for users.

The requests performed to the server are in HTTP, meaning that the information is sent in plain text, for the sake of simplicity. Of course that, for a commercial implementation, the data would need to be protected using HTTPS or any other type of mechanism.

It’s also important to take into account that timestamping the measurements in the server may not be the best option, since the delay between the measurement and the arrival of the information to the server may not be negligenciable. The best option would be implementing the timestamping in the ESP8266 (see an example here of an implementation of a clock for microcontrollers).





14 Replies to “IoT: Temperature logger”

    1. Hi Claudio. I thought there was, since I have already some followers. Probably I messed some configuration and did not notice, I will check it. Thanks for the advice 🙂


    1. Thanks for your feedback 🙂 Well, personally I try to post regularly and also share my posts on other networks, such as Linkedin, google +, youtube, etc. I also try to use some images/schematics to make content more appealing and avoid very long posts. Other than that, I must admit that I don’t have any special tip, I just try to share a bit of my work.

      Liked by 1 person

    1. I don’t know how much you are familiarized with microcontrollers, Arduino, etc, but the ESP8266 is basically a device that you can program to do things like reading sensors, controlling actuators and it also has functions to connect to a WiFi network and then send/receive HTTP requests, amongst many other things.

      You can read a little bit more about the device here:

      If you are interested in actual code for the ESP8266, check bellow,

      Connect the ESP8266 to a WiFi network:

      Send HTTP requests with the ESP8266:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s