Hi Shramik & all,
I’m trying to add a resend of the trigger notification every hour as a reminder. Thought just by resetting the widget back to 0 would do it. Everything works but the reset. Is there a better way? Any pointers?
Thanks,
John
/*
This example is to be used when using Cayenne triggers.
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:
- Set the trigger and threshold values in the sketch below.
- Set the Cayenne authentication info to match the authentication info from the Dashboard.
- Compile and upload the sketch.
- Two temporary widget (DATA_CHANNEL and TRIGGER_CHANNEL) will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
- Add trigger on your cayenne dashboard for the TRIGGER_CHANNEL widget when it becomes 1.
*/
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneMQTTESP8266.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tempSensorA = { 0x28, 0xFF, 0x09, 0x61, 0x51, 0x17, 0x04, 0x97};
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char ssid = “__”;
char wifiPassword = “00”;
char username = “000000000000”;
char password = “0000000000”;
char clientID = “000000000”;
#define DATA_CHANNEL 0 //Virtual channel for publishing sensor data.
#define TRIGGER_CHANNEL 1 //Virtual channel for publishing the trigger value.
#define THRESHOLD 75 //Threshold for the trigger.
unsigned long lastMillis = 0;
bool sendBelowThreshold = false; ///// Set to true if the trigger should happen when the data value is below the threshold,
///// false if it should happen when the data value is above or equal to the threshold.
bool crossedThreshold = false;
int previousState1 = -1;
int currentState1 = -1;
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID);
sensors.setResolution(tempSensorA, 10);
sensors.begin();
}
void sendTriggerValue(int channel, int value, int threshold, bool sendBelowThreshold) {
if (((value >= threshold) && !sendBelowThreshold) || ((value < threshold) && sendBelowThreshold)) {
if (!crossedThreshold) {
Cayenne.virtualWrite(channel, 1, “digital_sensor”, “d”); //set trigger two-state widget to 1
crossedThreshold = true;
}
}
else
{
Cayenne.virtualWrite(channel, 0, “digital_sensor”, “d”); //set trigger two-state widget to 0
crossedThreshold = false;
}
}
void loop() {
Cayenne.loop();
//Publish data every 5 minutes (300000 milliseconds).
if (millis() - lastMillis > 60000)
{
lastMillis = millis();
sensors.requestTemperatures();
int sensor_value1 = sensors.getTempF(tempSensorA);
sendTriggerValue(TRIGGER_CHANNEL, sensor_value1, THRESHOLD, sendBelowThreshold);
Cayenne.virtualWrite(DATA_CHANNEL, sensor_value1 , “temp”, “f”);
long rssi = WiFi.RSSI();
Cayenne.virtualWrite(3, rssi, "rssi", "dbm");
}
// Problem here>>>>>>>
// Reset trigger every 1 hour (3600000 milliseconds).
if (millis() - lastMillis > 120000)
{
lastMillis = millis();
Cayenne.virtualWrite(1, 0, "digital_sensor", "d"); //set trigger two-state widget to 0
}
}