Przy tym projekcie skorzystałem znów ze świetnego kanału ACROBOTIC z YouTube. Wreszcie udało mi się, dzięki witrynie Cayenne , odpalić dwie diody dwoma włącznikami. Nie potrafiłem tego zrobić na Ubidots. Tu funkcja czytająca dane ma jako argument numer kanału, dzięki czemu można podpiąć kilka odbiorników.
CAYENNE_IN(0) { digitalWrite(Pin_D1, !getValue.asInt()); } CAYENNE_IN(1) { digitalWrite(Pin_D2, !getValue.asInt()); }
Biblioteka:
Kod:
// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data. // Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling. // ACROBOTIC https://youtu.be/6YAnqHTm7_o?list=PL7a2CLd93-ftcPc3WMG_6SNRGFjXlHCUb #define CAYENNE_DEBUG #define CAYENNE_PRINT Serial #define Pin_D1 5 #define Pin_D2 4 #include <CayenneMQTTESP8266.h> // Informacje sieci WiFi. char ssid[] = "nazwa"; char password[] = "hasło"; // Autoryzacja Cayenne. Przepisujemy ze strony po zalogowaniu. char username[] = "MQTT Username"; char mqtt_password[] = "MQTT Password"; char client_id[] = "Client ID"; void setup() { Cayenne.begin(username, mqtt_password, client_id, ssid, password); pinMode(Pin_D1, OUTPUT); digitalWrite(Pin_D1, LOW); pinMode(Pin_D2, OUTPUT); digitalWrite(Pin_D2, LOW); } void loop() { Cayenne.loop(); } //Funkcja do pobierania danych z myDevices Cayenne CAYENNE_IN(1) { digitalWrite(Pin_D1, !getValue.asInt()); } CAYENNE_IN(0) { digitalWrite(Pin_D2, !getValue.asInt()); }