Basics of sending an email/txt notification after an event is detected?

I am new to the imp, and to network programming, and I am wondering if someone might provide a general guidance to me on what I need to set up in order to use the info sent from an imp back to the agent to send me an email/text that an event has occurred (like “Check your AC, because the living room temperature is 93 degrees”). I assume that I will need to be running some sort of server at home, but I am rather clueless as to the basic approach that is considered “standard”. Any guidance is greatly appreciated, and I will be very happy to go STFW and RTFM once I have some direction. Thanks.

The beauty of the imp is no, you do not need a server at home :slight_smile:

For a SMS alerting system from a thermistor, you’d pull in two libraries:

  1. Thermistor library. This will read a thermistor & bias resistor hooked to an imp pin and give you a temperature. Wiring instructions are in the repo. You’d set up an imp.wakeup look to read the temperature periodically, and send it to the agent with an agent.send() call.

Something like this:

  • 10k thermistor between GND and pin 9
  • 10k resistor between pin 9 and 3.3v.

`
#require “Thermistor.class.nut:1.0.0”

const b_therm = 3988;
const t0_therm = 298.15;

temp_sns <- hardware.pin9;

// thermistor on bottom of divider
myThermistor <- Thermistor(temp_sns, b_therm, t0_therm, 10, false);

function read_and_send() {
// read temperature in F and send to agent
local reading = myThermistor.readF();
server.log("temperature = "+reading+“F”);
agent.send(“temperature”, reading);

// do it again in 60 seconds
imp.wakeup(60, read_and_send);
}

// Start sampling
read_and_send();
`

  1. Twilio library (and a twilio account - sign up on twilio.com). You’d write a few lines of code to receive temperatures from the imp and a one liner to send you an SMS if a threshold was crossed.

`#require “Twilio.class.nut:1.0.0”

// Fill these in with the details from your twilio account
twilio <- Twilio(TWILIO_SID, TWILIO_AUTH, TWILIO_NUM);

// When we get a message from the imp…
device.on(“reading”, function(reading) {
// Show it arrived
server.log("received reading "+reading+“F”);

// Too hot?
if (reading > 90) {
// Send SMS
local message = "Alert! Temperature is "+reading+“F”;
local resp = twilio.send(“your phone number”, message);
server.log("Twilio response: "+resp.statuscode + ": " + resp.body);
});
`

See here https://www.electricimp.com/docs/examples/libraries/

…and that’s it. You can plug it in anywhere in the world, connect it to wifi, and it will just sit there and work. If you fancy changing the code, you can do that from anywhere in the world and it’ll securely download to the imp.

There are all sorts of optimizations - eg making the imp run from batteries for years by sleeping (and maybe not even firing up wifi unless the temperature was such that an alarm needed to be sent) - which will make it bigger & more complex.

This is wonderful! Thank you very much!

For a handy email API which works with imp check out http://www.mailgun.com/

It’s so easy to use it does not need a library :slight_smile:

btw plenty of other email API’s out there. Mandrill and SendGrid spring to mind.

And some of you would be shocked if I didn’t put in a plug for our friends at GroveStreams. Similar to other cloud services, they let you post data there for historical analysis and easily set up graphs and events to do things like send SMS or email messages or call APIs when the conditions you specify are satisfied.

For gerriko for sharing this Email- API it helps me alot. I am also looking for this kind of SMS gateway API please share if you have one to send Bulk SMS

@Natashawilliams,

Look into Twilio (www.twilio.com). It’s not free though. You probably won’t find a free SMS service that would handle more than a few texts each day.

What is nice about Twilio is that you are given a “twilio cellphone number”. That means when someone gets a text, they can reply. The reply goes to your Twilio phone number, and you can act on that reply through your website’s PHP scripts, or in the case of the Imp, the Agent can act on the reply. This could be important because when you get a text from the Agent, you may want to tell the Agent that you received the text and do not text again for a certain number of hours.

Can you tell us more about what your Imp is doing? Why it would be texting you?

Nexmo is another and I believe you get some free credit to get you started.

I just looked at Nexmo. That is really an easy service to use, and not so expensive. What is nice about text (SMS) compared to email, is that almost nobody emails messages to phones. Any user that gets an email message would be a little bit confused by it. Texting is mindless. Also, using email requires different @ email addresses based on carrier. Texting is just a phone number.

Pricing: You can send 1000 messages for about 6 dollars. It costs .74 cents each month to have a “message number” (your own Nexmo cellphone number).