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.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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
var b = require('bonescript');
var net = require('net');
var LEDS = [
  'USR0',
  'USR1',
  'USR2',
  'USR3'
];
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);
  });
  connection.end();
});

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

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

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

Creative Commons License