I’m using Agent 2.0 on a raspberry pi with a number of two state sensors. I have set up each sensor with a trigger to send an email when the sensor changes state.
I have named each sensor differently (and it appears as such in the sensor list) and named each trigger differently.
However:
The email text received quotes the channel id rather than the trigger / sensor name - so the email text states:
Channel dev:9orzwCD1sEGvtyr is turned on
Which makes it hard to figure out which channel is which sensor.
How do I amend the email text to provide the sensor effect rather than the channel?
ok thanks. As I’m sure you are aware the original alerts quoted the trigger name (not the channel).
As another comment, the original also quoted the sensor name in the GPIO screen alongside the pin - making it really clear which pins are being used for which sensors. This seems to have gone from this release.
Anyways - it’s still a great piece of work that you should all be very proud. Thanks
Just wondering if there is some code that we can write directly into the micro controller that can send a notification. I.e something like Cayenne.sendtext()
then we could make use of the text message sending ability, and just code it ourselves?
Also any chance you may be able to help me with a coding problem/question? Im trying to build some code that will send notifications at certain temps, which at the moment is working, but i want to clean it up before i upload it for everyone to view.
the issue is actually to do with local and global variables, and for some reason i can’t get my global variables to work for all functions, and so im finding myself having to list my variables in nearly all of my individual functions.
can i just post the code here, or should i start a new topic asking for help?
Thanks this is the code below. as explained above, i can only get the ‘h’ and ‘t’ variables to apply globally to one of my functions (sendnotification). The other function has to have them declared inside it?
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include "DHT.h"
#define DHTPIN D4 // what digital pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
char ssid[] = "xxx";
char wifiPassword[] = "xxx";
char username[] = "xxx";
char password[] = "xxx;
char clientID[] = "xxx";
#include <SimpleTimer.h>
SimpleTimer timer;
unsigned long lastMillis = 0;
boolean HighTempFlag =0;
boolean LowTempFlag =0;
float h = dht.readHumidity();
float t = dht.readTemperature();
unsigned long HighTempMillis = 0;
unsigned long LowTempMillis = 0;
void setup() {
Serial.begin(9600);
Serial.println (" **** ESP8266 MINI TRIAL TRIGGER WITH FLAG func split *****");
dht.begin();
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
timer.setInterval(2000L, sendUpTimeAndSensorData);
timer.setInterval(10000L, sendNotification);
}
void sendNotification(){
//float t = dht.readTemperature();
int notificationReset = 60000;
unsigned long currentMillis = millis();
if(t >= 22.5 && HighTempFlag == 0 ){
Cayenne.virtualWrite(3,HIGH);
HighTempFlag = 1;
Serial.println("High Temp Flag set to channel 3");
HighTempMillis = currentMillis;
}
else { Cayenne.virtualWrite(3,LOW);
}
if (t <= 21.0 && LowTempFlag == 0){
Cayenne.virtualWrite(4,HIGH);
LowTempFlag = 1;
Serial.println(currentMillis);
Serial.println(LowTempMillis);
Serial.println("Low Temp Flag set to channel 4");
LowTempMillis = currentMillis;
Serial.println(currentMillis);
Serial.println(LowTempMillis);
}
else {Cayenne.virtualWrite(4,LOW);
}
if (HighTempFlag == 1 && currentMillis - HighTempMillis >= notificationReset){
HighTempFlag = 0;
Serial.println("High temp notification reset");
}
if (LowTempFlag == 1 && currentMillis - LowTempMillis >= notificationReset){
LowTempFlag = 0;
Serial.println("Low temp notification reset");
Serial.println(LowTempMillis);
Serial.println(currentMillis);
Serial.print(millis());
}
}
void sendUpTimeAndSensorData(){
float h = dht.readHumidity();
float t = dht.readTemperature();
Cayenne.celsiusWrite(1, t);
Cayenne.virtualWrite(2, h, "Humidity", "%");
Cayenne.virtualWrite(0, millis());
Serial.print(h);
Serial.print("H");
Serial.print(" ");
Serial.print(t);
Serial.print("C");
Serial.println("\r");
Serial.println(millis());
}
void loop() {
Cayenne.loop();
timer.run();
}
Hi thanks very much! I don’t fully understand how my function ‘sendNotification’ doesn’t need to have the ‘dht.readHumidity/temperature()’ functions declared in it, when they aren’t declared as a global variable?
Im still pretty new to coding, so thanks for your time on this.
dht.readHumidity/temperature() is the function which is called to get the humidtiy and temperarure. this returrn the value and is store in h and t variables in sendUpTimeAndSensorData(). this value is then used in sendNotification() to do whatever you want.