Class: Sim800c::Commands::SendMessage
- Inherits:
-
Object
- Object
- Sim800c::Commands::SendMessage
- Includes:
- Helpers
- Defined in:
- lib/sim800c/commands/send_message.rb
Instance Method Summary collapse
-
#initialize(serial) ⇒ SendMessage
constructor
A new instance of SendMessage.
-
#save_and_send(phone_number, message) ⇒ Object
Stores and sends the message using AT+CMGW and AT+CMSS.
-
#send_immediate(phone_number, message) ⇒ Object
Sends the message immediately using AT+CMGS.
Methods included from Helpers
#at_cmd, #parse_cmgl_response, #read_response, #return_or_raise_error!
Constructor Details
#initialize(serial) ⇒ SendMessage
Returns a new instance of SendMessage.
8 9 10 |
# File 'lib/sim800c/commands/send_message.rb', line 8 def initialize(serial) @serial = serial end |
Instance Method Details
#save_and_send(phone_number, message) ⇒ Object
Stores and sends the message using AT+CMGW and AT+CMSS
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sim800c/commands/send_message.rb', line 26 def save_and_send(phone_number, ) at_cmd('AT+CMGF=1') @serial.read(100) at_cmd("AT+CMGW=\"#{phone_number}\"") @serial.read(100) at_cmd("#{}#{26.chr}") response = read_response(wait_time: 1) index = response[/\+CMGW:\s*(\d+)/, 1] at_cmd("AT+CMSS=#{index}") if index response = read_response(wait_time: 1) response.lines.last.chomp.eql?('OK') end |
#send_immediate(phone_number, message) ⇒ Object
Sends the message immediately using AT+CMGS
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sim800c/commands/send_message.rb', line 13 def send_immediate(phone_number, ) at_cmd('AT+CMGF=1') @serial.read(100) at_cmd("AT+CMGS=\"#{phone_number}\"") @serial.read(100) at_cmd("#{}#{26.chr}") response = read_response(wait_time: 1) response.lines.last.chomp.eql?('OK') end |