Hi Thanks for pointing me to this from my question. This looks something similar to what i was doing with blynk, i.e setting flags and so i understand how something like this works from a code level. However don’t completely understand how this code actually activates a trigger. As far as i can tell if the codes trigger value is true then it VirtualWrites to channel 3? but that seems to be another sensor value? Would this code work if you did a virtualWrite to a custom widget that would just ‘show its on/off state’ thereby sending 1 notification?
thanks for your time
ok. and what about my questions regarding your code? ‘’ However don’t completely understand how this code actually activates a trigger. As far as i can tell if the codes trigger value is true then it VirtualWrites to channel 3? but that seems to be another sensor value? ‘’
sorry just trying to understand why your doing it that way. Im new to coding…
you have to set the trigger value. eg if humidity is less than 35;
int trigger 35= ;// you need to set this value
I have two functions which are called from the main loop.
send_data();
trigger();
this function sends data to channel 2 if humidity is greater than the trigger and set a = 1;
void send_data()
{
if (HumiditeTerre > trigger)
{
a = 1;
if (millis() - lastMillis > 10000) {
lastMillis = millis();
Cayenne.virtualWrite(1, HumiditeTerre, "soil_moist", "p");
}
}
}
this function sends data to channel 2 when humidity is less than the trigger and also send data to channel 3 and sets a =0. so till humidity does not rise higher than the trigger, it won’t send data to channel 3.
void trigger()
{
if (HumiditeTerre <= trigger)
{
if (millis() - lastMillis > 10000)
{
lastMillis = millis();
Cayenne.virtualWrite(1, HumiditeTerre, "soil_moist", "p");
}
if ( a == 1)
{
Serial.println("Sending trigger");
Cayenne.virtualWrite(3, HumiditeTerre, "soil_moist", "p");
a = 0;
}
}
}
Now that you have sent data to channel 3 only once, you set a trigger on the cayenne dashboard to channel 3. this will avoid the trigger flooding issue.
this is the best i can explain the code working , i hope it helps you out. revert back if any problem.
can u explain reed swicth to this clever code like this … i want use esp8266 or arduino to use reed sensor … i use some basiccode to display 2 state on dash board… its give me too many sms alert … n some time its stop sms to me … pls share the reed exmple like this… thanks
int previousState = -1;
int currentState = -1;
unsigned long previousMillis = 0;
void checkSensor()
{
unsigned long currentMillis = millis();
// Check sensor data every 250 milliseconds
if (currentMillis - previousMillis >= 250) {
// Check the sensor state and send data when it changes.
currentState = digitalRead(SENSOR_PIN);
if (currentState != previousState) {
Serial.println("changed");
Cayenne.virtualWrite(VIRTUAL_CHANNEL, currentState, "digital_sensor", "d");
previousState = currentState;
}
previousMillis = currentMillis;
}
}
ur provided code not work for me … here i create new code but its still sms a lot … i need 1 single sms when door is open …this is my Code
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include <CayenneMQTTESP8266.h> #define CAYENNE_DEBUG
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = " ";
char password = " ";
char clientID = " ";
#define VIRTUAL_CHANNEL 4 #define SENSOR_PIN D0 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
// WiFi network info.
char ssid = “”;
char wifiPassword = “”;
// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
// Read data from the sensor and send it to the virtual channel here.
// For example, to send a digital value you can use the following:
int value = digitalRead(SENSOR_PIN);
Cayenne.virtualWrite(V4, value, TYPE_DIGITAL_SENSOR, UNIT_DIGITAL);
}
Hallo @shramik_salgaonkar as Community Manager
Can you help me with my code to not continuously send a notification when the ultrasonic sensor read the limit, thank you
indent preformatted text by 4 spaces
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <Ultrasonic.h>
#define VIRTUAL_PIN V2
#define VIRTUAL_PIN V7
#define ACTUATOR_PIN 0
#define TRIGGER 5
#define ECHO 4
// NodeMCU Pin D1 > TRIGGER | Pin D2 > ECHO
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char username[] = " ";
char mqtt_password[] = " ";
char client_id[] = " ";
// Your network name and password.
char ssid[] = " ";
char password[] = " ";
Ultrasonic ultrasonic(5, 4);
void setup() {
Serial.begin (9600);
Cayenne.begin(username, mqtt_password, client_id, ssid, password);
pinMode(TRIGGER, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(BUILTIN_LED, OUTPUT);
pinMode(ACTUATOR_PIN, OUTPUT);
digitalWrite(ACTUATOR_PIN, HIGH);
}
void loop()
{
Cayenne.loop();
// do something
}
// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(V2)
{
long duration;
int distance;
digitalWrite(TRIGGER, LOW);
delayMicroseconds(1);
digitalWrite(TRIGGER, HIGH);
delayMicroseconds(1);
digitalWrite(TRIGGER, LOW);
duration = pulseIn(ECHO, HIGH);
distance = duration/29.1/ 2;
if(distance <= 0){
Serial.println("Out of Range");
}
else{
Serial.print(distance);
Serial.println("cm");
delay(1);
Cayenne.virtualWrite(V2, distance);
}}
CAYENNE_IN(V7)
{
int value = getValue.asInt();
if (value == HIGH){
digitalWrite(ACTUATOR_PIN, LOW);
}
else if (value == LOW){
digitalWrite(ACTUATOR_PIN, HIGH);
}
}
hello I turned on the trigger to send e-mail to the action of the channel, the first half hour while I was trying the emails arrived,but for some reason then the emails stopped coming, whatever I did