Archive for the ‘Ruby’ Category

Send Gmail From Ruby Script

Hi.

Now we are going to see , how to send e-mail from Ruby Script.

fro that we need to install ,

$ sudo apt-get install ruby

$ sudo apt-get install rubygems

$ sudo gem install tlsmail

gmail.rb

require ‘rubygems’
require ‘tlsmail’
require ‘time’

$a=[‘tarulalan@gmail.com’,’tshrinivasan@gmail.com’,’jemenisuresh@gmail.com’]
$a.each do |to_mail|

content = <<MESSAGE_END
From: Arulalan <tarulalan@gmail.com>
To: #{to_mail}
Subject: SMTP e-mail test

This is a test e-mail message….

hi da.. how r u .. i m fine… now i sending this mail from ruby scrpt…… This body of our mail

MESSAGE_END

Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
Net::SMTP.start(‘smtp.gmail.com’, 587, ‘gmail.com’, ‘tarulalan@gmail.com’, ‘my passwd’, :login) do |smtp|
smtp.send_message(content, ‘tarulalan@gmail.com’, “#{to_mail}”)
end

end

# End Of Program

in this Prog , $a is an array and u can add many email id  to send mail.

and in this program tarulalan@gmail is my mail id.. you can replace with ur  gmail id.  🙂

அருளாளன் . த

Advertisements

SMS Frame Work Using Gnokii , Ruby & Mysql – Sending Bulk Sms

SMS Frame Work

Hai Friends,

Now we r going to see , how to send bulk sms using Mysql and Ruby and Gnokii.

For that we need to install following packages.

# To install MySql database:

$ sudo apt-get install mysql-server mysql-client mysql-admin

While install mysql , it will ask Password for root user of mysql database. We need to enter password two times. Type password as “password” itself. It will be safe.

# To install Ruby

$ sudo apt-get install ruby

$ sudo apt-get install libmysql-ruby

# To install Gnokii ( send sms from mobiles )

$ sudo apt-get install gnokii

Connect mobile and system:

To connct the mobile and sys ON the bluetooth in mobile and system,for system use bluetooth dongle no need of any drivers for bluetooth dongle.

In system the bluetooth sysbol apper as

note:

*in bluetooth symbol click and get preference and select “service”

In this sysmbol right click and select “Browse device” and select the u r mobile and click “connect” ,and accept the msg in mobile and give any passky and click ok,now the mobile and system paired successfully.

Now goto terminal type,

$ sudo gedit /etc/gnokiirc

gnokiirc(/etc)-gedit file opened and change the settings as follows

* in 27th line default present like

* #port = aa:bb:cc:dd:ee:ff

* change port = aa:bb:cc:dd:ee:ff and we want the mobile id or address to get(when mobile and sys connected only) type in terminal like

* $ hcitool scan

* it gives some address and copy this .

* Paste in the 27th line like port = aa:bb:cc:dd:ee:ff change port = “u r mobile address”

* enable model = AT in 51th line disable #model=6110

* put like because v use bluetooth connection # connection = serial in 90 th line

* remove # from connection = bluetooth in 101 st line.

note:

*the id of mobile change depend on mobile model

*don’t use china and goriya.. mobiles or try….

*get preference from bluetooth symbol and enable input service and disable serial service

*Use Ubuntu 8.04 for bluetooth it is compatable…

send sms and enjoy:

go to terminal for send single sms to single number

type

$ echo “ Hai My Dear Friend , Have A Good Day “ | gnokii –sendsms mobileno

# gnokii (double minus symbol ) – – sendsms  9994332225

Press Enter .

now send succeed !…


How to send sms to many numbers by automatically :

Just follow three steps:

Step 1:

Open text editor.

Type the contact person name and type comma ( , ) and followed by contact number and press Enter.

Repeat this process upto we need to add contacts to send sms.

Eg:

Kanchi_Lug_Contacts

Arulalan,9994332225

Raj Kumar,9940857450

Dasthageer,9994685704

.

.

.

xxxxxxxx,9876543210

I saved the text as “Kanchi_Lug_Contacts”. And While type last contact person number in your list, Pl dont press Enter.

Step 2:

Type the follwing in terminal :

$ mysql -u root -p

It will ask to enter Password. U have to type root password for Mysql. ( what u typed passwd while installing mysql )

mysql > create database myphone;

mysql > exit;

—————————————————————————————————

#initial.rb

require “mysql”

my = Mysql::new(“localhost”, “root”, “password”, “myphone”)

# Here, type host name, root , passwd for root user and finally database.

my.query(“create table kanchilug (sno integer(5) not null auto_increment primary key,name varchar(25),phone varchar(15))”)

my.query(“insert into kanchilug values(1,’Arulalan’,’9994332225′)”)

# To make auto matic sno ( primary key) we need to insert atleast one record.

file=File.open(“Kanchi_Lug_Contacts”,”r”)

file.each do |name_and_no|

name_and_no.chomp!

contact=name_and_no.split(/,/)

my.query(“insert into kanchilug values(”,’#{contact[0]}’,’#{contact[1]}’)”)

end

my.close

print ” Kanchi Lug Members Contact Saved ”

—————————————————————————————————

Step 3:

# Klug_Send_Sms.rb

require “mysql”

my = Mysql::new(“localhost”, “root”, “password”, “myphone”)

klug_contacts=my.query(“select * from kanchilug”)

klug_contacts.each do |contact|

# Here contact becomes araay which stored ‘sno’, ‘name’, ‘number’

system(“echo ‘ Hi Kanchi Lug Friends , we hv class on sunday 3 pm. v r going to learn about Arduino Board & Python. Same place, come early ‘ | gnokii –sendsms ‘#{contact[2]}’ “)

# gnokii (double minus symbol ) – – sendsms  9994332225

print “Kanchilug msg sent to #{contact[0]} : #{contact[1]} : #{contact[2]} \n ”

sleep(10)

end

my.close

print ” Msg Sent To All Kanchi Lug Members Successfully \n”

print “Bye\n”

—————————————————————————————————


Thats all….

Here u need to type ur msg with echo “ “ in this program.

Here after u just run the above program only to send sms .

First two steps for setup, initially. ( No need for every time :- )

Yeap !

Enjoy With Ruby and Gnokii by sending bulk sms…

You can download this blog as pdf from here

http://www.slideshare.net/arulalan/sms-frame-work#

Regards ,

Arulalan.T

அருளாளன் . த

RAD INSTALLATION GUIDE

Ruby Arduino Development (RAD) Installation

we tried to install rad (Ruby Arduino Development) in ubuntu , but it showed many errors because of version variation between Ruby and Rubygems…

so we tried to install rad in new ubuntu loaded system. even there we got few errors, but finally we have installed successfully.

If gem works properly in your system then , just run:

$sudo gem install rad


In new ubuntu system ( or remove already installed ruby and rubygems)

to install rad follow the below steps:

Type the following link in your URL

www.rubyhead.com/files/installruby.zip


Then it will ask to save file and save that.

Now Extract (unzip) this “installruby.zip”…


$cd installruby


change the current directory into installruby folder via Terminal. Now run this following

$ ./installruby

(Here ‘installruby’ is a scripting program and it will install ruby,irb,rubygems, rails and many needed packages automatically.)


$sudo gem install rad


It will take some time to install and end with “could not find main page README.txt”

Many things will be installed and from that it installed “ParseTree-3.0.3”.. This is higher version , and it will make version conflict error while executing rake make:compile our project.

So we have to uninstall that and replace with “ParseTree-2.2.0”

$sudo gem uninstall ParseTree

Now it asks to remove some packages and we have to agree it by press “y”

(yes). And even it asks to remove “RubyToC” , so remove that too..

Now install “ParseTree-2.2.0”

$ sudo gem install –version=2.2.0 ParseTree


$sudo gem install RubyToC

Now we are going to download Arduino software.

Arduino Software Download Link:

http://arduino.cc/en/Main/Software

In that web page we have more links to download arduino, from that we have to choose below line:

Arduino 0012 (release notes): Windows, Mac OS X, Linux (32bit), Linux (AMD 64bit)

From this click Linux(32 bit) , then it will started to download

Then extract the downloaded “arduino-0012-linux.tgz”

Then we have to install gcc library for avr

$sudo apt-get install gcc-avr avr-libc

Now we have to make link between avr-gcc libraries and arduino

first create a directory “avr” inside the arduino-0012/hardware/tools.

$mkdir arduino-0012/hardware/tools/avr


$ ln -s /usr/bin /home/user name/arduino-0012/hardware/tools/avr

Now we finished all our installation & linking works. Let us start to work in rad.

RAD Use Guide

$rad my_sketch

Now it will created “my_sketch” folder inside current directory…

Inside that folder it has “my_sketch.rb” ,we have to write our ruby code for arduino in that file.

Inside that it have “config” folder, it contains “hardware.yml” and “software.yml”.

We have to edit “software.yml” and set the path to arduino( /home/user name/arduino-0012 )

We have to edit “hardware.yml” also

serial_port: /dev/ttyS0

physical_reset: false

mcu: atmega8

If the chip is does not atmega8 then change to corresponding chip name.(atmega168)

$rake make:compile

Reset your Arduino Board


$rake make:upload

Enjoy with RAD !

அருளாளன் . த