/* This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data. The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager. Steps: 1. Set the Cayenne authentication info to match the authentication info from the Dashboard. 2. Compile and upload the sketch. 3. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget. */ //#define CAYENNE_DEBUG // Uncomment to show debug messages #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include #include int state = LOW; RCSwitch mySwitch = RCSwitch(); // Cayenne authentication info. This should be obtained from the Cayenne Dashboard. char username[] = "MQTT_USERNAME"; char password[] = "MQTT_PASSWORD"; char clientID[] = "CLIENT_ID"; void setup() { Serial.begin(9600); Cayenne.begin(username, password, clientID); mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2 pinMode(7, OUTPUT); } void loop() { Cayenne.loop(); if (mySwitch.available()) { if (mySwitch.getReceivedValue() == 2068824 & state == LOW) { digitalWrite(7, HIGH); state = HIGH; Cayenne.virtualWrite(1, "1"); delay(100); mySwitch.resetAvailable(); } if (mySwitch.getReceivedValue() == 2068824 & state == HIGH) { digitalWrite(7, LOW); state = LOW; Cayenne.virtualWrite(1, "0"); delay(100); mySwitch.resetAvailable(); } } } // Default function for processing actuator commands from the Cayenne Dashboard. // You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands. CAYENNE_IN_DEFAULT() { CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString()); //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message"); if (request.channel = 1) { String value; value = (String)getValue.asString(); if (value == "1") { digitalWrite(7, HIGH); state=HIGH; } else { digitalWrite(7, LOW); state=LOW; } } }