Up: Smart Plug

Previous: Smart Plug Prototype 0.1

Smart Plug Prototype 0.2

This next phase of the prototype is adding the ability to control the light over a network. Importing Node’s standard net package allows us to listen for simple TCP connections, and to activate the light in response.

The way we’re communicating with our application is with Telnet. Telnet is a simple application that can open a TCP socket and provide an interactive text-based interface for sending and receiving data. Here we’re not even using it to send any data, it’s only being used to connect and immediately close, and that connection being established is enough of a command at this point.

var b = require('bonescript');
var net = require('net');
var LEDS = [
LEDS.forEach(function (LED) {
  b.pinMode(LED, b.OUTPUT);
  b.digitalWrite(LED, b.LOW);
var server = net.createServer(function(connection) {
  LEDS.forEach(function (LED) {
    b.digitalWrite(LED, b.HIGH);

server.listen(9999, function () {});

Next up, we need a way to turn the LED off.

Next: Smart Plug Prototype 0.3

Creative Commons License