//#define CAYENNE_DEBUG #define CAYENNE_PRINT Serial #include <CayenneMQTTESP8266.h> // WiFi network info. char ssid[] = "nom_de_votre_reseau_wifi"; char wifiPassword[] = "mot_de_passe_du_reseau_wifi"; // Cayenne authentication info. This should be obtained from the Cayenne Dashboard. char username[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; char password[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; char clientID[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; void setup() { Serial.begin(9600); Cayenne.begin(username, password, clientID, ssid, wifiPassword); randomSeed(analogRead(0));//initialise la fonction random pinMode(2, OUTPUT); } void loop() { Cayenne.loop(); } // Default function for sending sensor data at intervals to Cayenne. // You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data. CAYENNE_OUT_DEFAULT() { Cayenne.virtualWrite(0, random(0, 1024)); Cayenne.virtualWrite(1, random(0, 1024)); Cayenne.virtualWrite(2, random(0, 1024)); } // 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"); } CAYENNE_IN(3) { int CV = getValue.asInt(); if (CV == 1) { digitalWrite(2, LOW); } else { digitalWrite(2, HIGH); } } CAYENNE_IN(4) { int TT = getValue.asInt(); if (TT > 50) { Serial.println("channel 4 HIGHT"); } else { Serial.println("channel 4 LOW"); } }