2 # Copyright (C) 2011-2012 W. Trevor King <wking@tremily.us>
4 # This file is part of pypid.
6 # pypid is free software: you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation, either version 3 of the License, or (at your option) any later
11 # pypid is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along with
16 # pypid. If not, see <http://www.gnu.org/licenses/>.
18 """Log control and ambient temperature every 10 seconds.
20 usage: python temp_monitor.py
25 from pypid.backend import get_backend
28 b = get_backend('melcor')()
31 with open('temp_monitor.log', 'a') as f:
34 next_time = last + period
36 time.sleep(next_time - time.time())
37 tstr = time.strftime('%Y-%m-%d %H:%M:%S')
38 temp = str(b.get_temp())
39 ambient = str(b.get_ambient_temp())
40 f.write('\t'.join([tstr, temp, ambient]) + '\n')
42 print('\t'.join([tstr, temp, ambient]))