iprog_sms 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/iprog_send_sms +39 -0
- data/bin/iprog_send_sms_from_api +22 -0
- data/bin/iprog_sms_troubleshoot +16 -0
- data/lib/iprog_sms/sim800c_troubleshoot.rb +107 -0
- data/lib/iprog_sms/sms.rb +40 -47
- data/lib/iprog_sms/version.rb +1 -1
- data/lib/iprog_sms.rb +5 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dbc858e8d39453fd6c0fc37cd608bb11e1de15cbdd0abaa61c3644c61515f35
|
4
|
+
data.tar.gz: 3a8bb09fbc5a8cc46754034a05d629b282944ee7fc3e03c6c2994dd28b6393c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f93d1cde5d157272a7409f1919c57d3d74947184feda65959d9c3fad5d5217bbafff9ca72fc84357e04a89f8e7d98639ebd64f386b012bb187151bdde122ca8
|
7
|
+
data.tar.gz: 1236837762de8303d51fab8753f6ac1c92927d2480b05fdd518521434e5f67f0134817abc00bad4d80089dfbcb837ce32f9a6fbc9eb9e7038c19b37bf345cc04
|
data/bin/iprog_send_sms
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/iprog_sms'
|
4
|
+
|
5
|
+
# Welcome message
|
6
|
+
puts "Welcome to IPROG SMS Sender!"
|
7
|
+
|
8
|
+
# Prompt for phone number
|
9
|
+
print "Enter the phone number to send SMS: "
|
10
|
+
phone_number = gets.chomp
|
11
|
+
|
12
|
+
# Prompt for message
|
13
|
+
print "Enter the message to send: "
|
14
|
+
message = gets.chomp
|
15
|
+
message = message.empty? ? "Test message form IPROG SMS" : message
|
16
|
+
|
17
|
+
# Optional: Prompt for the serial port (useful if there are multiple ports)
|
18
|
+
print "Enter the serial port for SIM800C (or press Enter to use default /dev/tty.usbserial-1120): "
|
19
|
+
port = gets.chomp
|
20
|
+
port = port.empty? ? "/dev/tty.usbserial-1120" : port
|
21
|
+
|
22
|
+
# Initialize SMS sender with the specified or default port
|
23
|
+
sms = IprogSms::SMS.new(port)
|
24
|
+
|
25
|
+
# Check if SIM800C is connected
|
26
|
+
if sms.connected?
|
27
|
+
puts "SIM800C module detected! Sending SMS..."
|
28
|
+
success = sms.send_sms(phone_number, message)
|
29
|
+
|
30
|
+
if success && !sms.error_message
|
31
|
+
puts "SMS sent successfully."
|
32
|
+
else
|
33
|
+
puts "Failed to send SMS: #{sms.error_message}"
|
34
|
+
end
|
35
|
+
|
36
|
+
puts success.inspect
|
37
|
+
else
|
38
|
+
puts "SIM800C module not detected. Please check your connection."
|
39
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/iprog_sms'
|
4
|
+
|
5
|
+
# Welcome message
|
6
|
+
puts "Welcome to IPROG SMS Sender with API!"
|
7
|
+
|
8
|
+
# Prompt for API URL
|
9
|
+
print "Enter the API URL to fetch SMS details: "
|
10
|
+
api_url = gets.chomp
|
11
|
+
|
12
|
+
# Initialize the SMS sender with API
|
13
|
+
sender = IprogSms::Sender.new(api_url)
|
14
|
+
|
15
|
+
# Check if SIM800C is connected
|
16
|
+
if sender.instance_variable_get(:@sms_sender).connected?
|
17
|
+
puts "SIM800C module detected! Fetching SMS details from API and sending..."
|
18
|
+
sender.send_sms_from_api
|
19
|
+
puts "SMS sent successfully!"
|
20
|
+
else
|
21
|
+
puts "SIM800C module not detected. Please check your connection."
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'iprog_sms'
|
4
|
+
|
5
|
+
# Ensure that a port argument is provided
|
6
|
+
if ARGV.empty?
|
7
|
+
puts "Usage: iprog_sms_troubleshoot <port>"
|
8
|
+
puts "Example: iprog_sms_troubleshoot /dev/tty.usbserial-1120"
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Get the serial port from the command-line arguments
|
13
|
+
port_str = ARGV[0]
|
14
|
+
|
15
|
+
# Run the troubleshooting method
|
16
|
+
IprogSms.troubleshoot_sim800c(port_str)
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# lib/iprog_sms/sim800c_troubleshoot.rb
|
2
|
+
require 'rubyserial'
|
3
|
+
|
4
|
+
module IprogSms
|
5
|
+
module Sim800cTroubleshoot
|
6
|
+
# Sends an AT command to the SIM800C and reads the response
|
7
|
+
def self.send_at_command(serial, command, wait_time = 1)
|
8
|
+
puts "Sending command: #{command}"
|
9
|
+
serial.write("#{command}\r")
|
10
|
+
sleep(wait_time)
|
11
|
+
response = serial.read(1000)
|
12
|
+
puts "Response: #{response}"
|
13
|
+
response
|
14
|
+
rescue StandardError => e
|
15
|
+
puts "Error sending command #{command}: #{e.message}"
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
# Set message storage location to SIM card
|
20
|
+
def self.set_message_storage(serial)
|
21
|
+
response = send_at_command(serial, 'AT+CPMS="SM","SM","SM"')
|
22
|
+
if response&.include?("OK")
|
23
|
+
puts "Message storage set to SIM card (SM)."
|
24
|
+
else
|
25
|
+
puts "Failed to set message storage location."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Set message format to text mode
|
30
|
+
def self.set_text_mode(serial)
|
31
|
+
response = send_at_command(serial, "AT+CMGF=1")
|
32
|
+
if response&.include?("OK")
|
33
|
+
puts "Message format set to Text Mode."
|
34
|
+
else
|
35
|
+
puts "Failed to set message format to Text Mode."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Check signal strength
|
40
|
+
def self.check_signal_strength(serial)
|
41
|
+
response = send_at_command(serial, "AT+CSQ")
|
42
|
+
if response&.include?("+CSQ")
|
43
|
+
signal_strength = response.match(/\+CSQ: (\d+)/)[1].to_i
|
44
|
+
puts "Signal strength: #{signal_strength}"
|
45
|
+
if signal_strength < 10
|
46
|
+
puts "Warning: Low signal strength may affect message delivery."
|
47
|
+
else
|
48
|
+
puts "Signal strength is adequate."
|
49
|
+
end
|
50
|
+
else
|
51
|
+
puts "Failed to retrieve signal strength."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# List all messages in the inbox
|
56
|
+
def self.list_messages(serial)
|
57
|
+
response = send_at_command(serial, 'AT+CMGL="ALL"')
|
58
|
+
if response&.include?("+CMGL")
|
59
|
+
puts "Messages in inbox:\n#{response}"
|
60
|
+
else
|
61
|
+
puts "No messages found in the inbox or unable to retrieve messages."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Restart the SIM800C module (if supported)
|
66
|
+
def self.restart_module(serial)
|
67
|
+
response = send_at_command(serial, "AT+CFUN=1,1")
|
68
|
+
if response&.include?("OK")
|
69
|
+
puts "Module restarted successfully."
|
70
|
+
else
|
71
|
+
puts "Failed to restart the module. Try manually if this command is unsupported."
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Main troubleshooting function
|
76
|
+
def self.troubleshoot_sim800c(port_str)
|
77
|
+
begin
|
78
|
+
serial = Serial.new(port_str, 9600) # Adjust baud rate if necessary
|
79
|
+
puts "Starting SIM800C troubleshooting..."
|
80
|
+
|
81
|
+
# Step 1: Set message storage to SIM card
|
82
|
+
set_message_storage(serial)
|
83
|
+
|
84
|
+
# Step 2: Set message format to Text Mode
|
85
|
+
set_text_mode(serial)
|
86
|
+
|
87
|
+
# Step 3: Check signal strength
|
88
|
+
check_signal_strength(serial)
|
89
|
+
|
90
|
+
# Step 4: List all messages in the inbox
|
91
|
+
list_messages(serial)
|
92
|
+
|
93
|
+
# Step 5: Restart the module if needed
|
94
|
+
puts "Do you want to restart the module? (y/n)"
|
95
|
+
if gets.chomp.downcase == 'y'
|
96
|
+
restart_module(serial)
|
97
|
+
end
|
98
|
+
|
99
|
+
rescue StandardError => e
|
100
|
+
puts "Error: #{e.message}"
|
101
|
+
ensure
|
102
|
+
serial&.close
|
103
|
+
puts "Troubleshooting complete."
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/lib/iprog_sms/sms.rb
CHANGED
@@ -5,33 +5,57 @@ require 'rubyserial'
|
|
5
5
|
|
6
6
|
module IprogSms
|
7
7
|
class SMS
|
8
|
-
|
8
|
+
attr_reader :error_message
|
9
|
+
|
10
|
+
def initialize(port_str = "/dev/ttyUSB0")
|
9
11
|
@baud_rate = 9600
|
10
|
-
@port_str =
|
12
|
+
@port_str = port_str # Use the passed port, or default to "/dev/ttyUSB0"
|
13
|
+
@error_message = nil # Initialize error message
|
11
14
|
end
|
12
15
|
|
13
16
|
def send_sms(phone_number, message)
|
17
|
+
@error_message = nil # Reset error message before sending
|
18
|
+
|
14
19
|
if connected?
|
15
20
|
begin
|
16
21
|
# Open the serial connection
|
17
22
|
serial = Serial.new(@port_str, @baud_rate)
|
23
|
+
result_status = false
|
18
24
|
|
19
|
-
# Set SMS to text mode
|
20
|
-
send_at_command(serial, "AT+CMGF=1")
|
25
|
+
# Set SMS to text mode with a shorter delay
|
26
|
+
send_at_command(serial, "AT+CMGF=1", 3)
|
21
27
|
|
22
28
|
# Specify the recipient phone number
|
23
|
-
send_at_command(serial, "AT+CMGS=\"#{phone_number}\"")
|
29
|
+
response = send_at_command(serial, "AT+CMGS=\"#{phone_number}\"", 3)
|
30
|
+
unless response.include?(">")
|
31
|
+
@error_message = "Failed to specify recipient. Response: #{response}"
|
32
|
+
result_status = false
|
33
|
+
end
|
24
34
|
|
25
35
|
# Send the actual SMS message, followed by Ctrl+Z (ASCII 26)
|
26
|
-
send_at_command(serial, "#{message}\x1A", 5)
|
36
|
+
response = send_at_command(serial, "#{message}\x1A", 5)
|
37
|
+
if response.include?("+CMGS")
|
38
|
+
puts "SMS successfully sent to #{phone_number}."
|
39
|
+
result_status = true
|
40
|
+
elsif response.include?("+CMS ERROR")
|
41
|
+
error_code = response.match(/\+CMS ERROR: (\d+)/)[1]
|
42
|
+
@error_message = "Failed to send SMS. Error code: #{error_code}"
|
43
|
+
result_status = false
|
44
|
+
else
|
45
|
+
@error_message = "Unexpected response while sending SMS: #{response}"
|
46
|
+
result_status = false
|
47
|
+
end
|
27
48
|
|
28
|
-
puts "SMS sent to #{phone_number}."
|
29
49
|
serial.close
|
30
|
-
|
31
|
-
|
50
|
+
|
51
|
+
result_status
|
52
|
+
rescue StandardError => e
|
53
|
+
@error_message = "Error while sending SMS: #{e.message}"
|
54
|
+
false
|
32
55
|
end
|
33
56
|
else
|
34
|
-
|
57
|
+
@error_message = "SIM800C is not connected!"
|
58
|
+
false
|
35
59
|
end
|
36
60
|
end
|
37
61
|
|
@@ -41,55 +65,24 @@ module IprogSms
|
|
41
65
|
response = send_at_command(serial, "AT")
|
42
66
|
serial.close
|
43
67
|
response.include?("OK") # Check if the response contains "OK"
|
44
|
-
rescue
|
45
|
-
|
68
|
+
rescue StandardError => e
|
69
|
+
@error_message = "Error checking connection: #{e.message}"
|
46
70
|
false
|
47
71
|
end
|
48
72
|
end
|
49
73
|
|
50
74
|
private
|
51
75
|
|
52
|
-
def detect_sim800c
|
53
|
-
# List all potential serial ports (Linux/macOS). For Windows, replace with 'COM*'.
|
54
|
-
potential_ports = Dir['/dev/ttyUSB*'] + Dir['/dev/tty.usbserial*'] + Dir['/dev/tty.*']
|
55
|
-
|
56
|
-
potential_ports.each do |port|
|
57
|
-
puts "Checking port: #{port}"
|
58
|
-
begin
|
59
|
-
# Try opening the port
|
60
|
-
serial = Serial.new(port, @baud_rate)
|
61
|
-
|
62
|
-
# Send the AT command
|
63
|
-
serial.write("AT\r")
|
64
|
-
sleep(1) # Wait for a response
|
65
|
-
response = serial.read(100)
|
66
|
-
|
67
|
-
# If the response contains "OK", it's likely the SIM800C
|
68
|
-
if response.include?("OK")
|
69
|
-
puts "SIM800C detected on port: #{port}"
|
70
|
-
serial.close
|
71
|
-
return port # Return the correct port
|
72
|
-
else
|
73
|
-
puts "No response from #{port}, moving to next port..."
|
74
|
-
serial.close
|
75
|
-
end
|
76
|
-
rescue StandardError => e
|
77
|
-
puts "Error on #{port}: #{e.message}"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# If no SIM800C is detected
|
82
|
-
puts "No SIM800C module detected."
|
83
|
-
nil
|
84
|
-
end
|
85
|
-
|
86
76
|
def send_at_command(serial, command, wait_time = 1)
|
87
77
|
puts "Sending command: #{command}"
|
88
78
|
serial.write("#{command}\r")
|
89
79
|
sleep(wait_time)
|
90
80
|
response = serial.read(1000)
|
91
81
|
puts "Response: #{response}"
|
92
|
-
|
82
|
+
response
|
83
|
+
rescue StandardError => e
|
84
|
+
@error_message = "Error during command execution: #{e.message}"
|
85
|
+
""
|
93
86
|
end
|
94
87
|
end
|
95
88
|
end
|
data/lib/iprog_sms/version.rb
CHANGED
data/lib/iprog_sms.rb
CHANGED
@@ -5,6 +5,11 @@ require_relative "../lib/iprog_sms/version"
|
|
5
5
|
require_relative "../lib/iprog_sms/sms"
|
6
6
|
require_relative "../lib/iprog_sms/api_client"
|
7
7
|
require_relative "../lib/iprog_sms/sender"
|
8
|
+
require_relative '../lib/iprog_sms/sim800c_troubleshoot'
|
8
9
|
|
9
10
|
module IprogSms
|
11
|
+
# Method to run the SIM800C troubleshooting script
|
12
|
+
def self.troubleshoot_sim800c(port_str)
|
13
|
+
IprogSms::Sim800cTroubleshoot.troubleshoot_sim800c(port_str)
|
14
|
+
end
|
10
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iprog_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jayson Presto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyserial
|
@@ -28,13 +28,20 @@ description: This gem allows you to send SMS using the SIM800C module and suppor
|
|
28
28
|
fetching SMS details from an API.
|
29
29
|
email:
|
30
30
|
- jaysonpresto.iprog21@gmail.com
|
31
|
-
executables:
|
31
|
+
executables:
|
32
|
+
- iprog_sms_troubleshoot
|
33
|
+
- iprog_send_sms
|
34
|
+
- iprog_send_sms_from_api
|
32
35
|
extensions: []
|
33
36
|
extra_rdoc_files: []
|
34
37
|
files:
|
38
|
+
- bin/iprog_send_sms
|
39
|
+
- bin/iprog_send_sms_from_api
|
40
|
+
- bin/iprog_sms_troubleshoot
|
35
41
|
- lib/iprog_sms.rb
|
36
42
|
- lib/iprog_sms/api_client.rb
|
37
43
|
- lib/iprog_sms/sender.rb
|
44
|
+
- lib/iprog_sms/sim800c_troubleshoot.rb
|
38
45
|
- lib/iprog_sms/sms.rb
|
39
46
|
- lib/iprog_sms/version.rb
|
40
47
|
homepage: https://rubygems.org/gems/iprog_sms
|