Introducing In-Glass, a Temperature Monitoring and Logging Utility

May 20, 2014

As humans, we typically like to know that our stuff is safe, even when we can’t be near it. Smoke detectors are nice, but they typically aren’t connected to the Internet. To that end, I, along with my friends Dustin and Lance, created In-Glass. On the hardware side, it utilizes a TEMPer USB thermometer, connected to any PC running a Linux distro that supports PyUSB. On the software side, it makes use of the excellent temper-python driver by padelt, and the awesome Flask framework.

Burrrr! Hopefully this isn't the temperature in your house.

Burrrr! Hopefully this isn’t the temperature in your house.

In-Glass works by serving a website using Flask. On an HTTP query to the main page, it retrieves the temperature from the device and displays it, with the background of the page colored based on the warmth. Optionally, users can enable auto-updating at an arbitrary number of seconds, as well as choose to use the philistine centigrade measurement system. The app remembers these preferences via HTML5 LocalStorage, so I’m sorry to say that if you feel compelled to use old versions of Internet Explorer, the app won’t work for you. Stop it.

The app generates a JSON API for the current temperature and the logs of the temperature for times the app was running. The app uses its own API for the front-end: The current temperature and graphing pages call the API to get the data. The excellent D3 graphing library is used to create the graphs, though I fear we have barely tapped its potential in this regard.

Another neat feature of In-Glass is its method of generating temperature logs. A separate thread is created which is responsible for logging the data every 15 minutes. Logs are stored as CSV files, because the files are hella small compared to JSON. But outputting the CSV as the API would be stupid as hell, so when a request is made to a particular log, the app parses the corresponding CSV file and generates appropriate JSON.

#Output logs for a given device and day as JSON
def json_history_output(device, year, month, day):
file = build_log_path(device, year, month, day)
history = []
with open(file, ‘r’) as log:
log_read = csv.reader(log)
for row in log_read:
if(len(row) > 0):
‘hour’: row[0],
‘minute’: row[1],
‘f’: row[2],
‘c’: row[3]
return jsonify(logs=history)

A similar app, PiThermo, was created by wowo last year. We based certain parts of In-Glass’s architecture on it. It’s a great program, but there are a few key differences between it and In-Glass…notably:

  • PiThermo uses a Dallas digital thermometer, which are significantly cheaper, but require an adapter or pin breadboard to connect to the PC. The TEMPer connects via USB.
  • PiThermo stores logs in a Mongo database, rather than CSV files as In-Glass does.
  • PiThermo doesn’t require any drivers and reads the temperature from the system bus, as far as I can tell.
  • In-Glass has an auto-updating temperature display, while PiThermo doesn’t, as far as I can tell.
  • In-Glass uses D3, while PiThermo uses Google Charts.

So check it out! It’s on GitHub and PyPI!

Leave a Reply

Your email address will not be published. Required fields are marked *