Advertisement
arekem

Untitled

Feb 2nd, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
  2. #include <OneWire.h>
  3. #include <DallasTemperature.h>
  4. #include <CayenneMQTTEthernet.h>
  5.  
  6. // Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
  7. char username[] = "";
  8. char password[] = "";
  9. char clientID[] = "";
  10.  
  11. #define SENSOR_PIN 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
  12.  
  13. OneWire oneWire(SENSOR_PIN);
  14. DallasTemperature sensors(&oneWire);
  15.  
  16. void setup()
  17. {
  18.   Serial.begin(9600);
  19.   Cayenne.begin(username, password, clientID);
  20.   sensors.begin();
  21. }
  22.  
  23. void loop()
  24. {
  25.   Cayenne.loop();
  26. }
  27.  
  28. // This function is called at intervals to send sensor data to Cayenne.
  29. CAYENNE_OUT_DEFAULT()
  30. {
  31.   // Send the command to get temperatures.
  32.   sensors.requestTemperatures();
  33.   // This command writes the temperature in Celsius to the Virtual Channel.
  34.   Cayenne.celsiusWrite(0, sensors.getTempCByIndex(0));
  35.   Cayenne.celsiusWrite(1, sensors.getTempCByIndex(1));
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement