Introducing WebKeezer
An Omega2 powered temperature control and spillage monitor
A keezer is a freezer repurposed for kegs.
A WebKeezer lets you monitor temperature from the web.
Materials
Here are the components.
- Omega2
- Relay
- Dallas Systems DS18B20 temperature sensors
- Various electronic components
The completed setup is still lacking an enclosure.
Omega2
A bare Omega2 is sufficient for this project. However, if you add more components an Omega2+ or added SD storage may be necessary.
DS18B20
I’ve used these for other (Arduino) projects and they have served me well.
Here's the onion wiki page for 1wire devices. I've used them with Arduino at 5V and had difficulty on my Omega2 with 3.3V so I've stayed with the tried and true 5V. The Omega2 can read both sensors on a single input pin.
I use two sensors: one as input for the temperature control, and the other to monitor the air temperature near the taps. The sensor that is used for temperature control is in a jar with about a cup of water. This keeps the temperature signal nice and smooth and adds some thermal mass to prevent large temperature swings and frequent cycling of the freezer.
Relay
The relay is housed in the electrical outlet box and is powered from the custom board.
The relay needs 5V to be switched and breaks the hot wire to the outlet when activated.
Float Switch
I made a simple float switch from a piece of weather sealing foam. The foam floats on water and lifts the wire on the left to close the connection to an input pin.
Here’s a diagram:
The input pins on the Omega2 cannot handle 5V!
Setup
Here's an outline of the software components used in the project.
- Python script to take readings, control the relay, and log data
- Local data files
- cron schedule to run the python script
- Webpage and Javascript file for showing information
Python
The Python script grabs data from the command line tool gpioctl to use as inputs for the control logic.
It's all
here on GitHub. Since the script is run only on the cron schedule I use a text file keezerparams.txt to keep a few parameters for the script to use when it runs. This included the setpoint and a temperature differential to control swiching the relay.
The guts of the logic is pretty simple:
Data Log
The python script runs every minute and logs temperature and relay states.
Data is appended to a txt file and records the values: Temp1, Temp2, Setpoint, RelayState, FloatState
6.1,8,6,0,0
,8.1,,,
Unchanged values are left blank to save disc space. (This is probably unnecessary, but I haven't added an SD card to my Omega.)
To avoid reading the entire log file for displaying on the webpage I also write a recent.json file with only the most recent data.
data = {“temp1”: 6.1, “temp2”: 8.1, “relayState”: 0, “setpoint”: 6, “floatState”: 0, “time”: “02.10-15:33”}
Cron Schedule
This was my first time using cron and it was much easier than I anticipated.
1. Edit the crontab
#crontab -e
Add this line:
* * * * * /bin/python /root/tempcontrol.py
2. Start cron:
#/etc/init.d/cron enable
#/etc/init.d/cron start
Webpage
My directory /root/webkeezer/ has everything for web display. I link it to /www/console/:
#ln -s /root/webkeezer/ /www/console/webkeezer
Here's the body of the index.html file:
<h1> Hello, this is Keezer!</h1>
<h4 id="timetext">Time goes here</h4>
<h2 id="temptext">temperature 1</h2>
<h2 id="setpointtext">the setpoint</h2>
<h4 id="relaytext">What's the relay doing?</h4>
<h2 id="temp2text">temperature 2</h2>
<h4 id="floortext">What's the status of the floor sensor?</h4>
<script type="text/javascript" src="script.js"></script>
The file recent.json conveniently packages all the necessary data and script.js needs to be added after setting the id tags so it knows what to update.
The javascript file:
timetext.innerText="Last reading at: " + data.time;
temptext.innerText="Sensor Temp: " + data.tempC;
setpointtext.innerText="Setpoint: " + data.setpoint;
relaytext.innerText="The relay is " + ["Off", "On"][data.relayState];
temp2text.innerText="Tap Temp: " + data.temp2C;
floortext.innerText="The floor is currently " + ["nice and dry.", "FLOODED!"][data.floorState];
To Do:
Plot the data!
There's a fan in the keezer to keep air circulating. It'd be easy to switch it on/off with another relay.