Sending a lot of SMS alert and email


#1

Hello,

I hope I’m in the right place for my question,

I created a project and alerts, the problem is that several tens of sms are sent per second until the state has changed.

The number of sms create problems with my wives, lol.

can we manage the number of sending of notification?

Thank you for your really great application!


Multiple Notify actions from one event
Controlling "off the shelf" Smart sockets
Trigger issues - multiple alerts and no hystersis
#2

this is known bug and team is working on solving it. till then I can provide a workaround, so can you post the code you are using.


#3

Ok thanks for the return

Here are:

I am not professional the code may not be the best :wink:

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "blabla";
char password[] = "blabla";
char clientID[] = "blabla";

#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
#define VIRTUAL_CHANNELA 2
int  Steps2Take = 0;

int HumiditeTerre;
#define CapteurTerre 0
#define VIRTUAL_CHANNEL 1

void setup() {
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
  myStepper.setSpeed(60);
  pinMode(CapteurTerre, INPUT);
  
}

void loop() {
  Cayenne.loop();
  int HumiditeTerre = analogRead(CapteurTerre);
  Serial.print("HumiditeTerre : ");
  Serial.println(HumiditeTerre);
  Cayenne.virtualWrite(1, HumiditeTerre, "soil_moist", "p");
  Steps2Take  = 1024;
 
}
CAYENNE_IN(VIRTUAL_CHANNELA)
{

    myStepper.step(Steps2Take);

}

#4

changed the main part of the code to avoid trigger flooding, but you need to set the trigger value of the humidity in the code.

int y;
int x;
int a;

int trigger = ;// you need to set this value
unsigned long lastMillis = 0;

void loop() {
  Cayenne.loop();
  int HumiditeTerre = analogRead(CapteurTerre);
  Serial.print("HumiditeTerre : ");
  Serial.println(HumiditeTerre);
  send_data();
  trigger();
}
void send_data()
{
  if (HumiditeTerre > trigger)
  {
    a = 1;
    if (millis() - lastMillis > 10000) {
      lastMillis = millis();
      Cayenne.virtualWrite(1, HumiditeTerre, "soil_moist", "p");
    }
  }
}
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;
    }
  }
} 

Upload this code and set a trigger for channel 3.


Crazy notifications
Trigger settings don't save
#5

The code is clever and solves the problem
thank you,
:+1:


#6

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


#7

yes that can work too. give it a try and let me know.


#8

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…


#9

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.


#10

hi… shramiksalgaonkarCommunity Manager

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


#11

can you share the the reed switch code you are using to display a 2 state?


#12

here my code

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

int sensorPin = A0;   
int sensorValue = 0;  // value for photoresistor


#define VIRTUAL_CHANNEL 2
const int REED_PIN = D0 ; 
int  buttonstate;


#define VIRTUAL_CHANNEL 1
#define VIRTUAL_CHANNEL 4
#define VIRTUAL_CHANNEL 5
#define ACTUATOR_PIN  D1
#define VIRTUAL_CHANNEL 6
#define VIRTUAL_CHANNEL 7

// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "f";


void setup() {
	Serial.begin(115200);
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  pinMode(REED_PIN,INPUT);
  pinMode(sensorPin, INPUT);
  pinMode(ACTUATOR_PIN, OUTPUT);
  }




void loop() {
	Cayenne.loop();
  send_data();
  trigger();  
   
  sensorValue = analogRead(sensorPin);   
  Serial.print("Light Intensity                 = ");
  Serial.println(sensorValue);
  Cayenne.virtualWrite(V1, sensorValue, "lum",  "lux");
  
   int  buttonstate = digitalRead(REED_PIN);
  if(buttonstate == HIGH) {
  Cayenne.virtualWrite(V4, LOW, "digital_sensor",   "d");
  Serial.println("MAIN DOOR CLOSED");
}else {
  Cayenne.virtualWrite(V4, HIGH, "digital_sensor",   "d");
  Serial.println("MAIN DOOR Opened");
       }
   }   
}
// This function is called when data is sent from Cayenne.
CAYENNE_IN(V6)
{
  int value = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
  // Write the value received to the digital pin.
  digitalWrite(ACTUATOR_PIN, value);
      }
}

#13

for your case you can try using this code:

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;
	}
}

#14

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 = “”;

void setup()
{
Serial.begin(115200);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop()
{
Cayenne.loop();
}

// 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);
}


#15

i cannot see my code in your above code.