iprog_sms 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90b96ab4208fd86918b9b66a42e2b3d18153f93774e771da7db5ea33076652ae
4
- data.tar.gz: bb92a9bd4c9da6a8931f09f7a97bcb59eab08c4fbdd76f362de65543ba857c18
3
+ metadata.gz: 38d490d602c52d31b7ad45891697c635d66cb22d6ea2df5763165ea17b8158d4
4
+ data.tar.gz: a71301ee81282d13c29a7afe75c5728954119536506274a9f485f9f5d748f518
5
5
  SHA512:
6
- metadata.gz: '090c37cbbccef0b31f8f219bb8ce12d386e44a21ffbc9725e29b1be8e198bef6a437b8c692c84dc35f7d9346d9ca2333e7e724428b48abc92d2cbe5a240e2e3a'
7
- data.tar.gz: d72af85bf9271c25a1dfb9548f3a9a086a3dfc678d4e4fc6402b161adcb577f656e839bfe697c05f9dd22ae20d2c7bf4971e986f73603df2c49f25e6d7d9c1e4
6
+ metadata.gz: 78b2baa9276e6737886b07ea6eff242943e83fc8dbf01da8a479db11a58fb84a8920ed0acc4e4fbb838fa16c05a8af1976a0be231c9b5a555f04a1bb9ab87e05
7
+ data.tar.gz: 4e52939964e37d3eefcdecb8777ed71a8bc6595fa8a418084de82144a906141cf91446757673391e4cb2e96d44e54437fb52e822e39f0958d708b2e924edf1d7
@@ -0,0 +1,31 @@
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
+
16
+ # 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/ttyUSB0): "
18
+ port = gets.chomp
19
+ port = port.empty? ? "/dev/ttyUSB0" : port
20
+
21
+ # Initialize SMS sender with the specified or default port
22
+ sms = IprogSms::SMS.new(port)
23
+
24
+ # Check if SIM800C is connected
25
+ if sms.connected?
26
+ puts "SIM800C module detected! Sending SMS..."
27
+ sms.send_sms(phone_number, message)
28
+ puts "SMS sent successfully!"
29
+ else
30
+ puts "SIM800C module not detected. Please check your connection."
31
+ 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,9 +5,9 @@ require 'rubyserial'
5
5
 
6
6
  module IprogSms
7
7
  class SMS
8
- def initialize
8
+ def initialize(port_str = "/dev/ttyUSB0")
9
9
  @baud_rate = 9600
10
- @port_str = detect_sim800c || "/dev/ttyUSB0" # Detect SIM800C port automatically
10
+ @port_str = port_str # Use the passed port, or default to "/dev/ttyUSB0"
11
11
  end
12
12
 
13
13
  def send_sms(phone_number, message)
@@ -16,14 +16,14 @@ module IprogSms
16
16
  # Open the serial connection
17
17
  serial = Serial.new(@port_str, @baud_rate)
18
18
 
19
- # Set SMS to text mode
20
- send_at_command(serial, "AT+CMGF=1")
19
+ # Set SMS to text mode with a shorter delay
20
+ send_at_command(serial, "AT+CMGF=1", 1)
21
21
 
22
- # Specify the recipient phone number
23
- send_at_command(serial, "AT+CMGS=\"#{phone_number}\"")
22
+ # Specify the recipient phone number with a shorter delay
23
+ send_at_command(serial, "AT+CMGS=\"#{phone_number}\"", 1)
24
24
 
25
- # Send the actual SMS message, followed by Ctrl+Z (ASCII 26)
26
- send_at_command(serial, "#{message}\x1A", 5)
25
+ # Send the actual SMS message, followed by Ctrl+Z (ASCII 26), with a longer delay for processing
26
+ send_at_command(serial, "#{message}\x1A", 3)
27
27
 
28
28
  puts "SMS sent to #{phone_number}."
29
29
  serial.close
@@ -49,40 +49,6 @@ module IprogSms
49
49
 
50
50
  private
51
51
 
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
52
  def send_at_command(serial, command, wait_time = 1)
87
53
  puts "Sending command: #{command}"
88
54
  serial.write("#{command}\r")
@@ -2,5 +2,5 @@
2
2
  # lib/iprog_sms/version.rb
3
3
 
4
4
  module IprogSms
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
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.0
4
+ version: 0.1.1
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-10-26 00:00:00.000000000 Z
11
+ date: 2024-11-03 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