Sending a lot of SMS alert and email

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.

1 Like