loading

"I'M GONNA POP SOME TAGS, ONLY GOT TWENTY DOLLARS IN MY POCKET. I'M A HUNTING, LOOKING FOR A COME UP, THIS IS F......" Parties are a blast when they are YOUR party. They aren't so much fun when the sound is booming from across the street. While I'm SURE you love your loud neighbors and want to tell them in person to turn it down, it's cold outside and even your warmest flannel zebra jammies can't keep the chill out. Why don't we make a button the texts our neighbors when they are too loud? Perhaps a text from your handy Intel Edison?

This instructable is all about how to send SMS messages (ie texts) using node.js.

So drape yourself in (faux) leopard mink, a velour jumpsuit, and get ready to MAKE!

Step 1: Set Up Your Edison

Before you go any further, you've flashed your Edison with the newest image and configured the wifi, right? No? Well you had better get on it: https://communities.intel.com/docs/DOC-23147

We are going to need some things to make this work.

The first is the node packages from Twilio. Twilio is a company in San Francisco that has an API that allows folks to make calls and texts via THE CLOUD! (all hail the cloud). You will need to make a free account at www.Twilio.com in order to complete this instructable. Open up your terminal and connect to your Edison. Type the following and press enter:

>> npm install twilio

Cool. Now you can text. Now we need to get a package that allows us to run our app even when our terminal has been closed. Note that the "-g" flag is extremely important for our needs.

>> npm install forever -g

Awesome. Now we need a text editor. There is Vim/Vi on the Edison, but it doesn't always like to work. Here's how to install Nano (which is also much easier to use for beginners):

>> wget <a href="http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz" rel="nofollow">http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz</a> && tar xvf nano-2.2.6.tar.gz && cd nano-2.2.6 && ./configure && make && make install
>> make clean 
>> rm -r nano*

We need a folder to put our project into as well. Note that if you followed my email tutorial, you don't have to enter in the second line here.

>> cd
>> makedir mySandbox
>> makedir partyAlarm

I like to reboot to clear up ram that has been used (and improperly disposed of) during installs, so:

>> reboot

Cool beans. Now we are ready to write some code and make some circuits!

Step 2: Let's Write Some Code!

Before you write any code (ahw maaaannnnnnn), you will need to set up a Twilio account if you haven't already. Go to www.Twilio.com and set one up. For our purposes, we can use the free trial.

We are using node.js to write our code. It is a JavaScripting language that can be insanely wonderful to use. The first thing we want to do is open up our code file in Nano. You can save by pressing control+o and exit by pressing control+x.

>> nano partyAlarm.js -$ -i

Cool. Now in the words of every Game of Thrones fan, "Code is coming". Type all of this fine jazz into the text editor, save, and then exit. The instructables text editor LOVES to screw up the formatting. If you come across a <br>, delete it and start a newline there instead (ie, press enter or return).

// Set up our input pin on pin 5 of the Edison Arduino Board
var mraa = require('mraa'); var buttonPin = new mraa.Gpio(5); buttonPin.dir(mraa.DIR_IN); //Set up the stuffs for Twilio. You will need to set up an //account to get your SID and your token/authentication key
var twilio = require('twilio'); var client = new twilio.RestClient('<<twilio sid>>',
'<<twilio token>>'); //Read our button var buttonPushed = buttonPin.read(); //If our button was pressed, send our message //You will need to fill in your own twilio number to make this work.
//Note, we are texting 1(555)123-4567 here. This is obviously a
//wrong number. Put your friend's in there instead. if(buttonPushed){ client.sms.messages.create({ to:'+15551234567', from: '<<your twilio number>>',
body: 'I can\'t hear my light saber go SWOOSH SWOOSH over your racket.' }, function(error, message){ if(!error){
console.log("Message sent at " + message.dateCreated);
} else {
console.log("Message wasn't sent...");
}
});
} //Hold in the program until we release the button.
while (buttonPushed){
setTimeout(emptyFunction, 200); //debounce
buttonPushed = buttonPin.read(); }
//When we use forever.js, it will need to make sure that our program lasts at
//least 1 millisecond each time it runs. So, we wait for 4 milliseconds before
//ending our function
setTimeout(emptyFunction, 4);

//Basically, we use this for our delay. We have to call some flavor of
//function to use the setTimeout function.
function emptyFunction(){ }

Step 3: Simple Circuits and Start Up.

Since this is an instructable about texting with your Edison, we'll keep the circuit simple - a button with a 10K pulldown resistor. If you aren't familiar with how to wire that, search "Arduino button circuit" on Google.

Now that you've written your code and wired your button, we need to start our code running! Forever.js is a neat little package that will run your code until the end of time, restarting it over and over again until Godzilla knocks over the power lines. Unlike my email tutorial, you may notice that this code doesn't automatically loop - in order for the SMS message to be sent, the node.js app needs to exit. Once it exits, forever.js will restart it and keep going. In your Edison's terminal, type the following and press enter:

>> forever start --minUptime 1 partyAlarm.js

Ah man, you added some fancy stuff outside of this instructable, screwed up and your friend is getting text messages every half second. You need to stop the madness immediately! How do you do this? In the terminal, type the following and press enter:

>> forever list 

This will tell you what jobs are running and what the job numbers are. The job number will typically be "0" if you aren't running anything else with forever.js. So, we will stop job 0. Type the following and press enter:

>> forever stop 0 

GREAT! You are done! You now have a weapon of mass annoyance to bug your neighbors! Sweet!

<p>&gt;&gt; wget <a href="http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz" rel="nofollow">http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz</a> &amp;&amp; tar xvf nano-2.2.6.tar.gz &amp;&amp; cd nano-2.2.6 &amp;&amp; ./configure &amp;&amp; make &amp;&amp; make install <br><br>for this, I got unexpected &amp;&amp; error.</p>
<p>Hi BertugBerkay,</p><p>I also got that unexpected &amp;&amp; error, and what i did just simply remove the '&amp;&amp;':</p><p>wget <a href="http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz" rel="nofollow">http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz</a></p><p>tar xvf nano-2.2.6.tar.gz</p><p>cd nano-2.2.6</p><p>./configure</p><p>make</p><p>make install</p><p>cheers! </p><p>*and oh! thanks A_Steingrube for the instructable!</p>
If I want to learn the coding you did in putty, what language do I need to learn?
As I mentioned throughout this instructable, I am using Node.js here. You can write code in any language you want. Ones like Python, Node.Js and C++ are the best supported, but anything that can read and write files will work.<br><br>Also, Putty doesn't really &quot;do&quot; anything when it comes to programming. Think of it like a telephone that you are using to call a friend for help - the only thing Putty does is relay a message between you and your Edison in a format called SSH. What you see on the screen is a message from the Edison and what you type into Putty is messaged over to the Edison. Putty (or any other SSH client) is not a programming software, just a messenger.
Thank you
Thank You so much!<br>
<p>Putty is a Terminal Emulator, it is used to talk to the Edison's Linux command line. So go research command line commands for Intel Edison, or Yocto Image. It wouldn't hurt to research Linux commands in general, but they vary by distributions, or versions of the same distribution (usually do to missing packages, memory limits or they only compiled the bare minimum they needed). </p>
Thanks so much<br>
<p>Good call on installing Nano - I can see how Vi would be super discouraging to a first-time user. I may poach some of this for a public transit tracker I'm working on. I'll definitely link over to you if I end up using some of your code!</p>

About This Instructable

5,678views

29favorites

License:

Bio: I'm an Electrical Engineer who dabbles in just about everything. By trade, I'm a controls engineer and design machines for the largest manufacturing ... More »
More by A_Steingrube:Quick and Dirty Mosquito Trap Send Texts with Intel Edison (Party Alarm) Email with Intel Edison (Intruder Alarm) 
Add instructable to: