Skip to content

Instantly share code, notes, and snippets.

@mtcomb
Last active August 29, 2015 14:01
Show Gist options
  • Save mtcomb/a6b5d662bbf64d9b8fb1 to your computer and use it in GitHub Desktop.
Save mtcomb/a6b5d662bbf64d9b8fb1 to your computer and use it in GitHub Desktop.
measuring temperature with the TEMPer USB Thermometer in every 60 seconds
#!/usr/bin/python
from temperusb import TemperHandler
import threading, time
import logging
# logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
fh = logging.FileHandler('temp.log')
fh.setLevel(logging.INFO)
fmt = logging.Formatter('%(message)s')
fh.setFormatter(fmt)
logger.addHandler(fh)
# temperusb
th = TemperHandler()
devs = th.get_devices()
def foo(next_call):
logger.info('%0.2f %s'%(time.time(), devs[0].get_temperature()))
next_call = next_call+60
threading.Timer( next_call - time.time(), lambda :foo(next_call) ).start()
next_call = time.time()
foo(next_call)
#!/usr/bin/python
import numpy as np
import matplotlib.pyplot as plt
import time, datetime
D = np.loadtxt('temp.log')
x = map(lambda t: datetime.datetime.fromtimestamp(t), D[:,0])
y = D[:,1]
plt.plot(x,y)
plt.gcf().autofmt_xdate()
plt.ylim([10,30])
plt.show()
#!/bin/bash
watch -n 10 'gnuplot << EOF
set term dumb
set timefmt "%s"
set format x "%m/%d/%Y"
set xdata time
set xtics 24*60*60
#set yrange [10:40]
set autoscale fix
plot "< tail -n `expr 3 \* 24 \* 60` temp.log" \\
usi (\$1+9*60*60):2 w l t "temperature"
EOF'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment