Temperature monitoring easily using Wifi

First of all this project is only for my fun.

I was real lucky to find this cheap wemos D1 mini clones on aliexpress. Fortunately they are compatible with the original wemos D1 mini.

D1 mini is a mini wifi board based on ESP-8266EX.


11 digital input/output pins, all pins have interrupt/pwm/I2C/one-wire supported(except D0)

1 analog input(3.2V max input)

a Micro USB connection

Compatible with Arduino

Compatible with nodemcu

It is more than enough for me to start playing with it. One of my favorite is arduino ide, hence I will use it for the project, see https://www.arduino.cc/en/Main/Software

My plan was to split the monitoring process to two separated part: temperature measuring runs on the D1 mini as, temperature sensor with web interface. datadbase side runson my home linux server. It collects all measured temperature data in a RRD database and provides visualization, graph on an apache webserver.

First step is some soldering: 10kOhm thermistor (NTC) is used as sensor. The termistor is connected to D1 mini A0 pin with some wire in order to be able to placed to outside.


Next step is the D1 mini firmware. I used a simple webserver code and some mathematics to calculate the temperature from AD pin read. More info on http://playground.arduino.cc/ComponentLib/Thermistor2
On the wifi interface the D1 mini uses my DHCP server to get IP address. The address is reserved in my DHCP server config.

The D1 mini code:


const char* ssid = “Home-change-it”;
const char* password = “top-secret-change-it”;

int ledPin = D4; // Beepitett led a wifi-n
WiFiServer server(80);

float ntc(int analogpinNum){

int RawADC = analogRead(analogpinNum);

long Resistance;
double Temp;

// Assuming a 10k Thermistor. Calculation is actually: Resistance = (1024/ADC)
Resistance=((10240000/RawADC) – 10000);

/* Utilizes the Steinhart-Hart Thermistor Equation: */
/* Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]^3} */
/* where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08 */
Temp = log(Resistance);
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp – 273.15; // Convert Kelvin to Celsius

// Uncomment this line for the function to return Fahrenheit instead.
//Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert to Fahrenheit

return Temp; // Return the Temperature


void setup() {

pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {


digitalWrite(ledPin, HIGH);

void loop() {

// Check if a client has connected
WiFiClient client = server.available();
if (!client) {

// Wait until the client sends some data

// Read the first line of the request
float sensorValue = ntc(0);
// Match the request

client.print(“Temperature Celsius:”);



Yes, you are right there is no html header, body, etcetera, but we will process the data on a server not on a web browser. By the way the browser can show the webpage as a pure text.
Next step reserve the IP address for D1 mini. (Please google it for your DHCP solution.) I’m using Please make a test on it at this point. If you can’t see the temperature text when connecting with a web browser, you need some debuging, and need to check the DHCP server log. If you have wifi connection problems, you can simple add serial debug into the arduino code.

Next step: prepare the RRD on the linux box:

rrdtool create test.rrd –start 1477447200 DS:temp:GAUGE:600:U:U RRA:AVERAGE:0.5:1:24 RRA:AVERAGE:0.5:5m:90d RRA:AVERAGE:0.5:1h:18M RRA:AVERAGE:0.5:1d:20y

We can store the temperature data for 20 years and detailed in 90 days.

Next step: feed the data into RRD.
vi /usr/local/bin/temp.sh

cd /tmp/
wget > /dev/null
dos2unix index.html
a=`cat index.html | cut -d”:” -f2`
#echo `date +%s`”:”$a
cd /(insert your test.rrd path)
rrdtool update test.rrd N:$a
rm /tmp/index.html

Next step: create a crontab to schedule the feed of rrd. It updates the database in every minute. (you can adjust if you do not want high load with it.)

crontab -l

* * * * * /usr/local/bin/homero.sh &>/dev/null

Now we have a database with data. It is time to install apache and configure it.

Next step: create a simple webpage and generate the graph. The webpage is realy simple and the 2 years long graph is not only a joke.


Of course you need to copy this file under the wwwroot.

How to create the graph?

rrdtool graph hour.png –end now –start end-36000s DEF:temp=test.rrd:temp:AVERAGE LINE2:temp#FF0000

Please read the https://oss.oetiker.ch/rrdtool/tut/rrdtutorial.en.html

It looks like this:




I hope it helped you to get clouser to building this project. It took me about 3 hours with it.

If you have questions please feel free to ask me.

This entry was posted in Elektronika, Uncategorized. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s