Homebrew Web-Enabled Thermostat

Uses mbed, Mission: Cognition baseboard, and Seeedstudio's Grove/Twig modules.

Image of Thermostat Demo

Software:

Download the mbed C++ project files here and the HTML code here

Parts List:

Image of Parts Needed for Thermostat Demo Project

Step 1: Prepare Twig Cables

  • Cut each Twig cable in half.
  • Using wire strippers expose about 1/4 inch of bare wire.
  • Using a soldering iron apply solder to exposed ends of wires (this step is optional but highly recommended). Don't use too much solder -- keep the wire ends thin so they will fit in the terminal blocks easily.
Image of Prepared Cables

Step 2: Configure MC-101 Jumpers

  • Refer to the MC-101 jumper settings page for detailed information.
  • Set the jumper for JP11 to pins 1:2 (left position) to select 3.3V on the 'Analog' (middle) terminal block.
  • Set the jumper for JP12 to pins 2:3 (right position) to select 5V on the 'PWM' (right) terminal block<./li>
  • The remainder of the jumpers can remain where they are since they do not affect this demo.

Step 3: Connect Cables

  • Note: It is expected that the Twig cables color codes will match -- red=Power, black=GND, yellow=Signal, white=NC the color of your cables can be verified by comparing the pinout printing on the Twig modules.
  • Temp Sensor: Connect the wires as follows on the 'Analog' terminal block: red->1 yellow->2 black->8
  • Relays: Connect the wires as follows on the 'PWM' terminal block: red(1,2)->1 yellow(1)->2 yellow(2)-3 black(1,2)->8 (you should be able to fit two wires in one hole)
  • Ethernet: Connect the ethernet cable to the baseboard and your router (the mbed will request an ip address using DHCP).
Image of Wired Cables

Step 4: Prepare uSD Card

  • Using your computer copy the www directory onto the root path of the uSD card. Note that the mbed can only read old-style 8.3 DOS names.
  • Install the uSD card into the slot under the mbed module (it should click into place).

Step 5: Prepare mbed Module

  • Install the mbed module onto the MC-101 baseboard if you have not already.
  • Connect the mbed to your computer using the USB cable included with the mbed module.
  • Copy the thermostat program binary file onto the mbed drive. You can import the thermostat program into your compiler at mbed.org and build the binary file from scratch if you like.
  • Reset the mbed module (by pressing the reset button on top).

Program Operation

It is recommended that you open a terminal to view the serial console output from the mbed (over the USB cable). Details of how this can be accomplished can be found in the 'Working with mbed' section of the mbed Handbook.

Determine the ip address assigned to the mbed module either by monitoring the serial console or from your dhcp server on your router (or perhaps a lucky guess).

From your computer browser (the client) put in the URL http://xxx.xxx.xxx.xxx/ where xxx... refers to the mbed module's ip address. With the default configuration your client computer must have internet access since the jQuery and related files are downloaded from Google and Mission: Cognition servers. If you do not have internet access on this computer you must edit /www/index.htm to use the local versions of the files.

The web page pictured below should appear:

Thermostat Web Page Capture

Use the slider knobs to adjust the heat and cool setpoints. Put your finger on the blue thermistor on the temperature module to raise the temperature and test the thermostat operation.

You might want to configure your router to assign a fixed ip address based on the mac address of your mbed module (printed on the serial console) to make your life easier. If you can get it added as an entry in your DNS even better. That is how I was able to use the URL http://mbed1/ in the screenshot above.

How it Works

index.htm

main.cpp

An RPC function is setup in main.cpp to respond to /GetThermostat/run queries with a JSON compatible string [see GetThermostat(), DoGetThermostat()](unfortunately I could not change the mime type on the response to application/json so this is not strictly correct HTML). The javascript code does a getJSON request to that URL every three seconds or so [see setInterval(), SyncFunc()] and updates the displays and the slider to match [ProcessStateData()]

Meanwhile the mbed module is running a thermostat control loop in addition to polling for HTTP requests. Every half-second the temperature sensor is read and converted to degrees F. About once every four seconds setpoints are commpared to the current temperature to determine if one of the relays should be turned on or off. Hysteresis is used to ensure that the relays do not toggle back and forth if the temperature reading changes by a fraction of a degree across the threshold temperature.

At present there is a significant limitation for the HTTP server on the mbed. It does not handle multiple simultaneous requests well and may crash. The original design for this demo had many more small RPC requests but it proved unreliable. Loading the jquery and css files locally seems to trip up the server as well (multiple reset/reloads may eventually work). Fortunately there are people working on improved and alternative implementations for the HTTP server so this will hopefully be fixed before too long.

Suggested Improvments (Your Homework)

  • Add a seperate relay for fan control. Include startup and shutdown delays.
  • Add UI for adjusting the hysteresis.
  • Add a UI On/Off switch.
  • Add a schedule for system on and off times.
If you are interested in what the business side of Mission: Cognition has to offer visit missioncognition.com.