Skip to content

Commit 97fc5e5

Browse files
committed
Add custom widget examples.
1 parent db41304 commit 97fc5e5

File tree

6 files changed

+283
-0
lines changed

6 files changed

+283
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Cayenne Button Widget Example
3+
4+
This sketch shows how to set up a Button Widget with Cayenne.
5+
6+
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.
7+
8+
Steps:
9+
1. In the Cayenne Dashboard add a new Button Custom Widget.
10+
2. Select a virtual channel number for the widget.
11+
3. Set the VIRTUAL_CHANNEL value below to virtual channel you selected.
12+
4. Attach an output actuator (e.g. an LED) to a digital pin on your Arduino.
13+
5. Set the ACTUATOR_PIN value below to the pin number you used when connecting your output actuator.
14+
6. Set the Cayenne authentication info to match the authentication info from the Dashboard.
15+
7. Compile and upload this sketch.
16+
8. Once the Arduino connects to the Dashboard you can use the widget button to send digital values.
17+
*/
18+
19+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
20+
#include <CayenneMQTTEthernet.h>
21+
22+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
23+
char username[] = "MQTT_USERNAME";
24+
char password[] = "MQTT_PASSWORD";
25+
char clientID[] = "CLIENT_ID";
26+
27+
#define VIRTUAL_CHANNEL 1
28+
#define ACTUATOR_PIN 4 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
29+
30+
void setup()
31+
{
32+
Serial.begin(9600);
33+
pinMode(ACTUATOR_PIN, OUTPUT);
34+
Cayenne.begin(username, password, clientID);
35+
}
36+
37+
void loop()
38+
{
39+
Cayenne.loop();
40+
}
41+
42+
// This function is called when data is sent from Cayenne.
43+
CAYENNE_IN(VIRTUAL_CHANNEL)
44+
{
45+
int value = getValue.asInt();
46+
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
47+
// Write the value received to the digital pin.
48+
digitalWrite(ACTUATOR_PIN, value);
49+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Cayenne Gauge Widget Example
3+
4+
This sketch shows how to set up a Gauge Custom Widget with Cayenne.
5+
6+
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.
7+
8+
Steps:
9+
1. Attach an analog input device (e.g. a temperature sensor) to your Arduino.
10+
2. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of a Gauge Custom Widget you have added) in the Dashboard.
11+
3. Update the CAYENNE_OUT function below to send the data from your sensor.
12+
4. Set the Cayenne authentication info to match the authentication info from the Dashboard.
13+
5. Compile and upload this sketch.
14+
6. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the Gauge widget you have added) with data.
15+
To make a temporary widget permanent click the plus sign on the widget. Use the settings gear icon to change between Value, Gauge and Line Chart widgets.
16+
*/
17+
18+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
19+
#include <CayenneMQTTEthernet.h> // Change this to use a different communication device. See Communications examples.
20+
21+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
22+
char username[] = "MQTT_USERNAME";
23+
char password[] = "MQTT_PASSWORD";
24+
char clientID[] = "CLIENT_ID";
25+
26+
#define VIRTUAL_CHANNEL 1
27+
28+
void setup()
29+
{
30+
Serial.begin(9600);
31+
Cayenne.begin(username, password, clientID);
32+
}
33+
34+
void loop()
35+
{
36+
Cayenne.loop();
37+
}
38+
39+
// This function is called at intervals to send sensor data to Cayenne.
40+
CAYENNE_OUT(VIRTUAL_CHANNEL)
41+
{
42+
// Read data from the sensor and send it to the virtual channel here.
43+
// You can write data using virtualWrite or other Cayenne write functions.
44+
// For example, to send a temperature in Celsius you can use the following:
45+
// Cayenne.virtualWrite(VIRTUAL_CHANNEL, 25.5, TYPE_TEMPERATURE, UNIT_CELSIUS);
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Cayenne Line Chart Widget Example
3+
4+
This sketch shows how to set up a Line Chart Custom Widget with Cayenne.
5+
6+
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.
7+
8+
Steps:
9+
1. Attach an analog input device (e.g. a temperature sensor) to your Arduino.
10+
2. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of a Line Chart Custom Widget you have added) in the Dashboard.
11+
3. Update the CAYENNE_OUT function below to send the data from your sensor.
12+
4. Set the Cayenne authentication info to match the authentication info from the Dashboard.
13+
5. Compile and upload this sketch.
14+
6. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the Line Chart widget you have added) with data.
15+
To make a temporary widget permanent click the plus sign on the widget. Use the settings gear icon to change between Value, Gauge and Line Chart widgets.
16+
*/
17+
18+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
19+
#include <CayenneMQTTEthernet.h> // Change this to use a different communication device. See Communications examples.
20+
21+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
22+
char username[] = "MQTT_USERNAME";
23+
char password[] = "MQTT_PASSWORD";
24+
char clientID[] = "CLIENT_ID";
25+
26+
#define VIRTUAL_CHANNEL 1
27+
28+
void setup()
29+
{
30+
Serial.begin(9600);
31+
Cayenne.begin(username, password, clientID);
32+
}
33+
34+
void loop()
35+
{
36+
Cayenne.loop();
37+
}
38+
39+
// This function is called at intervals to send sensor data to Cayenne.
40+
CAYENNE_OUT(VIRTUAL_CHANNEL)
41+
{
42+
// Read data from the sensor and send it to the virtual channel here.
43+
// You can write data using virtualWrite or other Cayenne write functions.
44+
// For example, to send a temperature in Celsius you can use the following:
45+
// Cayenne.virtualWrite(VIRTUAL_CHANNEL, 25.5, TYPE_TEMPERATURE, UNIT_CELSIUS);
46+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Cayenne Slider Widget Example
3+
4+
This sketch shows how to set up a Slider Widget with Cayenne.
5+
6+
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.
7+
8+
Steps:
9+
1. In the Cayenne Dashboard add a new Slider Custom Widget.
10+
2. Select a virtual channel number.
11+
3. Set the slider widget min value to 0 and max value to 255.
12+
4. Set VIRTUAL_CHANNEL to the virtual channel number you selected.
13+
5. Attach an output device to a digital PWM pin (3, 5, 6, 9, 10, and 11 on most Arduino boards).
14+
6. Set ACTUATOR_PIN to the digital PWM pin number you selected.
15+
7. Set the Cayenne authentication info to match the authentication info from the Dashboard.
16+
8. Compile and upload this sketch.
17+
9. Once the Arduino connects to the Dashboard you can use the slider to change PWM values.
18+
*/
19+
20+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
21+
#include <CayenneMQTTEthernet.h>
22+
23+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
24+
char username[] = "MQTT_USERNAME";
25+
char password[] = "MQTT_PASSWORD";
26+
char clientID[] = "CLIENT_ID";
27+
28+
#define VIRTUAL_CHANNEL 1
29+
#define ACTUATOR_PIN 3
30+
31+
void setup()
32+
{
33+
Serial.begin(9600);
34+
Cayenne.begin(username, password, clientID);
35+
}
36+
37+
void loop()
38+
{
39+
Cayenne.loop();
40+
}
41+
42+
// This function is called when data is sent from Cayenne.
43+
CAYENNE_IN(VIRTUAL_CHANNEL)
44+
{
45+
int value = getValue.asInt(); // 0 to 255
46+
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
47+
// Write the value received to the PWM pin. analogWrite accepts a value from 0 to 255.
48+
analogWrite(ACTUATOR_PIN, value);
49+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Cayenne 2 State Widget Example
3+
4+
This sketch shows how to set up a 2 State Custom Widget with Cayenne.
5+
6+
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.
7+
8+
Steps:
9+
1. Attach a digital input device (e.g. a button) to a digital pin on your Arduino.
10+
2. Set the SENSOR_PIN value below to the pin number you used when connecting the sensor.
11+
3. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of a 2 State Custom Widget you have added) in the Dashboard.
12+
4. Set the Cayenne authentication info to match the authentication info from the Dashboard.
13+
5. Compile and upload this sketch.
14+
6. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the 2 State widget you have added) with data.
15+
To make a temporary widget permanent click the plus sign on the widget.
16+
*/
17+
18+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
19+
#include <CayenneMQTTEthernet.h>
20+
21+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
22+
char username[] = "MQTT_USERNAME";
23+
char password[] = "MQTT_PASSWORD";
24+
char clientID[] = "CLIENT_ID";
25+
26+
#define VIRTUAL_CHANNEL 1
27+
#define SENSOR_PIN 0
28+
29+
void setup()
30+
{
31+
Serial.begin(9600);
32+
Cayenne.begin(username, password, clientID);
33+
}
34+
35+
void loop()
36+
{
37+
Cayenne.loop();
38+
}
39+
40+
// This function is called at intervals to send sensor data to Cayenne.
41+
CAYENNE_OUT(VIRTUAL_CHANNEL)
42+
{
43+
// Read data from the sensor and send it to the virtual channel here.
44+
// For example, to send a digital value you can use the following:
45+
int value = digitalRead(SENSOR_PIN);
46+
Cayenne.virtualWrite(VIRTUAL_CHANNEL, value, TYPE_DIGITAL_SENSOR, UNIT_DIGITAL);
47+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Cayenne Value Widget Example
3+
4+
This sketch shows how to set up a Value Custom Widget with Cayenne.
5+
6+
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.
7+
8+
Steps:
9+
1. Attach an analog input device (e.g. a temperature sensor) to your Arduino.
10+
2. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of a Value Custom Widget you have added) in the Dashboard.
11+
3. Update the CAYENNE_OUT function below to send the data from your sensor.
12+
4. Set the Cayenne authentication info to match the authentication info from the Dashboard.
13+
5. Compile and upload this sketch.
14+
6. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the Value widget you have added) with data.
15+
To make a temporary widget permanent click the plus sign on the widget. Use the settings gear icon to change between Value, Gauge and Line Chart widgets.
16+
*/
17+
18+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
19+
#include <CayenneMQTTEthernet.h> // Change this to use a different communication device. See Communications examples.
20+
21+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
22+
char username[] = "MQTT_USERNAME";
23+
char password[] = "MQTT_PASSWORD";
24+
char clientID[] = "CLIENT_ID";
25+
26+
#define VIRTUAL_CHANNEL 1
27+
28+
void setup()
29+
{
30+
Serial.begin(9600);
31+
Cayenne.begin(username, password, clientID);
32+
}
33+
34+
void loop()
35+
{
36+
Cayenne.loop();
37+
}
38+
39+
// This function is called at intervals to send sensor data to Cayenne.
40+
CAYENNE_OUT(VIRTUAL_CHANNEL)
41+
{
42+
// Read data from the sensor and send it to the virtual channel here.
43+
// You can write data using virtualWrite or other Cayenne write functions.
44+
// For example, to send a temperature in Celsius you can use the following:
45+
// Cayenne.virtualWrite(VIRTUAL_CHANNEL, 25.5, TYPE_TEMPERATURE, UNIT_CELSIUS);
46+
}

0 commit comments

Comments
 (0)