Sending message text to an email function. [Probably same for SMS]

{I previewed this message and saw how long it was. OMG! It's Siri's fault. She's just such a good secretary. I start dictating and before I realize it we've written a book! Sorry. She keeps up really well. ;)

Hey fellas,

I'm pretty new to Arduino (got it and Ethernet Shield a couple months ago) and I am 99% new to programming. My first program is a socket server to send and receive strings to/from an iPhone app called Net IO. (I'll take this opportunity to say that it is simply an amazing app. It is 100% customizable and well worth the $8 or $10. It even supports multiple simultaneous connections. The creator is very nice and helpful too.) None of this has anything to do with the question I am about to ask, but I wanted to throw that in just so that you get a grasp on the fact that I am new to Ardolino, but while I'm not the sharpest tool in the shed, I'm sharpened with the same stone...if that makes sense.

So aside from that and the SD card File Server I plan to add to it next, it includes a function for sending an email which I have addressed to my phone number @ my cellular carrier .com so that I get text messages triggered by events as notifications. Currently I only have worked out how I want it to work with the Alarm elements of myHone Automation, but will add others such as temperature later on.

I want to be able to change the subject and body of the email/text based on which event I'm being notified about. For example: "Breach at front door" or "Alarm triggered-zone 1". (I'll figure out times stamping once it's up and running. Every little thing I do I have to read and read to teach myself how to make it happen!)

Currently the only way that I think I could do it with my current knowledge-scratch that, call it basic understanding-is to pass the function a variable when it is called by the if statement that is checking the alarm state for a breach. Then within the email function, have if statements (or maybe a switch case?) that instruct the Arduino to send different text to the SMTP server depending on which value of the variable the function is given.

I have been trying to understand strings and I just can't figure them out. I barrowed roughly 15-20 lines of code from an example sketch so that's how I got my server to send/receive strings when I don't know how to code for them ;) Gotta love open source! Really, I think this community of DIY'rs and Techies is great! Anyways, I don't even understand how to send that email function a feasible word as the variable that tells it which message to send. I'd have to use integers and just remember that the PIR needs message 2 sent when triggered, or whatever number I gave it. I would really like to be able to leave my email function pretty much as it is, and simply give it the message body and subject that I want it to use.

I'm at work on my iPhone, or else I could include my sketch. I can post it a little later if necessary. My question is probably quite simple (at least to those out there that know how) and I'm guessing only requires a little bit of code, so I figured that you guys could provide an answer without having to see my sketch. Upon its completion, I do plan on posting it for everybody to use should they do desire. Right now it is incomplete, messy, and needs to be commented out.

Thanks so much for you help fellas, and ladies (; Hey, my first post! Joey

My question is probably quite simple

So can you form it in just one or two sentances?

Shoot. I'll give it a shot. I've always been far too loquacious for my own good.

How does one pass text (as in a sentence or two, like I'm attempting to ask my question using) to a function? I have an emailing function which works perfectly. The problem is it only sends the email subject and body that I have permanently typed into the function. I'm looking for more dynamic function.

For example, I'd like to be able to have my sketch call up the email function like this:

If (x == true) { sendEmail("x is true.", "Take my word for it bro, the rabbit hole is pretty deep!"); }

instead of just:

if...(){ sendEmail(); }

Where the first string is the subject of the email and the second string is the body. These can of course be variables that I define elsewhere. ie msgSubject1 and msgBody1 and so on. I've no idea how to do this.

Currently all I can do (I think it would work) is have an integer variable passed to the function and include if statements in the function. If var = 1 {then relist the code for sending the email over and over with different message text for each variable value I define; portion or all if the SMTP makes me.}

That's quite a waste of space. I'm sure this is possible. Am I being unclear at all? Please tell me if that isn't understandable.

Thanks fellas! Joey

Oh yea, so it turns out I can't has to question just a couple sentences.

Post your sendmail function. Without seeing it though, it looks like you need to adapt it to take two parameters:

void SendMail(char *Subject,char *Body)

And use those params appropriately in the body instead of your hard coded versions

void textMsgPushNotif()//int MsgContent) { const int waiting = 50;

if(mailClient.connect(mailServer, 25)) { mailClient.println("HELO x@x.xyx");//Say hello. delay(waiting); //Wait for a response. mailClient.println("MAIL From: x@x.xyx"); //Identify sender. delay(waiting); mailClient.println("RCPT To: 5555555555@messaging.CellularSP.com");//Identify recipient. mailClient.println("DATA"); delay(waiting); mailClient.println("Subject: System has been triggered by some shady bizness."); // Insert subject here. mailClient.println("FROM: x@x.xyx");//Sender's address, again. mailClient.println("TO: 5555555555@messaging.CellularSP.com");//Recipient's address, again. mailClient.println("I wish this whole line was something like: mailClient.println(msgBody); - Same for subject line: ...ntln(msgSubject);"); //Insert body of the email. mailClient.println("."); // end message mailClient.println("QUIT"); // terminate connection delay(waiting); mailClient.println(); mailClient.stop(); return; //??? Not sure if this is needed } }

Is the last line containing "return;" even required?

Is the last line containing “return;” even required?

No, it isn’t.