/* ___ ___ ___ _ _ ___ ___ ____ ___ ____ * / _ \ /___)/ _ \| | | |/ _ \ / _ \ / ___) _ \| \ *| |_| |___ | |_| | |_| | |_| | |_| ( (__| |_| | | | | * \___/(___/ \___/ \__ |\___/ \___(_)____)___/|_|_|_| * (____/ *In this sketch, we will show how to use Arduino MQTT wifi shield to exchange data with MQTT broker/clients * when Arduino board gets MQTT message "Hello Arduino!", it will turn on LED in D13 and reply "hi, LED is turned on." * when Arduino board gets MQTT message "Good Bye!", it will turn off LED and reply "Bye! LED is turned off" * Tutorial URL http://osoyoo.com/?p=17438 * CopyRight www.osoyoo.com */ String str; int led_pin=13; void setup() { pinMode(led_pin, OUTPUT); Serial.begin(115200); //115200 is the baud rate UNO board communicate with Wifi Shield } void loop() { str= Serial.readString(); //get message from MQTT if(str.length()>0 && str=="Hello Arduino!") { digitalWrite(led_pin, HIGH); Serial.println("Hi, LED is turned on!"); } if(str.length()>0 && str=="Good Bye!") { digitalWrite(led_pin, LOW); Serial.println("Bye! LED is turned off!"); } }