diff options
author | Nat Lasseter <Redacted> | 2017-07-27 16:44:56 +0100 |
---|---|---|
committer | Nat Lasseter <Redacted> | 2017-07-27 16:44:56 +0100 |
commit | f7993b536d01957e5e9cfc91af01617d7e48704c (patch) | |
tree | 4df98738c1d7ac687f2deb29cbc9c7a6bb6fe321 /photon.ino |
Initial commit
Diffstat (limited to 'photon.ino')
-rw-r--r-- | photon.ino | 36 |
1 files changed, 36 insertions, 0 deletions
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(); +} |