Hello Guys,
I have a Wemos D1 running on Cayenne and code is below, temperature triggers works just fine, I can get e-mail and SMS alarms when temperatura is above or below, but, the Online/Offline trigger doesnt work, any idea?
// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// WiFi network info.
char ssid = âXXXâ;
char wifiPassword = âXXXâ;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = âXXXâ;
char password = âXXXâ;
char clientID = âXXXXXXâ;
unsigned long lastMillis = 0;
//
// First we include the libraries
#include <OneWire.h>
#include <DallasTemperature.h>
//
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 4
//
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
//
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/********************************************************************/
float temp_0;
float temp_1;
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
Serial.println(âDallas Temperature IC Control Library Demoâ);
// Start up the library
sensors.begin();
}
void loop() {
Cayenne.loop();
//
sensors.requestTemperatures(); // Send the command to get temperature readings
temp_0 = sensors.getTempCByIndex(0);
temp_1 = sensors.getTempCByIndex(1);
//
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 1000) {
lastMillis = millis();
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
Cayenne.virtualWrite(8, temp_0);
Cayenne.virtualWrite(9, temp_1);
//Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}
}
//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(âCAYENNE_IN_DEFAULT(%u) - %s, %sâ, request.channel, getValue.getId(), getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(âError messageâ);
}