I have installed a gem “Rubygsm and dependencies”
I have the send sms working via the gem
The following code is from the gem core file for receiving an sms:
call-seq:
receive(callback_method, interval=5, join_thread=false)
Starts a new thread, which polls the device every interval
seconds to capture incoming SMS and call callback_method
for each, and polls the device’s internal storage for incoming
SMS that we weren’t notified about (some modems don’t support
that).
class Receiver
def incoming(msg)
puts “From #{msg.from} at #{msg.sent}:”, msg.text
end
end
# create the instances,
# and start receiving
rcv = Receiver.new
m = Gsm::Modem.new “/dev/ttyS0”
m.receive rcv.method :incoming
# block until ctrl+c
while(true) { sleep 2 }
Note: New messages may arrive at any time, even if this method’s
receiver thread isn’t waiting to process them. They are not lost,
but cached in @incoming until this method is called.
def receive(callback, interval=5, join_thread=false)
@polled = 0
The working code…
end # Modem
end # Gsm
Where do I setup the actions and where should I place the method calls
to the object in this class
All the hashes above are descriptions I believe on how to call the
methods but need guidance.
Can I define a class within a class, say messages? I tried this but I
dont think I can
I have run it in console in my app and get failures
Craig L. wrote in post #972958:
I have installed a gem “Rubygsm and dependencies”
I have the send sms working via the gem
The following code is from the gem core file for receiving an sms:
call-seq:
receive(callback_method, interval=5, join_thread=false)
Starts a new thread, which polls the device every interval
seconds to capture incoming SMS and call callback_method
for each, and polls the device’s internal storage for incoming
SMS that we weren’t notified about (some modems don’t support
that).
class Receiver
def incoming(msg)
puts “From #{msg.from} at #{msg.sent}:”, msg.text
end
end
This is showing you an example of a custom class that you are expected
to write. Say in a file called receiver.rb.
# create the instances,
# and start receiving
rcv = Receiver.new
m = Gsm::Modem.new “/dev/ttyS0”
m.receive rcv.method :incoming
# block until ctrl+c
while(true) { sleep 2 }
This is a script that uses the Receiver class. This code can be placed
at the end of the receiver.rb file somewhere after declaring and
implementing your Receiver class (just like the example here is
showing). Or it could exist in it’s own file that requires receiver.rb
at top.
The last line of this file will loop indefinitely with a two second
sleep between each loop.
Use ctrl+c to stop the program as shown above.
Note: I don’t see it shown here but you will need to require the gem
somewhere at the very top of receiver.rb. Something like:
require ‘rubygems’
require ‘’
In case you’ll be using this inside a Rails project somehow then adding
the gem to your Gemfile should be sufficient to use the GSM::Modem class
I believe.
Great
I will give it a try Robert, thanks for the help