This is an old revision of the document!
Coming soon
The following is the code for the controller with relay module. Required libraries:
lib_deps = ITTIoT
/* * Ventilator example - relay shield program * * This program is for the controller with relay shield. It is meant to work together with * the Ventilator - DHT shield program. * The controller subscribes to topics "temp" and "conf". The "temp" topic is meant for temperature data. * If the received temperature is higher then tempLimit (default 28 degrees) it will switch on the relay. * If the temperature goes under the limit again, the relay is switched off. * For changing the tempLimit, send new limit to topic "conf" (for example: "26.3"). * * Author: Rim Puks * May 2018 */ #include <Arduino.h> #include <ittiot.h> #define RELAY_PIN 5 float t; //for holding the received float value float tempLimit = 28; //the temperature limit on what the relay will switch void iot_received(String topic, String msg) { Serial.print("MSG FROM USER callback, topic: "); Serial.print(topic); Serial.print(" payload: "); Serial.println(msg); t=msg.toFloat(); if(topic=="DHT/conf") { tempLimit=t; //re-configures the limit temperature } if(topic=="DHT/temp") { if(t >= tempLimit) { digitalWrite(RELAY_PIN, HIGH); } else { digitalWrite(RELAY_PIN, LOW); } } } void iot_connected() { Serial.println("MQTT connected callback"); iot.subscribe("temp"); iot.subscribe("conf"); iot.log("Ventilator 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); }
The following is the program code for the controller with DHT module. Required libraries: