digiTEMP

Digitemp on small TP-Link WR703N wireless router

Measuring ambient temperature with cheap Dallas sensor DS18B20 (~ 1$) over USB 2.0 to UART TTL 6PIN Module Serial Converter CP2102 (~1,50 $) and showing temperature on simple static html web page hosted on wireless router TP-Link WR703N (~ 25$), acting as cheap wireless “meteo” station.

We need wireless router TP-Link WR703N with OpenWrt image on it. If you don’t know how to flash with OpenWrt, take a look on great OpenWrt Wiki page.

Simple electronic circuit

You can order USB 2.0 to UART TTL 6PIN Module Serial Converter CP2102 from e-bay and Dallas sensor DS18B20 from Maxim-IC (or you can acquire one free sample🙂

– connect GND and +5V to DS18B20

– connect RX and TX together and to thedata line of 1-wire sensor DS18B20

– that’s all🙂

Installing OpenWrt driver for UART CP2102 USB module

On fresh OpenWrt installation, upgrade and install required package:

opkg update && opkg install kmod-usb-serial-cp210x

Installing digitemp package for reading temperature from sensor

opkg install digitemp

Initializing sensor

digitemp_DS9097 -i -s /dev/ttyUSB0
  • execute ls/dev/ command to find your UART location

You should get output like this:

DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Turning off all DS2409 Couplers
.
Searching the 1-Wire LAN
28CBC89A0300007B : DS18B20 Temperature Sensor
ROM #0 : 28CBC89A0300007B
Wrote .digitemprc

Reading temperature from sensor

digitemp_DS9097 -a

You should get output like this:

DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Jun 25 21:19:55 Sensor 0 C:26.06 F: 78.91

Adding some startup commands

Edit /etc/rc.local file to add some startup command which initiate sensor after every reboot. You can edit it with included vi editor, or you can install nano editor with:

opkg install nano

Now edit /etc/rc.local file

nano /etc/rc.local

and add this line:

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
sleep 60 && digitemp_DS9097 -i -s /dev/ttyUSB0
exit 0

After modification, press Ctrl+X, accept with Y, and press Enter …

  • sleep 60 add 60 second pause before execute digitemp command

Installing uhttpd web server and make it run on startup

Install with:

opkg install uhttpd

Enable with:

/etc/init.d/uhttpd enable

Manually start with:

/etc/init.d/uhttpd start

Making simple html page

Create simple html web page which will show temperature.

cd /www && nano index.html

Copy paste below code:

 <html>
        <head>
                <title>Temperature</title>
        </head>
        <body bgcolor="#222222">
                <table align="center" border="0" cellpadding="0" cellspacing="0">
                <tbody>
                <tr>
                <td style="text-align: center; "><span style="color:#696969;"><span style="font-size: 90px; "><strong><span style="font-family: verdana, geneva, sans-serif; ">Temperature [&deg;C]</span></strong></span></span></td>
                </tr>
                <tr>
                <td style="text-align: center; "><span style="color:#66cc00;"><span style="font-size:300px;"><span style="font-family: verdana, geneva, sans-serif; ">27.13</span></span></td>
                </tr>
                </tbody>
                </table>
                <p>
                &nbsp;</p>
        </body>
</html>

After modification press Ctrl+X, accept with Y, and press Enter …

Getting and adding sensor data (temperature) to html page

We will use default cron service to get data from sensor and refresh html page with current data every minute. Edit /etc/crontabs/root with:

nano /etc/crontabs/root

Add this line:

 */1* * * * TEMP=`digitemp_DS9097 -a | grep -i sensor | awk '{print $7}'`; sed -i -r "14s,>[^<]*</,>${TEMP}</," /www/index.html

After modification, press Ctrl+X, accept with Y, and press Enter …

Restart cron service:

/etc/init.d/cron restart

Now open your browser and enter IP adress of your router (example: http://192.168.100.1) and you should get something like this:

That’s it folks🙂

valentino.sefer[at]gmail.com

4 thoughts on “digiTEMP

  1. this is exactly what i am in need of!
    but i am having some issues,
    i get the browser open, and it shows the temp, but not the correct one, but when i do the “digitemp_DS9097 -a” command i get the correct temp. can any one help??

  2. Thanks for a great article!

    I have a problem adding the script to /etc/crontabs/root

    The qoutation marks are turned into … in vi, and ^?^? in Nano, and the script won’t work. Does anybody have a clue how to get around this?

  3. Pingback: Cheap tweeting RFID home security/automation system V1.5 | labOS - otvoreni multimedijski laboratorij

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