From f7993b536d01957e5e9cfc91af01617d7e48704c Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Thu, 27 Jul 2017 16:44:56 +0100 Subject: Initial commit --- README | 3 +++ photon.ino | 36 ++++++++++++++++++++++++++++++++++++ ring.rb | 14 ++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 README create mode 100644 photon.ino create mode 100644 ring.rb diff --git a/README b/README new file mode 100644 index 0000000..03914a1 --- /dev/null +++ b/README @@ -0,0 +1,3 @@ +My entry for the Flashing Light Prize 2017 + +https://www.youtube.com/watch?v=OtDt_FSoU8c diff --git a/photon.ino b/photon.ino new file mode 100644 index 0000000..da1c5a1 --- /dev/null +++ b/photon.ino @@ -0,0 +1,36 @@ +#include + +bool bulb = false; + +void callback(char* topic, byte* payload, unsigned int length); + +MQTT client("server.flashinglightprize.nathan.uk0.bigv.io", 1883, callback); + +void callback(char* topic, byte* payload, unsigned int length) { + char p[length + 1]; + memcpy(p, payload, length); + p[length] = NULL; + + if (!strcmp(p, "0")) { + bulb = !bulb; + if (bulb) { + digitalWrite(D0, HIGH); + } else { + digitalWrite(D0, LOW); + } + } +} + + +void setup() { + pinMode(D0, OUTPUT); + client.connect("bulb"); + if (client.isConnected()) { + client.subscribe("ring/0"); + } +} + +void loop() { + if (client.isConnected()) + client.loop(); +} diff --git a/ring.rb b/ring.rb new file mode 100644 index 0000000..b355075 --- /dev/null +++ b/ring.rb @@ -0,0 +1,14 @@ +require "rubygems" +require "mqtt" + +IAM = ARGV.shift +TO = ARGV.shift + +MQTT::Client.connect("server.flashinglightprize.nathan.uk0.bigv.io") do |c| + c.get("ring/#{IAM}") do |topic, message| + if message == IAM then + sleep 0.1 + c.publish("ring/#{TO}", TO) + end + end +end -- cgit v1.2.1