aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Lasseter <Redacted>2017-07-27 16:44:56 +0100
committerNat Lasseter <Redacted>2017-07-27 16:44:56 +0100
commitf7993b536d01957e5e9cfc91af01617d7e48704c (patch)
tree4df98738c1d7ac687f2deb29cbc9c7a6bb6fe321
Initial commit
-rw-r--r--README3
-rw-r--r--photon.ino36
-rw-r--r--ring.rb14
3 files changed, 53 insertions, 0 deletions
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 <MQTT.h>
+
+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