aboutsummaryrefslogtreecommitdiff
path: root/photon.ino
blob: da1c5a1cd1006b2b269c620af4035d3dcc000025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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();
}