Monitor Your Room Temperature – With An AVR-NET-IO

I was using an AVR-NET-IO with the Ethersex firmware to log temperatures. I used an NTC and measured the the voltage drop across to get the temperature. The logging was done with (a previous version of) this script.

Real Time Plotting

This can be done with plotTemperaturesRealtime.py.

Analysis Using R

With temperature_3.txt containing lines in the following format:

23.67, "2009-11-28 13:07:01.347245"
23.75, "2009-11-28 13:08:01.704526"
23.75, "2009-11-28 13:09:02.086855"
23.75, "2009-11-28 13:10:01.473609"
23.75, "2009-11-28 13:11:01.776415"
23.91, "2009-11-28 13:12:02.116962"
[...]

Run the following code in R:

postscript("plot_3.eps", horizontal=FALSE, onefile=FALSE, height=7, width=12, pointsize=10)
data<-read.table("temperature_3.txt",sep=',') # not csv as we do not have a header row
dates <- strptime(data$V2, format="%Y-%m-%d %R")
plot(dates,data$V1,xlab='2009',ylab='Temperature [°C]')

and you'll get an image like this:

Logged temperature plotted with R

Analyzing Older Data → Large Data Set

I was logging the temperature for quite some time and thus had this large dataset:

28.09 - 2009-08-19 00:03:01.281959
28.00 - 2009-08-19 00:03:03.016500
27.74 - 2009-08-19 00:04:01.614767
27.66 - 2009-08-19 00:05:01.934760
28.09 - 2009-08-19 00:06:01.274991
... and so on

Unfortunately the format was not perfect to use with R, so I used the following python code to transform the data format:

#!/usr/bin/env python
# -*- encoding: UTF8 -*-
# Author: Philipp Klaus, philipp.klaus AT gmail.com
def main():
    # for large files we use xreadlines instead of just f.readlines():
    f = open('log_2009-autumn.txt','r')
    out = open('log_2009-autumn.csv', 'w')
    for line in f.xreadlines():
        out.write(line.replace(' - ',', "').replace('\n','"\n'))
    f.close()
    out.close()
if __name__ == '__main__':
    main()

The Python script produced the following log_2009-autumn.csv file:

28.09, "2009-08-19 00:03:01.281959"
28.00, "2009-08-19 00:03:03.016500"
27.74, "2009-08-19 00:04:01.614767"
27.66, "2009-08-19 00:05:01.934760"
28.09, "2009-08-19 00:06:01.274991"
... and so on

Now I was able to use it in R:

png('log_2009-autumn.png',width=10000,height=550)
# postscript("log_2009-autumn.eps", horizontal=FALSE, onefile=FALSE, height=5, width=15, pointsize=7)
data<-read.table("log_2009-autumn.csv",sep=',') # read.table() not read.csv() as our csv file has no header!
dates <- strptime(data$V2, format="%Y-%m-%d %R")
plot(dates,data$V1,xlab='2009',ylab='Temperature [°C]')

and get this huge 10,000x550 px image:

The temperature log autumn 2009

Later, I was taking that data again to draw a boxplot in gnuplot and I also created the same plot pooling the weeks instead.

using Python

#!/usr/bin/env python
# -*- encoding: UTF8 -*-

""" room temperature plotted
"""

from pylab import *
import sys
import csv
import urllib
import pdb
from dateutil import parser


def main(*args):
    raw_temp_log_socket = urllib.urlopen("http://example.com/temperature-logbook.txt")
    raw_temp_log = iter(raw_temp_log_socket.read().split("\n"))

    temp_log = csv.reader(raw_temp_log, delimiter=',',quotechar="\"", skipinitialspace=True, quoting=csv.QUOTE_MINIMAL)

    timestamp = []
    temperature = []
    temp_log.next()
    for row in temp_log:
        if len(row)==2:
            temperature.append(row[0])
            timestamp.append(parser.parse(row[1]))

    plot_date(timestamp, temperature, fmt="go", tz=None, xdate=True, ydate=False, label="Zimmertemp. Siolistr.")
    legend()
    grid()
    show()

if __name__ == "__main__":
    main(*sys.argv)

giving this:

room temperature plot

Test to communicate via IPv6

#  Using nc6 - IPv6 enabled netcat - to tell netcat to use IPv6 to communicate with the avrnetio:
# (See <http://www.ethersex.de/index.php/Dallas_1-wire_Bus#sh_oder_bash>.)

ESEXIP=2001:6f8:1209:23:42::17 #IPv6 Adresse
echo adc get | nc6 -u $ESEXIP 2701 -q 1 2>/dev/null

Resources

Comments