iprog_sms 0.1.1 → 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 +12 -4
- data/lib/iprog_sms/sms.rb +39 -12
- data/lib/iprog_sms/version.rb +1 -1
- metadata +2 -2
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
CHANGED
@@ -12,11 +12,12 @@ phone_number = gets.chomp
|
|
12
12
|
# Prompt for message
|
13
13
|
print "Enter the message to send: "
|
14
14
|
message = gets.chomp
|
15
|
+
message = message.empty? ? "Test message form IPROG SMS" : message
|
15
16
|
|
16
17
|
# Optional: Prompt for the serial port (useful if there are multiple ports)
|
17
|
-
print "Enter the serial port for SIM800C (or press Enter to use default /dev/
|
18
|
+
print "Enter the serial port for SIM800C (or press Enter to use default /dev/tty.usbserial-1120): "
|
18
19
|
port = gets.chomp
|
19
|
-
port = port.empty? ? "/dev/
|
20
|
+
port = port.empty? ? "/dev/tty.usbserial-1120" : port
|
20
21
|
|
21
22
|
# Initialize SMS sender with the specified or default port
|
22
23
|
sms = IprogSms::SMS.new(port)
|
@@ -24,8 +25,15 @@ sms = IprogSms::SMS.new(port)
|
|
24
25
|
# Check if SIM800C is connected
|
25
26
|
if sms.connected?
|
26
27
|
puts "SIM800C module detected! Sending SMS..."
|
27
|
-
sms.send_sms(phone_number, message)
|
28
|
-
|
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
|
29
37
|
else
|
30
38
|
puts "SIM800C module not detected. Please check your connection."
|
31
39
|
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
|
+
attr_reader :error_message
|
9
|
+
|
8
10
|
def initialize(port_str = "/dev/ttyUSB0")
|
9
11
|
@baud_rate = 9600
|
10
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
25
|
# Set SMS to text mode with a shorter delay
|
20
|
-
send_at_command(serial, "AT+CMGF=1",
|
26
|
+
send_at_command(serial, "AT+CMGF=1", 3)
|
21
27
|
|
22
|
-
# Specify the recipient phone number
|
23
|
-
send_at_command(serial, "AT+CMGS=\"#{phone_number}\"",
|
28
|
+
# Specify the recipient 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
|
-
# Send the actual SMS message, followed by Ctrl+Z (ASCII 26)
|
26
|
-
send_at_command(serial, "#{message}\x1A",
|
35
|
+
# Send the actual SMS message, followed by Ctrl+Z (ASCII 26)
|
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,8 +65,8 @@ 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
|
@@ -55,7 +79,10 @@ module IprogSms
|
|
55
79
|
sleep(wait_time)
|
56
80
|
response = serial.read(1000)
|
57
81
|
puts "Response: #{response}"
|
58
|
-
|
82
|
+
response
|
83
|
+
rescue StandardError => e
|
84
|
+
@error_message = "Error during command execution: #{e.message}"
|
85
|
+
""
|
59
86
|
end
|
60
87
|
end
|
61
88
|
end
|
data/lib/iprog_sms/version.rb
CHANGED
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-
|
11
|
+
date: 2024-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyserial
|