Skip to content

Commit e3f38d7

Browse files
committed
Update basic example sketches.
1 parent 7069d86 commit e3f38d7

File tree

4 files changed

+65
-71
lines changed

4 files changed

+65
-71
lines changed

examples/Basics/ReceiveData/ReceiveData.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/*
2-
Cayenne ReceiveData Example
3-
42
This example sketch shows how a value can be sent from the Cayenne Dashboard to the Arduino on a Virtual Channel.
53
64
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.
Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,40 @@
11
/*
2-
Cayenne SendData Example
3-
4-
This example sketch shows how a value can be sent from Arduino to the Cayenne Dashboard on a Virtual Channel.
2+
This example sketch shows how a value can be sent from the Arduino to the Cayenne Dashboard at automatic intervals.
53
64
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.
75
86
Steps:
97
1. Set the Cayenne authentication info to match the authentication info from the Dashboard.
108
2. Compile and upload the sketch.
119
3. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
12-
13-
NOTE:
14-
For this example you'll need SimpleTimer library:
15-
https://github.com/jfturcot/SimpleTimer
16-
Visit this page for more information:
17-
http://playground.arduino.cc/Code/SimpleTimer
1810
*/
1911

20-
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
21-
#include <CayenneMQTTEthernet.h> // Change this to use a different communication device. See Communications examples.
22-
#include <SimpleTimer.h>
12+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
13+
#include <CayenneMQTTEthernet.h> // Change this to use a different communication device. See Communications examples.
2314

2415
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
2516
char username[] = "MQTT_USERNAME";
2617
char password[] = "MQTT_PASSWORD";
2718
char clientID[] = "CLIENT_ID";
2819

29-
SimpleTimer timer;
30-
31-
// This function sends Arduino's up time to Virtual Channel 5.
32-
void sendUptime()
33-
{
34-
// Send values using the virtualWrite function. Cayenne currently accepts int and float values.
35-
// Please don't send more that 10 values per second.
36-
Cayenne.virtualWrite(5, millis() / 1000);
37-
}
20+
// Use Virtual Channel 5 for uptime display.
21+
#define VIRTUAL_CHANNEL 5
3822

3923
void setup()
4024
{
41-
Serial.begin(9600); // See the connection status in Serial Monitor
25+
Serial.begin(9600);
4226
Cayenne.begin(username, password, clientID);
43-
44-
// Set up a function to be called every 5 seconds
45-
timer.setInterval(5000L, sendUptime);
4627
}
4728

4829
void loop()
4930
{
50-
Cayenne.loop(); // Runs main loop
51-
timer.run(); // Initiates SimpleTimer
31+
Cayenne.loop();
5232
}
5333

34+
// This function is called at intervals to send data to Cayenne.
35+
CAYENNE_OUT(VIRTUAL_CHANNEL)
36+
{
37+
CAYENNE_LOG("Send data for Virtual Channel %d", VIRTUAL_CHANNEL);
38+
// This command writes the device's uptime in seconds to the Virtual Channel.
39+
Cayenne.virtualWrite(VIRTUAL_CHANNEL, millis() / 1000);
40+
}

examples/Basics/SendDataOnRequest/SendDataOnRequest.ino

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
This example sketch shows how a value can be sent from the Arduino to the Cayenne Dashboard at specified intervals.
3+
4+
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.
5+
6+
Steps:
7+
1. Set the Cayenne authentication info to match the authentication info from the Dashboard.
8+
2. Compile and upload the sketch.
9+
3. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
10+
11+
NOTE:
12+
For this example you'll need SimpleTimer library:
13+
https://github.com/jfturcot/SimpleTimer
14+
Visit this page for more information:
15+
http://playground.arduino.cc/Code/SimpleTimer
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+
#include <SimpleTimer.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+
SimpleTimer timer;
28+
29+
// This function sends the device's uptime to Cayenne on Virtual Channel 5.
30+
void sendUptime()
31+
{
32+
// Send values using the virtualWrite function. Cayenne currently accepts int and float values.
33+
// Please don't send more that 10 values per second.
34+
Cayenne.virtualWrite(5, millis() / 1000);
35+
}
36+
37+
void setup()
38+
{
39+
Serial.begin(9600); // See the connection status in Serial Monitor
40+
Cayenne.begin(username, password, clientID);
41+
42+
// Set up a function to be called every 5 seconds
43+
timer.setInterval(5000L, sendUptime);
44+
}
45+
46+
void loop()
47+
{
48+
Cayenne.loop(); // Runs main loop
49+
timer.run(); // Initiates SimpleTimer
50+
}
51+

0 commit comments

Comments
 (0)