Skip to content

Commit 535e359

Browse files
authored
Allow sending raw AT commands to the modem (#28)
1 parent 3996463 commit 535e359

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

scripts/hologram_modem.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import subprocess
1818
import time
1919

20+
DEFAULT_TIMEOUT = 5
21+
2022
help_connect = '''This subcommand establishes a cellular connection.\n
2123
'''
2224

@@ -40,6 +42,8 @@
4042
help_location = '''Print the location of the modem based on cell towers if supported\n
4143
'''
4244

45+
help_at_command = '''Send an AT command to the modem and print the result'''
46+
4347
help_reset = '''Restart the modem\n'''
4448

4549
help_radio_off = '''Turn off the cellular radio on the modem\n'''
@@ -87,6 +91,17 @@ def run_modem_signal(args):
8791
else:
8892
print('Signal strength: ' + str(cloud.network.signal_strength))
8993

94+
def run_at_command(args):
95+
cloud = CustomCloud(None, network='cellular')
96+
cmd = ''
97+
if args['command'] is not None:
98+
cmd = args['command'].lstrip("AT")
99+
val = None
100+
if not cmd.endswith('?') and '=' in cmd:
101+
cmd, val = cmd.split('=')
102+
result, response = cloud.network.modem.command(cmd, val, timeout=args['timeout'])
103+
print('Response: ' + ''.join(map(str, response)) + f'\n{result}')
104+
90105
def run_modem_version(args):
91106
cloud = CustomCloud(None, network='cellular')
92107
version = cloud.network.modem.version
@@ -142,6 +157,7 @@ def run_modem_location(args):
142157
_run_handlers = {
143158
'modem_connect': run_modem_connect,
144159
'modem_disconnect': run_modem_disconnect,
160+
'modem_command': run_at_command,
145161
'modem_sim': run_modem_sim,
146162
'modem_operator': run_modem_operator,
147163
'modem_signal': run_modem_signal,
@@ -212,6 +228,14 @@ def parse_hologram_modem_args(parser):
212228
parser_radio_off.set_defaults(command_selected='modem_radio_off')
213229
parser_radio_off.add_argument('-v', nargs='?', action=VAction, dest='verbose', required=False)
214230

231+
# at-command
232+
parser_command = subparsers.add_parser('command', help=help_at_command)
233+
parser_command.set_defaults(command_selected='modem_command')
234+
parser_command.add_argument('command', nargs='?', help='AT command to send to the modem')
235+
parser_command.add_argument('-t', '--timeout', type=int, default=DEFAULT_TIMEOUT, nargs='?',
236+
help='The period in seconds before the command exits if it doesn\'t receive a response')
237+
parser_command.add_argument('-v', nargs='?', action=VAction, dest='verbose', required=False)
238+
215239
# version
216240
parser_version = subparsers.add_parser('version', help=help_version)
217241
parser_version.set_defaults(command_selected='modem_version')

0 commit comments

Comments
 (0)