diff options
-rw-r--r-- | README | 3 | ||||
-rw-r--r-- | photon.ino | 36 | ||||
-rw-r--r-- | ring.rb | 14 |
3 files changed, 53 insertions, 0 deletions
@@ -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(); +} @@ -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 |