Skip to content

Commit 3ceb3c2

Browse files
feat: implement get_signal_strength method in network.py (#124)
Within this commit, we have added a new method called `get_signal_strength` to the `Network` class in the `network.py` module. This method retrieves the signal strength of the connected network and returns it in dBm units. It is a request made in issue #118.
1 parent e05506a commit 3ceb3c2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pico_lte/modules/network.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,25 @@ def get_pdp_ready(self):
345345
elif result["status"] == Status.ERROR:
346346
return result
347347
time.sleep(result["interval"])
348+
349+
def get_signal_strength(self):
350+
"""
351+
Function for getting the cellular signal strength (RSSI) in dBm.
352+
353+
Returns
354+
-------
355+
dict
356+
Result that includes "status", "response", and "rssi" keys.
357+
"""
358+
command = "AT+CSQ"
359+
result = self.atcom.send_at_comm(command)
360+
361+
if result["status"] == Status.SUCCESS:
362+
try:
363+
rssi_raw = result["response"][0].split(":")[1].split(",")[0].strip()
364+
rssi_dbm = (int(rssi_raw) * 2) - 109
365+
result["rssi"] = rssi_dbm
366+
except (IndexError, ValueError):
367+
result["status"] = Status.ERROR
368+
result["error"] = "Failed to parse RSSI value."
369+
return result

0 commit comments

Comments
 (0)