Module: IprogSms::Sim800cTroubleshoot
- Defined in:
- lib/iprog_sms/sim800c_troubleshoot.rb
Class Method Summary collapse
-
.check_signal_strength(serial) ⇒ Object
Check signal strength.
-
.list_messages(serial) ⇒ Object
List all messages in the inbox.
-
.restart_module(serial) ⇒ Object
Restart the SIM800C module (if supported).
-
.send_at_command(serial, command, wait_time = 1) ⇒ Object
Sends an AT command to the SIM800C and reads the response.
-
.set_message_storage(serial) ⇒ Object
Set message storage location to SIM card.
-
.set_text_mode(serial) ⇒ Object
Set message format to text mode.
-
.troubleshoot_sim800c(port_str) ⇒ Object
Main troubleshooting function.
Class Method Details
.check_signal_strength(serial) ⇒ Object
Check signal strength
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/iprog_sms/sim800c_troubleshoot.rb', line 40 def self.check_signal_strength(serial) response = send_at_command(serial, "AT+CSQ") if response&.include?("+CSQ") signal_strength = response.match(/\+CSQ: (\d+)/)[1].to_i puts "Signal strength: #{signal_strength}" if signal_strength < 10 puts "Warning: Low signal strength may affect message delivery." else puts "Signal strength is adequate." end else puts "Failed to retrieve signal strength." end end |
.list_messages(serial) ⇒ Object
List all messages in the inbox
56 57 58 59 60 61 62 63 |
# File 'lib/iprog_sms/sim800c_troubleshoot.rb', line 56 def self.(serial) response = send_at_command(serial, 'AT+CMGL="ALL"') if response&.include?("+CMGL") puts "Messages in inbox:\n#{response}" else puts "No messages found in the inbox or unable to retrieve messages." end end |
.restart_module(serial) ⇒ Object
Restart the SIM800C module (if supported)
66 67 68 69 70 71 72 73 |
# File 'lib/iprog_sms/sim800c_troubleshoot.rb', line 66 def self.restart_module(serial) response = send_at_command(serial, "AT+CFUN=1,1") if response&.include?("OK") puts "Module restarted successfully." else puts "Failed to restart the module. Try manually if this command is unsupported." end end |
.send_at_command(serial, command, wait_time = 1) ⇒ Object
Sends an AT command to the SIM800C and reads the response
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/iprog_sms/sim800c_troubleshoot.rb', line 7 def self.send_at_command(serial, command, wait_time = 1) puts "Sending command: #{command}" serial.write("#{command}\r") sleep(wait_time) response = serial.read(1000) puts "Response: #{response}" response rescue StandardError => e puts "Error sending command #{command}: #{e.}" nil end |
.set_message_storage(serial) ⇒ Object
Set message storage location to SIM card
20 21 22 23 24 25 26 27 |
# File 'lib/iprog_sms/sim800c_troubleshoot.rb', line 20 def self.(serial) response = send_at_command(serial, 'AT+CPMS="SM","SM","SM"') if response&.include?("OK") puts "Message storage set to SIM card (SM)." else puts "Failed to set message storage location." end end |
.set_text_mode(serial) ⇒ Object
Set message format to text mode
30 31 32 33 34 35 36 37 |
# File 'lib/iprog_sms/sim800c_troubleshoot.rb', line 30 def self.set_text_mode(serial) response = send_at_command(serial, "AT+CMGF=1") if response&.include?("OK") puts "Message format set to Text Mode." else puts "Failed to set message format to Text Mode." end end |
.troubleshoot_sim800c(port_str) ⇒ Object
Main troubleshooting function
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/iprog_sms/sim800c_troubleshoot.rb', line 76 def self.troubleshoot_sim800c(port_str) begin serial = Serial.new(port_str, 9600) # Adjust baud rate if necessary puts "Starting SIM800C troubleshooting..." # Step 1: Set message storage to SIM card (serial) # Step 2: Set message format to Text Mode set_text_mode(serial) # Step 3: Check signal strength check_signal_strength(serial) # Step 4: List all messages in the inbox (serial) # Step 5: Restart the module if needed puts "Do you want to restart the module? (y/n)" if gets.chomp.downcase == 'y' restart_module(serial) end rescue StandardError => e puts "Error: #{e.}" ensure serial&.close puts "Troubleshooting complete." end end |