jonah.id / Smart Plug
  1. 2019-03-21 — Smart Plug Intro
  2. 2019-03-22 — Smart Plug Prototype 0.1
  3. 2019-03-22 — Smart Plug Prototype 0.2
  4. 2019-03-22 — Smart Plug Prototype 0.3 ⬿
  5. 2019-03-22 — Smart Plug Prototype 0.4
  6. 2019-03-27 — Smart Plug Prototype 0.5
  7. 2019-03-29 — Smart Plug Prototype 0.6
  8. 2019-04-04 — Smart Plug Prototype 1.0
  9. 2019-06-05 — Smart Plug Prototype 2.0
  10. 2019-07-14 — Rust on Arduino
  11. 2019-07-28 — W5500 Driver for Rust Embedded-HAL on AVR
  12. 2019-07-31 — Working UDP Listener in Rust (finally)

Smart Plug Prototype 0.3

The next phase of usefullness is turning the light off. In this next version, we keep track of whether the light is on or off, and toggle it upon receiving a TCP connection.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var b = require('bonescript');
var net = require('net');
var LEDS = [
  'USR0',
  'USR1',
  'USR2',
  'USR3'
];
var state = b.LOW;
LEDS.forEach(function (LED) {
  b.pinMode(LED, b.OUTPUT);
  b.digitalWrite(LED, state);
});
var server = net.createServer(function(connection) {
  console.log('Received connection');
  state = Number(!Boolean(state));
  LEDS.forEach(function (LED) {
    b.digitalWrite(LED, state);
  });
  connection.end();
});
server.listen(9999, function () {
  console.log('Ready for commands');
});

This works, but it’s fairly crude. What would be better is defined protocol beyond just listening for connections.

Next: 2019-03-22 — Smart Plug Prototype 0.4

Creative Commons License