[SOLVED] Sending warning to email

i want sending warning to my email if my sensor value reach temperature 25 Celcius. I use DHT 11 for my sensor.

here is my code

#include <Bridge.h>
#include <Process.h>
#include <DHT.h>
#include <SimpleTimer.h>
#include <FileIO.h>
#include <Process.h>
#define DHTPIN 9
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
unsigned int data;
int pir_pin = 8;
int relay_pin = 13;
int statuslampu = 0;

void sendData()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (t > 25.0) {
Process p;
p.runShellCommand(“cat /mnt/sda1/mail.txt | ssmtp agung.saputra94@gmail.com”);
delay (30000);
}
}

void takePicture() {
Process p; // Create a new process
p.begin(“fswebcam”); // Run the fswebcam utility, but first…
p.addParameter("/foto/pic.jpg"); // add a path parameter
p.addParameter("-r 1280x720"); // and a resolution parameter
p.run(); // now run it and and wait for its termination
}

void uploadPicture() {
Process p;
p.begin(“python”);
p.addParameter("/upload-to-dropbox.py");
p.run();
}

void setup() {
// put your setup code here, to run once:
Bridge.begin();
FileSystem.begin();
timer.setInterval(1000, sendData);
pinMode(pir_pin,INPUT);
pinMode(relay_pin,OUTPUT);
}

void loop() {
if ((digitalRead(pir_pin) == HIGH )&& (statuslampu == LOW)) {
digitalWrite(relay_pin, HIGH);
statuslampu = HIGH;
takePicture();
uploadPicture();
Process p;
p.runShellCommand(“cat /mnt/sda1/objek.txt | ssmtp agung.saputra94@gmail.com”);
}
if ((digitalRead(pir_pin) == HIGH) && (statuslampu ==HIGH)) {
digitalWrite(relay_pin, LOW);
statuslampu=LOW;
Process p;
p.runShellCommand(“cat /mnt/sda1/objek.txt | ssmtp agung.saputra94@gmail.com”);
takePicture();
uploadPicture();
}
}

but i dont get email form my yun . what i do for fix it ? can someone help me ?

Thanks for your attention

What happens if you SSH into your Yun and manually type this command at the Linx command line?

cat /mnt/sda1/objek.txt | ssmtp agung.saputra94@gmail.com

I'm not familiar with this way of sending a message. I've only ever used the Python smtplib to send emails from the Yun. This looks like it might be a much simpler way, so I'm interested in how this works out.

Does running it manually at the command line give you any error messages that might help? For example, does your smtp server require logging in before sending mail? (I'm pretty sure gmail.com doesn't run as an open gateway and does require you to log in.)

Make sure you can send the message from the command line first, before you try to send it from a sketch. If you can't perform an operation by typing it directly to the command line, then there isn't any point in trying to do it in a sketch using the Process object. Test it on the command line first, where you can actually see any error messages.

in this line cat /mnt/sda1/objek.txt | ssmtp agung.saputra94@gmail.com

in objek. txt i write for the content From:arduino yun Subject: Objek terdeteksi Objek terdeteksi

and I got email

in this line

if ((digitalRead(pir_pin) == HIGH )&& (statuslampu == LOW)) { digitalWrite(relay_pin, HIGH); statuslampu = HIGH; takePicture(); uploadPicture(); Process p; p.runShellCommand("cat /mnt/sda1/objek.txt | ssmtp agung.saputra94@gmail.com"); } if ((digitalRead(pir_pin) == HIGH) && (statuslampu ==HIGH)) { digitalWrite(relay_pin, LOW); statuslampu=LOW; Process p; p.runShellCommand("cat /mnt/sda1/objek.txt | ssmtp agung.saputra94@gmail.com"); takePicture(); uploadPicture(); } }

i got email when pir detect motion

but in this line void sendData() { float h = dht.readHumidity(); float t = dht.readTemperature(); if (t > 25.0) { Process p; p.runShellCommand("cat /mnt/sda1/mail.txt | ssmtp agung.saputra94@gmail.com"); delay (30000); } }

i dont get an email i dont know what happen here . I am sure my temperature over 25 celcius

Does the file /mnt/sda1/mail.txt exist?

Are you sure the sendData() function is being called?

You’re sure the temperature is greater than 25, but is the temperature actually being read properly?

For testing, I would hook up the USB serial port and open the serial monitor. Print out the temperature immediately after reading it. Then print out a message when you are a out to send the mail message. Do you see the proper temperature being printed? Does it print out the message that it’s going to send the mail?

Did you try running the problematical command direct from the Linux command line to see if it works?

thanks i can get warning from my sensor now

here is my latest code

#include <Bridge.h>
#include <Process.h>
#include <DHT.h>
#include <FileIO.h>
#define DHTPIN 9
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
long data = 0;
int pir_pin = 8;
int relay_pin = 13;


void takePicture() {
  Process p; // Create a new process
  p.begin("fswebcam"); // Run the fswebcam utility, but first...
  p.addParameter("/foto/pic.jpg"); // add a path parameter
  p.addParameter("-r 1280x720"); // and a resolution parameter
  p.run(); // now run it and and wait for its termination
}

void uploadPicture() {
  Process p; 
  p.begin("python"); 
  p.addParameter("/upload-to-dropbox.py"); 
  p.run(); 
}

void ceksuhu(){
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  Serial.print("Humidity: "); 
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: "); 
    Serial.print(t);
    Serial.println(" *C");
if (t > 25) {
   Process p;
 // This command line runs the WifiStatus script, (/usr/bin/pretty-wifi-info.lua), then 
 // sends the result to the grep command to look for a line containing the word
 // "Signal:"  the result is passed to this sketch:
 // p.begin();
 String dataString;
 dataString+="From: Arduino Yun\n";
 dataString+="To:agung.saputra94@yourmail.dk\n";
 dataString+="Subject: Peringatan Terjadi Kenaikan Suhu\n\n";
 dataString+="Terjadi kenaikan suhu\n";
 dataString+="Suhu Yang Terukur (dalam celcius)=";
 dataString+=t;
 File dataFile = FileSystem.open("/mnt/sda1/suhunaik.txt", FILE_WRITE);
 // if the file is available, write to it:
 if (dataFile) {

   dataFile.println(dataString);
   dataFile.close();
   // print to the serial port too:
   Serial.println(dataString);
 }  
 // if the file isn't open, pop up an error:
 else {
   Serial.println("error opening datalog.txt");
 } 


 p.runShellCommand("cat /mnt/sda1/suhunaik.txt | ssmtp agung.saputra94@gmail.com");

 while(p.running());  

 // Read command output. runShellCommand() should have passed "Signal: xx&":

 while (p.available()>0) {
   char c = p.read();
   Serial.print(c);
 }

 // Ensure the last bit of data is sent.
 Serial.flush();
 Serial.println("end");
 delay(50000);  // wait 50 seconds before you do it again
}  
}

void setup() {
  // put your setup code here, to run once:
   Bridge.begin();
  Serial.begin(9600); 
  Serial.println("DHTxx test!");
  dht.begin();
  FileSystem.begin();
  pinMode(pir_pin,INPUT);
  pinMode(relay_pin,OUTPUT);
  digitalWrite(relay_pin, LOW);
}

void loop() {
  ceksuhu();
  data = digitalRead(pir_pin);
  if (data == HIGH){
  digitalWrite(relay_pin, HIGH);
  takePicture();
  uploadPicture();
  Process p; 
  p.runShellCommand("cat /mnt/sda1/objek.txt | ssmtp agung.saputra94@gmail.com");
  delay(30000);
  } 
else if(data == LOW ) {
digitalWrite(relay_pin, LOW);}


}