Are you looking Maybe for Button State ? Then have a Look on My Projekt.
WeMos D1 Fan Control. I read the GPIO of the Fan And Send the state to Cayenne.
No need for code for monitoring pin state only thing you need is Cayenne.run(); in the loop section.
Since you will be monitoring Digital pin, select desired Digital pin in dropdown (NOT Virtual) in second drop select pin you want to monitor and thats it.
You will see 2 state monitor added to dashboard.
@tett is usinng MQTT connection so he has to add code to show value of two state widget.
void loop() {
Cayenne.loop();
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 10000) {
lastMillis = millis();
x = digitalRead(4);
Cayenne.virtualWrite(1, x, "digital_sensor", "d");
}
}
this will automatically create a two state widget on your dashboard.
Can you point me to good instructional tutorials or reference materials where I can learn about programming arduinos with cayenne? Can’t find much yet with google.
@tett here is a small tutorial:
on your cayenne dashboard first you need to add a device to connect to cayenne. go to add new > devices/widget >bring your own thing and take note of MQTT username, password and clientid.
then add cayenne MQTT library to you arduino ide . then add this code with your MQTT credential :
// 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.
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
unsigned long lastMillis = 0;
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
Serial.println("connected");
}
void loop() {
Cayenne.loop();
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 10000) {
lastMillis = millis();
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
Cayenne.virtualWrite(0, lastMillis);
//Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}
}
upload this code on to your device and this will add value widget automatically to your dashboard.
till now is a basic tutorial to connect to cayenne using MQTT.
next what you want depends on how you code your arduino.