Thermostat Controller

This example Thing is a controller. A controller controls other Things.

Let's build a thermostat controller.

Consider the house example below. In the bedroom, Thing 1 senses the temperature in the bedroom. In the basement is Thing 2 with two relays, one to turn a furnace on/off and one to turn air conditioning on/off. We've already built these two Things. Thing 1 is the Temperature/Pressure Sensor example. Thing 2 is the Relays example. We'll reuse those two examples Things and build a new one, Thing 3.

Thing 3 is our new controller Thing. It is connected inside the house to Thing 1 and 2 over Wifi.

Thing 3' is Thing Prime for Thing 3, so it's really just a copy of Thing 3 but running in the cloud.

Controller Function

Thing 3's controller job is pretty straight forward:

  • Monitor Thing 1 temperature

  • If temperature is greater than set-point, then turn on air conditioning and turn off furnace, via Thing 2

  • If temperature is less than or equal to set-point, then turn off air conditioning and turn on furnace, via Thing 2

  • User can adjust set-point from Thing 3 UI

  • User can adjust set-point from Thing 3' UI over the Internet


If the Internet connection goes down, Thing 3 continues to function as controller and the user can view Thing 3 UI over the local Wifi network. When the Internet comes back up, the user can view Thing 3' from anywhere.

User Interface

Let's look at the UIs of all four Things. We've seen Thing 1 and 2 UIs before with the Temperature/Pressure Sensor and Relays examples. Thing 3 UI is a console for the thermostat showing which relay is on/off, the temperature at Thing 1 and a slider to adjust the set-point to the desired temperature. Thing 3' sees the same UI as Thing 3. Thing 3' UI is available over the Internet, so point your phone browser to its address to view. Things 1, 2, and 3 are only viewable from within the local Wifi network.

Here's a closer look at Thing 3 UI.

Hardware Setup

Thing 1 has same hardware setup as Temperature/Pressure Sensor.

Thing 2 has same hardware setup as Relays.

Thing 3 doesn't require any special hardware since it doesn't control I/O directly.

Thing 4 runs in the cloud so no hardware setup.

Software Setup

Files for this example are located in examples/thermo.


examples/thermo/

├── assets // Thermo assets

│   ├── css

│   │   └── thermo.css

│   ├── images

│   ├── js

│   │   └── thermo.js

│   └── templates

│   └── thermo.html

├── cmd

│   └── thermo

│   └── main.go // Thermo application

└── thermo.go // Thermo Thing


Thing 1 has same software setup as Temperature/Pressure Sensor.

Thing 2 has same software setup as Relays.

Thing3/Thing3' run the thermo application above.

Building

Build Thing 1 and 2 per Temperature/Pressure Sensor and Relays.

$ cd merle

$ ./build examples/bmp180

$ ./build examples/relays

Build Thing 3 and Thing 3':

$ cd merle

$ ./build examples/thermo

Running

Run Thing 1, specifying Thing 3 as mother:

// (on Thing1)

$ cd merle

$ ~/go/bin/bmp180 -rhost <thing 3 address>


Run Thing 2, specifying Thing 3 as mother:

// (on Thing2)

$ cd merle

$ ~/go/bin/relays -rhost <thing 3 address>


Run Thing 3, specifying Thing 3' as mother:

// (on Thing3)

$ cd merle

$ ~/go/bin/thermo -rhost <thing 3' address>


Finally, run Thing 3':

// (on Thing3')

$ cd merle

$ ~/go/bin/thermo -prime -TLS 443