Simple routine in Sketch

Hi,
I’m setting out my Yun to read several sensors in my house. When a sensor is triggered, I’d like to receive an email alerting me of the problem.
I set up a Temboo account and test it out successfully so my question is:
How do I set up a routine in Sketch so that when a sensor is triggered, I can receive an email?

String emailSubject("This is an automated email from your Arduino Yún. ");
String emailBody(“”);
void loop() {
if (moistureState == HIGH); {  // if triggered send email
String emailBody(“”); // clear text
emailBody = "A water leak has been detected!!"
sendMail(emailSubject,emailBody);
}
if (tempState == HIGH); {  // if triggered send email
String emailBody(“”); // clear text
emailBody = (“High temp has been detected”)
sendMail(emailSubject,emailBody);
}
}
sendMail(emailSubject,emailBody) {
-- working Temboo code here--
}

Any help is appreciated.
TIA

This almost is always a mistake:

if (tempState == HIGH); {  // if triggered send email

Note the semicolon between the closing parenthesis and the opening brace. Also, go to your source code window, put the cursor somewhere in the source code window and press Ctrl-T.

Thank you for pointing that out. It was a typo while typing the code (didn’t copy/paste it as the original code is in a different language).

My question is how do I write a routine so can just call it when needed.

Cheers.

If that was a typo, maybe these are too:

String emailSubject("This is an automated email from your Arduino Yún. ");
String emailBody("");
void loop() {
if (moistureState == HIGH); { // if triggered send email
String emailBody(""); // clear text
emailBody = "A water leak has been detected!!"
sendMail(emailSubject,emailBody);
}
if (tempState == HIGH); { // if triggered send email
String emailBody(""); // clear text
emailBody = ("High temp has been detected")
sendMail(emailSubject,emailBody);
}
}
sendMail(emailSubject,emailBody) {
-- working Temboo code here--
}

When you call a function, you do not put the function type specifier in front of the call. Indeed, if these two functions return a String object type, you normally would be assigning the return value into something.

Thank you again.

I didn’t pay too much attention to my code as I was after the subroutine. Next time I’ll pass my code through Sketch.

Anyway, I found my answer here: http://forum.arduino.cc/index.php?topic=54578.0

No, we understand: Too much work for you to do before you post, so just let us do it rather than doing it yourself first.

ebolisa:
Thank you for pointing that out. It was a typo while typing the code (didn’t copy/paste it as the original code is in a different language).

The code itself will still be readable. We tend to ignore comments anyway as they often don't really describe what is happening. Much better to copy and paste.