Skip to content

Commit

Permalink
Allow sending raw AT commands to the modem (hologram-io#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
DomAmato authored Apr 3, 2020
1 parent 3996463 commit 535e359
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scripts/hologram_modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import subprocess
import time

DEFAULT_TIMEOUT = 5

help_connect = '''This subcommand establishes a cellular connection.\n
'''

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

help_at_command = '''Send an AT command to the modem and print the result'''

help_reset = '''Restart the modem\n'''

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

def run_at_command(args):
cloud = CustomCloud(None, network='cellular')
cmd = ''
if args['command'] is not None:
cmd = args['command'].lstrip("AT")
val = None
if not cmd.endswith('?') and '=' in cmd:
cmd, val = cmd.split('=')
result, response = cloud.network.modem.command(cmd, val, timeout=args['timeout'])
print('Response: ' + ''.join(map(str, response)) + f'\n{result}')

def run_modem_version(args):
cloud = CustomCloud(None, network='cellular')
version = cloud.network.modem.version
Expand Down Expand Up @@ -142,6 +157,7 @@ def run_modem_location(args):
_run_handlers = {
'modem_connect': run_modem_connect,
'modem_disconnect': run_modem_disconnect,
'modem_command': run_at_command,
'modem_sim': run_modem_sim,
'modem_operator': run_modem_operator,
'modem_signal': run_modem_signal,
Expand Down Expand Up @@ -212,6 +228,14 @@ def parse_hologram_modem_args(parser):
parser_radio_off.set_defaults(command_selected='modem_radio_off')
parser_radio_off.add_argument('-v', nargs='?', action=VAction, dest='verbose', required=False)

# at-command
parser_command = subparsers.add_parser('command', help=help_at_command)
parser_command.set_defaults(command_selected='modem_command')
parser_command.add_argument('command', nargs='?', help='AT command to send to the modem')
parser_command.add_argument('-t', '--timeout', type=int, default=DEFAULT_TIMEOUT, nargs='?',
help='The period in seconds before the command exits if it doesn\'t receive a response')
parser_command.add_argument('-v', nargs='?', action=VAction, dest='verbose', required=False)

# version
parser_version = subparsers.add_parser('version', help=help_version)
parser_version.set_defaults(command_selected='modem_version')
Expand Down

0 comments on commit 535e359

Please sign in to comment.