#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);
}
en/iot/relay.txt · Last modified: 2020/07/20 09:00 by 127.0.0.1
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