1
+ /*
2
+ Cayenne Line Chart Widget Example
3
+
4
+ This sketch shows how to set up a Line Chart Widget with Cayenne.
5
+
6
+ Steps:
7
+ 1. In the Cayenne Dashboard add a new Line Chart Custom Widget.
8
+ 3. Select Virtual I/O and a virtual pin number.
9
+ 4. Set VIRTUAL_PIN to the pin number you selected.
10
+ 5. Select a data type and unit, e.g. Temperature, Celsius.
11
+ 6. Attach an analog input device (e.g. a temperature sensor) to your Arduino.
12
+ 7. Set the token variable to match the Arduino token from the Dashboard.
13
+ 8. Modify the CAYENNE_OUT(VIRTUAL_PIN) function to send data from your sensor.
14
+ 8. Compile and upload this sketch.
15
+ 9. Once the Arduino connects to the Dashboard it should automatically update the Line Chart widget with data.
16
+
17
+ For further examples of how to send data to Cayenne see the example sketches under Sensors.
18
+ */
19
+
20
+ #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
21
+ #include < CayenneTemperature.h>
22
+ #include < CayenneEthernet.h> // Change this to use a different communication device. See Communications examples.
23
+
24
+ // Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
25
+ char token[] = " AuthenticationToken" ;
26
+
27
+ // Virtual Pin of the Thermistor widget.
28
+ #define VIRTUAL_PIN V1
29
+
30
+ void setup ()
31
+ {
32
+ Serial.begin (9600 );
33
+ Cayenne.begin (token);
34
+ }
35
+
36
+ void loop ()
37
+ {
38
+ Cayenne.run ();
39
+ }
40
+
41
+ // This function is called when the Cayenne widget requests data for the Virtual Pin.
42
+ CAYENNE_OUT (VIRTUAL_PIN)
43
+ {
44
+ // Read data from the sensor and send it to the virtual channel here.
45
+ // For example, this command writes a temperature in Celsius to the Virtual Pin.
46
+ Cayenne.celsiusWrite (VIRTUAL_PIN, 25.5 );
47
+ // You can also write data using virtualWrite:
48
+ // Cayenne.virtualWrite(VIRTUAL_PIN, 25.5, CELSIUS, TEMPERATURE);
49
+ }
0 commit comments