This shows you the differences between two versions of the page.
| en:iot:relay [2017/09/22 11:47] – created Somepub | en:iot:relay [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #define RELAY_PIN 5 | ||
| + | |||
| + | // If message received switch relay | ||
| + | void iot_received(String topic, String msg) | ||
| + | { | ||
| + | Serial.print(" | ||
| + | Serial.print(topic); | ||
| + | Serial.print(" | ||
| + | Serial.println(msg); | ||
| + | if(msg == " | ||
| + | { | ||
| + | digitalWrite(RELAY_PIN, | ||
| + | } | ||
| + | |||
| + | if(msg == " | ||
| + | { | ||
| + | digitalWrite(RELAY_PIN, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void iot_connected() | ||
| + | { | ||
| + | Serial.println(" | ||
| + | iot.subscribe(" | ||
| + | iot.log(" | ||
| + | } | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | Serial.begin(115200); | ||
| + | Serial.println(" | ||
| + | |||
| + | iot.printConfig(); | ||
| + | iot.setup(); | ||
| + | pinMode(RELAY_PIN, | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | iot.handle(); | ||
| + | delay(200); | ||
| + | } | ||
| + | |||
| + | </ | ||