Saturday, March 25, 2017

WebKeezer Plots

WebKeezer, now with plots!

As this is still a work in progress, I'm going to have to rework a lot of code later. Yes, later.

But I've used chartist.js to make a pretty nice plot. If I had more storage space on my Omega, I'd install pyplot and not deal with java, but I'm squeezing the last 100kB out of my on board storage.

Here's the plot:
The yellow line is the temperature in the jar of water that controls the freezer. The setpoint is 5.5 C with a differential of 0.9 C. The red line is from a second temperature sensor I placed near the beer lines and shanks to track air temp. I have a small computer fan inside running continuously. Depending on how it's positioned the air temperature can be about 2 C cooler than shown in this graph.

The code is on GitHub.

I had to add this line to the chartist.css file to get rotated labels:

New Wiring


New Wiring

Relays

I had originally used a custom board from an Arduino project for the external guts for WebKeezer. But now I decided to put my relay expansion to use. The relays on the expansion are only capable of handling 2A so I'm still using the relay in the outlet box.

Temperature Probe Inputs

I've decided to simplify the wiring using phone connectors. The 1-Wire bus only requires a single resistor connecting Vcc to the digital input pin. This allows all inputs to come in through a single port using a phone line splitter. I soldered this together to avoid the need for extra perf board.
The phone cord I got has 6 wires (RJ25) but the jack I'm using has four pins (RJ14). I used black, red, green, for the ground, voltage, and 1-wire bus leaving the yellow wire for potentially reading a switch/button. (I should use the yellow wire for 1-wire bus and green for reading a switch so I can use normal 2-wire  RJ11 cable for switches.)

Float Switch RIP

The float switch didn't work too well. The cold environment made it too stiff. But I'm looking forward to using the new phone cord system when I get something else figured out.

Wednesday, February 15, 2017

Introducing WebKeezer

Introducing WebKeezer

An Omega2 powered temperature control and spillage monitor

Code on github!

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.