• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomeProjectYún – SMS alarm
Previous Next

Yún – SMS alarm

Posted by: Olva , May 12, 2016

[vc_row][vc_column][vc_column_text]This tutorial will explain a way to communicate between the sketch running on the ATMega and the Linino(Linux) OS running on the Yun’s SoC: the ability to execute Linux processes from a sketch.

I’m going to build a simple SMS alarm:

  • A microswitch is connected to the Arduino
  • when the microswitch is pressed, an SMS is sent using Skebby gateway

[embedyt] http://www.youtube.com/watch?v=xpshNEz4pUw[/embedyt]

[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column][vc_tta_tour][vc_tta_section title=”Linino side” tab_id=”1463103142130-9bfd498f-e05c”][vc_column_text]A PHP script will send the message interacting with the Skebby SMS gateway.

To be able to run PHP scripts you have first to install some modules, with the command:

opkg install php5 php5-cli php5-mod-curl

The sendSMSAlert.php script, developed starting from some of the available examples, is available on my GitHub’s repository and must be saved in the /root folder (home directory for the root user).

You have to change some parameters in the sendSMS method: insert your Skebby account, the recipient and sender numbers and the text to be sent:

echo sendSMS("skebby_user", "skebby_password", 
 "391234567890", "391234567890", "Warning: door opened!", "0cent") . "\n";

5

Skebby offers different SMS types: the last parameter specifies which SMS have to be used. The available SMS types are listed at the top of the script:

define ("SMS_TYPE_0CENT", "0cent");
define ("SMS_TYPE_CLASSIC", "classic");
define ("SMS_TYPE_CLASSIC_PLUS", "classic_plus");
define ("SMS_TYPE_BASIC", "basic");

In the video I used the 0cent type, which is free but requires the Skebby app installed on the recipient’s phone (and the phone must be connected to the Internet too).[/vc_column_text][/vc_tta_section][vc_tta_section title=”Arduino side” tab_id=”1463103142176-38e96c82-3b84″][vc_column_text]The Arduino sketch is too available on my repository.

I connected the microswitch this way:

  • the common PIN to Arduino’s PIN 2
  • the normally closed PIN to ground
  • the normally opened PIN to 5V

This means that when the microswitch is open, PIN 2 of Arduino is connected to the ground (LOW state), but when the microswitch is pressed, that PIN is connected to 5V (HIGH state). I also used PIN 13 (connected on a LED on the board) to display the status of the microswitch).

5-15-2

Both the two PINs can be changed using the constants at the beginning of the sketch:

#define SWITCH_PIN 2
#define LED_PIN 13

In the main loop() the sketch continuously checks the microswitch status: if it’s pressed, the sendAlert()method is invoked. I also store the previous status of the microswitch to be sure to send an SMS only when it changes from free to pressed.

The sendAlert() method uses a functionality of the Bridge library: the ability to run a command/script on the Linino side:

void sendAlert() {
 
  Process p;            
  p.begin("php-cli");      
  p.addParameter("/root/sendSMSAlert.php"); 
  p.run();
}

It calls the PHP interpreter (php-cli) to run the sendSMSAlert.php script that was previously saved in the root’s home directory.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Conclusions” tab_id=”1463103144366-6fdaafc8-56b5″][vc_column_text]In this tutorial I showed you a first example of how to interact between a sketch and Linino… in the next ones I’m going to show you how to do the opposite (Linino -> sketch) and how to pass values between them,[/vc_column_text][/vc_tta_section][/vc_tta_tour][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]For more details,please refer to original post

http://www.lucadentella.it/en/2015/03/07/yun-allarme-via-sms/[/vc_column_text][/vc_column][/vc_row]

Share!
Tweet

Olva

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors