Skip to content

Commit

Permalink
clean-up sms on start
Browse files Browse the repository at this point in the history
  • Loading branch information
nitram2342 committed Dec 16, 2024
1 parent c66e8ce commit d699121
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions server/modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def get_port(self) -> Optional[str]:

def get_status(self) -> Optional[str]:
"""
Get a textual string representing the current state of the modem in human-readbale form.
Get a textual string representing the current state of the modem in human-readable form.
@return: Returns a message indicating the modem's current state. Value may be None.
"""
return self.status
Expand Down Expand Up @@ -638,7 +638,7 @@ def _init_modem(self) -> bool:
self.status = "Check port renumbering - Exception."
return False

self.modem.smsTextMode = False
self.modem.smsTextMode = True # was False

self.l.debug(f"Connecting to GSM modem on {self.current_port}.")
self.status = "Connecting to modem."
Expand All @@ -649,6 +649,7 @@ def _init_modem(self) -> bool:
self.modem_config.pin,
waitingForModemToStartInSeconds=self.modem_config.wait_for_start,
)
#self.modem.processStoredSms()

except PinRequiredError:
self.l.error(f"Error: SIM card PIN required. Please specify a PIN.")
Expand Down Expand Up @@ -684,7 +685,7 @@ def _init_modem(self) -> bool:
self.modem.close()
return False

self._delete_sms()
self._delete_sms(all=True)

# We do not check the balance immediately, but wait a bit.
# self.check_balance()
Expand All @@ -705,12 +706,14 @@ def set_ready(self) -> None:
self.status = "Ready."

def _delete_sms(self, all:bool=False) -> None:
# Delete all unread/unset stored SMS
# Delete all unread/unsent stored SMS
try:
if all:
self.modem.write("AT+CMGD=,4\r\n")
self.modem.deleteMultipleStoredSms(4)
#self.modem.write("AT+CMGD=,4\r\n")
else:
self.modem.write("AT+CMGD=,2\r\n")
self.modem.deleteMultipleStoredSms(2)
#self.modem.write("AT+CMGD=,2\r\n")
except CmsError:
self.l.warning("Exception: Failed to delete SMS.")

Expand Down Expand Up @@ -877,6 +880,7 @@ def print_info(self) -> None:
self.l.info(f"Network : " + (self.current_network or "N/A"))
self.l.info(f"Signal strength : " + str(self.current_signal))
self.l.info(f"SMS Encoding : " + (self.modem.smsEncoding or "N/A"))
self.l.info(f"SMS Text Mode : " + str(self.modem.smsTextMode))

def _really_do_health_check(self) -> Tuple[str, Optional[str]]:
"""
Expand Down

0 comments on commit d699121

Please sign in to comment.