Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:iot:relay [2017/09/22 11:47] – created Somepuben:iot:relay [2020/07/20 12:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +<code c>
 +#include <Arduino.h>
 +#include <ittiot.h>
  
 +#define RELAY_PIN 5
 +
 +// If message received switch relay
 +void iot_received(String topic, String msg)
 +{
 +  Serial.print("MSG FROM USER callback, topic: ");
 +  Serial.print(topic);
 +  Serial.print(" payload: ");
 +  Serial.println(msg);
 +  if(msg == "1")
 +  {
 +    digitalWrite(RELAY_PIN, HIGH);
 +  }
 +
 +  if(msg == "0")
 +  {
 +    digitalWrite(RELAY_PIN, LOW);
 +  }
 +}
 +
 +void iot_connected()
 +{
 +  Serial.println("MQTT connected callback");
 +  iot.subscribe("relay");
 +  iot.log("IoT relay example!");
 +}
 +
 +void setup()
 +{
 +  Serial.begin(115200);
 +  Serial.println("Booting");
 +
 +  iot.printConfig(); // print json config to serial //Peale Serial.begin ja enne iot.setup
 +  iot.setup();
 +  pinMode(RELAY_PIN, OUTPUT);
 +}
 +
 +void loop()
 +{
 +  iot.handle();  
 +  delay(200);
 +}
 +
 +</code>
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0