Home icon

GM862 tutorial

The GM862 is a module that integrates a GSM modem, a GPS receiver and a Python interpreter.

The module features a file system. It doesn't support directories but it does support any files ( not just Python scripts) as long as the file names are no longer than 16 characters.

The gm862 script

Most of the tools available for the GM862 are for Windows. The archive below includes a command-line tool called gm862. The tool requires that a serial port be present and connected to the GM862. Edit ./gm862 if your serial port is not at /dev/ttyUSB0.

The script has sub-commands:

command purpose
list Shows a list of the files on the module
upload Uploads all the files given as arguments to the module
rm Removes all files given as arguments from the module
boots Shows which script will be booted when the module is started
boot Sets the active script that the module runs when it boots
run Runs the active script immediately without the need for a power cycle

Examples:

$ ./gm862 help
boot
boots
help
list
rm
run
upload

$ ./gm862 list
#LSCRIPT: "Test.py",1981
#LSCRIPT: "NMEA.pyo",1364

$ ./gm862 upload Main.py

$ ./gm862 list
#LSCRIPT: "Test.py",1981
#LSCRIPT: "NMEA.pyo",1364
#LSCRIPT: "Main.py",3226

$ ./gm862 rm Test.py

$ ./gm862 list
#LSCRIPT: "NMEA.pyo",1364
#LSCRIPT: "Main.py",3226

$ ./gm862 boots
#ESCRIPT: "Test.py"

$ ./gm862 boot Main.py

$ ./gm862 boots
#ESCRIPT: "Main.py"

$ ./gm862 run

Example code

There are some other files in the archive:

HelloWorld.py  Modem.py  debug.py  traceback.py

Modem.py wraps some AT commands and provides a nice API to:

traceback.py is a cut-down copy of the file of the same name from Python 1.5.2. The traceback Python module is not included on the device and is required by debug.py. debug.py provides a tidy way of sending nicely formatted debugging output but it also provides much needed support for catching and reporting exceptions on the module. Use it like this:

 
False, True = 0, 1

import SER
import MOD

SER.set_speed('4800')
SER.send("System initialization in progress..\r\n")

from debug import *
db("Debugging support is now available.")

try:
  db("Initializing modem..")
  from Modem import Modem
  modem = Modem()
  # Wait up to 15 seconds to get registered on the network:
  when_began_waiting = MOD.secCounter()
  while MOD.secCounter() < when_began_waiting + 15:
    if modem.is_registered():
      break
    MOD.sleep( 1)
  db("  registered on network: %s"% "Ny"[modem.is_registered()])
  db("  complete.")

  should_run = True
  while should_run:
    MOD.sleep( 10)

except Exception, e:
  report_error( e)

This is a considerable improvement over having the software crash with an exception and having no error output whatsoever.

Notes

Download