Skip to content

Commit 7069d86

Browse files
committed
Update connection examples.
1 parent 752e5c6 commit 7069d86

File tree

7 files changed

+195
-129
lines changed

7 files changed

+195
-129
lines changed
Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,48 @@
1-
// This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data.
1+
/*
2+
This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data.
23
3-
//#define CAYENNE_DEBUG
4-
#define CAYENNE_PRINT Serial
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+
12+
//#define CAYENNE_DEBUG // Uncomment to show debug messages
13+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
514
#include <CayenneMQTTEthernet.h>
615

716
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
817
char username[] = "MQTT_USERNAME";
918
char password[] = "MQTT_PASSWORD";
1019
char clientID[] = "CLIENT_ID";
1120

12-
unsigned long lastMillis = 0;
13-
1421
void setup() {
1522
Serial.begin(9600);
1623
Cayenne.begin(username, password, clientID);
1724
}
1825

1926
void loop() {
2027
Cayenne.loop();
28+
}
2129

22-
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
23-
if(millis() - lastMillis > 10000) {
24-
lastMillis = millis();
25-
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
26-
Cayenne.virtualWrite(0, lastMillis);
27-
//Some examples of other functions you can use to send data.
28-
//Cayenne.celsiusWrite(1, 22.0);
29-
//Cayenne.luxWrite(2, 700);
30-
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
31-
}
30+
// Default function for sending sensor data at intervals to Cayenne.
31+
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
32+
CAYENNE_OUT_DEFAULT()
33+
{
34+
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
35+
Cayenne.virtualWrite(0, millis());
36+
// Some examples of other functions you can use to send data.
37+
//Cayenne.celsiusWrite(1, 22.0);
38+
//Cayenne.luxWrite(2, 700);
39+
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
3240
}
3341

34-
//Default function for processing actuator commands from the Cayenne Dashboard.
35-
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
42+
// Default function for processing actuator commands from the Cayenne Dashboard.
43+
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
3644
CAYENNE_IN_DEFAULT()
3745
{
38-
CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
46+
CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
3947
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
4048
}
Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,50 @@
1-
// This example shows how to connect to Cayenne using an Ethernet W5200 shield and send/receive sample data.
1+
/*
2+
This example shows how to connect to Cayenne using an Ethernet W5200 shield and send/receive sample data.
23
3-
//#define CAYENNE_DEBUG
4-
#define CAYENNE_PRINT Serial
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. Download the Ethernet_Shield_W5200 library (https://github.com/Seeed-Studio/Ethernet_Shield_W5200) as a zip file.
8+
2. From the Arduino IDE Include Library menu select Add .ZIP Library and add the downloaded Ethernet_Shield_W5200 zip library.
9+
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
10+
4. Compile and upload the sketch.
11+
5. 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+
14+
//#define CAYENNE_DEBUG // Uncomment to show debug messages
15+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
516
#include <CayenneMQTTEthernetW5200.h>
617

718
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
819
char username[] = "MQTT_USERNAME";
920
char password[] = "MQTT_PASSWORD";
1021
char clientID[] = "CLIENT_ID";
1122

12-
unsigned long lastMillis = 0;
13-
1423
void setup() {
1524
Serial.begin(9600);
1625
Cayenne.begin(username, password, clientID);
1726
}
1827

1928
void loop() {
2029
Cayenne.loop();
30+
}
2131

22-
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
23-
if (millis() - lastMillis > 10000) {
24-
lastMillis = millis();
25-
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
26-
Cayenne.virtualWrite(0, lastMillis);
27-
//Some examples of other functions you can use to send data.
28-
//Cayenne.celsiusWrite(1, 22.0);
29-
//Cayenne.luxWrite(2, 700);
30-
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
31-
}
32+
// Default function for sending sensor data at intervals to Cayenne.
33+
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
34+
CAYENNE_OUT_DEFAULT()
35+
{
36+
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
37+
Cayenne.virtualWrite(0, millis());
38+
// Some examples of other functions you can use to send data.
39+
//Cayenne.celsiusWrite(1, 22.0);
40+
//Cayenne.luxWrite(2, 700);
41+
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
3242
}
3343

34-
//Default function for processing actuator commands from the Cayenne Dashboard.
35-
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
44+
// Default function for processing actuator commands from the Cayenne Dashboard.
45+
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
3646
CAYENNE_IN_DEFAULT()
3747
{
38-
CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
48+
CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
3949
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
40-
}
50+
}
Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,50 @@
1-
// This example shows how to connect to Cayenne using an Ethernet W5500 shield and send/receive sample data.
1+
/*
2+
This example shows how to connect to Cayenne using an Ethernet W5500 shield and send/receive sample data.
23
3-
//#define CAYENNE_DEBUG
4-
#define CAYENNE_PRINT Serial
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. Download the Ethernet2 library (https://github.com/adafruit/Ethernet2) as a zip file.
8+
2. From the Arduino IDE Include Library menu select Add .ZIP Library and add the downloaded Ethernet2 zip library.
9+
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
10+
4. Compile and upload the sketch.
11+
5. 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+
14+
//#define CAYENNE_DEBUG // Uncomment to show debug messages
15+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
516
#include <CayenneMQTTEthernetW5500.h>
617

718
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
819
char username[] = "MQTT_USERNAME";
920
char password[] = "MQTT_PASSWORD";
1021
char clientID[] = "CLIENT_ID";
1122

12-
unsigned long lastMillis = 0;
13-
1423
void setup() {
1524
Serial.begin(9600);
1625
Cayenne.begin(username, password, clientID);
1726
}
1827

1928
void loop() {
2029
Cayenne.loop();
30+
}
2131

22-
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
23-
if (millis() - lastMillis > 10000) {
24-
lastMillis = millis();
25-
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
26-
Cayenne.virtualWrite(0, lastMillis);
27-
//Some examples of other functions you can use to send data.
28-
//Cayenne.celsiusWrite(1, 22.0);
29-
//Cayenne.luxWrite(2, 700);
30-
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
31-
}
32+
// Default function for sending sensor data at intervals to Cayenne.
33+
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
34+
CAYENNE_OUT_DEFAULT()
35+
{
36+
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
37+
Cayenne.virtualWrite(0, millis());
38+
// Some examples of other functions you can use to send data.
39+
//Cayenne.celsiusWrite(1, 22.0);
40+
//Cayenne.luxWrite(2, 700);
41+
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
3242
}
3343

34-
//Default function for processing actuator commands from the Cayenne Dashboard.
35-
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
44+
// Default function for processing actuator commands from the Cayenne Dashboard.
45+
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
3646
CAYENNE_IN_DEFAULT()
3747
{
38-
CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
48+
CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
3949
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
40-
}
50+
}
Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
// This example shows how to connect to Cayenne using an Arduino/Genuino MKR1000 and send/receive sample data.
2-
3-
//#define CAYENNE_DEBUG
4-
#define CAYENNE_PRINT Serial
1+
/*
2+
This example shows how to connect to Cayenne using an Arduino/Genuino MKR1000 and send/receive sample data.
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. Install the Arduino SAMD Boards from the Arduino IDE Boards Manager if you have not already done so.
8+
2. Select the MKR1000 board from the Arduino IDE Tools menu.
9+
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
10+
4. Set the network name and password.
11+
5. Compile and upload the sketch.
12+
6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
13+
*/
14+
15+
//#define CAYENNE_DEBUG // Uncomment to show debug messages
16+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
517
#include <CayenneMQTTMKR1000.h>
618

719
// WiFi network info.
@@ -13,32 +25,31 @@ char username[] = "MQTT_USERNAME";
1325
char password[] = "MQTT_PASSWORD";
1426
char clientID[] = "CLIENT_ID";
1527

16-
unsigned long lastMillis = 0;
17-
1828
void setup() {
1929
Serial.begin(9600);
2030
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
2131
}
2232

2333
void loop() {
2434
Cayenne.loop();
35+
}
2536

26-
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
27-
if (millis() - lastMillis > 10000) {
28-
lastMillis = millis();
29-
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
30-
Cayenne.virtualWrite(0, lastMillis);
31-
//Some examples of other functions you can use to send data.
32-
//Cayenne.celsiusWrite(1, 22.0);
33-
//Cayenne.luxWrite(2, 700);
34-
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
35-
}
37+
// Default function for sending sensor data at intervals to Cayenne.
38+
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
39+
CAYENNE_OUT_DEFAULT()
40+
{
41+
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
42+
Cayenne.virtualWrite(0, millis());
43+
// Some examples of other functions you can use to send data.
44+
//Cayenne.celsiusWrite(1, 22.0);
45+
//Cayenne.luxWrite(2, 700);
46+
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
3647
}
3748

38-
//Default function for processing actuator commands from the Cayenne Dashboard.
39-
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
49+
// Default function for processing actuator commands from the Cayenne Dashboard.
50+
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
4051
CAYENNE_IN_DEFAULT()
4152
{
42-
CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
53+
CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
4354
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
4455
}
Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
// This example shows how to connect to Cayenne using a manually specified Ethernet connection and send/receive sample data.
1+
/*
2+
This example shows how to connect to Cayenne using a manually specified Ethernet connection and send/receive sample data.
23
3-
//#define CAYENNE_DEBUG
4-
#define CAYENNE_PRINT Serial
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+
12+
//#define CAYENNE_DEBUG // Uncomment to show debug messages
13+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
514
#include <CayenneMQTTEthernet.h>
615
//#include <CayenneMQTTEthernetW5500.h> // Uncomment this and comment out CayenneMQTTEthernet.h to use an Ethernet 2 shield or other Ethernet W5500 shield.
716
// You will need the Ethernet2 library installed. See the ArduinoEthernetW5500 example sketch for more info.
@@ -20,32 +29,31 @@ IPAddress dns_ip(8, 8, 8, 8);
2029
IPAddress gateway_ip(10, 0, 0, 1);
2130
IPAddress subnet_mask(255, 255, 255, 0);
2231

23-
unsigned long lastMillis = 0;
24-
2532
void setup() {
2633
Serial.begin(9600);
2734
Cayenne.begin(username, password, clientID, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
2835
}
2936

3037
void loop() {
3138
Cayenne.loop();
39+
}
3240

33-
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
34-
if (millis() - lastMillis > 10000) {
35-
lastMillis = millis();
36-
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
37-
Cayenne.virtualWrite(0, lastMillis);
38-
//Some examples of other functions you can use to send data.
39-
//Cayenne.celsiusWrite(1, 22.0);
40-
//Cayenne.luxWrite(2, 700);
41-
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
42-
}
41+
// Default function for sending sensor data at intervals to Cayenne.
42+
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
43+
CAYENNE_OUT_DEFAULT()
44+
{
45+
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
46+
Cayenne.virtualWrite(0, millis());
47+
// Some examples of other functions you can use to send data.
48+
//Cayenne.celsiusWrite(1, 22.0);
49+
//Cayenne.luxWrite(2, 700);
50+
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
4351
}
4452

45-
//Default function for processing actuator commands from the Cayenne Dashboard.
46-
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
53+
// Default function for processing actuator commands from the Cayenne Dashboard.
54+
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
4755
CAYENNE_IN_DEFAULT()
4856
{
49-
CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
57+
CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
5058
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
5159
}

0 commit comments

Comments
 (0)