/
GenericAnalogInput.ino
44 lines (35 loc) · 1.69 KB
/
GenericAnalogInput.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
Cayenne Generic Analog Input Example
This sketch shows how to send Generic Analog Input Sensor data to the Cayenne Dashboard.
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.
Steps:
1. Attach an analog input device (e.g. a potentiometer) to an analog pin on your Arduino. Make sure to use an analog pin, not a digital pin.
2. Set the SENSOR_PIN value below to the pin number you used when connecting the sensor.
3. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of an Generic Analog Input Sensor widget you have added) in the Dashboard.
4. Set the Cayenne authentication info to match the authentication info from the Dashboard.
5. Compile and upload this sketch.
6. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the Generic Analog Input Sensor widget you have added) with data.
To make a temporary widget permanent click the plus sign on the widget.
*/
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";
#define SENSOR_PIN 0
#define VIRTUAL_CHANNEL 1
void setup()
{
Serial.begin(9600);
Cayenne.begin(username, password, clientID);
}
void loop()
{
Cayenne.loop();
}
// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL, analogRead(SENSOR_PIN), "analog_sensor", "null");
}