Click here to Skip to main content
15,867,834 members
Articles / Programming Languages / Python
Article

Cellular Development with Telit GSM Module and Python

Rate me:
Please Sign up or sign in to vote.
4.75/5 (4 votes)
20 Sep 2010CPOL8 min read 87.1K   8   18
This article will provide some background to help understand how to get started developing Python scripts for the Telit family of devices.

Cellular Development with Telit GSM Module and Python

Introduction

Telit produces a series of cellular modules that can be used to add advanced communication abilities to any project. Some units come with a Python interpreter that makes it possible to access the advanced features and even control external equipment. I am not a Python expert, but the real challenge isn’t learning Python. It is understanding the AT commands needed to run the module. This article will provide some background to help understand how to get started developing Python scripts for this family of devices.

Background

I just completed a project involving monitoring and control of equipment for a remote FM radio transmitter site. We used the terminus device by Janus Remote Communications as the basis for this project. The exact product I used is available here.

Other companies such as Sparkfun provide breakout options, but the Terminus Terminal device I used works as an all in one enclosed system. GPS capable units are also available. Some units do now have Python capabilities, so be careful when ordering. Also, these are cell phones, so an active SIM card is needed in order to use the cellular functions.

Initial Setup

The module requires use of the Telit Python package. The editor is not the greatest, but will provide limited and buggy debugging capability. I used my own Python capable editor and just complied/downloaded the code with the Telit Python version. Once installed, all you need to do to load a script to the unit is right click on the file and compile it, then with the unit connected, right click on the .pyo file and download. The unit can use .py files, but more complex scripts tend to slow down without compiling them into .pyo files.

Image 1

To activate a script, we use an AT command:

AT#ESCRIPT[="script_name]

Example:

at#escript?
#ESCRIPT: "test.pyo"
OK

Setting the ESCRIPT determines what script will be used at startup. Another command is used to determine if it will startup and how long it will wait.

AT#STARTMODESCR=<start mode>, [script name]
at#startmodescr?
#STARTMODESCR: 1,10
OK

This command has two parameters, mode and timeout.

Three options exist for mode:

  • Option 0: No script at startup
  • Option 1: Script will run unless AT command is issued by user at startup
  • Option 2: Script will run after timeout no matter what.

Option 2 is dangerous unless you have access to more than one serial port on the device. However, it can be overcome with the use of the CMUX function that will be covered later.

Timeout is in seconds. It should be noted that the device takes ~5s to boot, then the timer starts, so a setting of 10 seconds will result in a bootup time before script execution of ~15 seconds.

Telit has a ton of documentation that is poorly organized and sometimes hard to understand. This article will cover most of the Python specific functions as well as debugging, but future articles may include certain topics more in-depth on how to do more functions with the module itself, such as sending an SMS or email.

CMUX

CMUX is buggy and hard to use, but when you get it to work, it’s a life saver and makes program development a lot easier.

CMUX is the ability for the module to multiplex several functions onto one serial port. For my project, I used CMUX to watch the Python print statements and send serial commands to an external device using a program called serialmon. It also gives you access to the second AT interface for issuing commands while a script is running.

I’ll explain how to set it up then tell you how I got around some of the crazy problems with it.

Two commands are needed:

AT+CMUX
AT#CMUXSCR

AT+CMUX has two parameters, but only one option for each one. Just confirm that it is set to 0,0 with the AT+CMUX? command.

AT+CMUXSCR controls the speed and activates the CMUX prototcol. To activate the interface with a speed of 115200 baud, use the following command:

AT#CMUXSCR=1,115200

Now comes the complex part. You need the PC based software from Telit. It can be downloaded from here.

Configure the software from the setup option in the main program:

Image 2

Image 3

Make sure the virtual ports do not conflict with real ports on your computer. The main port is the actual connection you will be using to talk to the module.

I used a terminal program that Round Solutions makes for the Telit modules. It can be found here.

Image 4

It has a lot of specific shortcuts for the modules and a logging function. Any terminal program will work fine.

Now comes the hard part. When connecting to the device that is running Python code, you need to give it time to startup and begin running. For my situation, this took ~15s. I setup a timer, and when I powered the device on and waited at least 15 seconds, I could connect with no trouble. Using your terminal program with Telitserialportmux, you can open a connection to the appropriate virtual port. It is important to note that the Python debugger is on virtual port #4 and the first AT instance is on port #1 by default.

Connecting to virtual port #4 after the script has started will activate the mux, and the icon in the system tray will turn blue. Now you should see any print statements that are executed in your script. Make sure to close the connections before powering off the unit, or you will have to close and restart all your programs. The mux program does not support suddenly losing connection that well.

Image 5

This is the hardest part to figure out and may not work for everyone. I mentioned this before but the interface is buggy, and if you don’t need it, don’t bother, but it helps to debug the scripts as you run them.

Python

It’s helpful to realize that the Python side of the module does not control the module directly; it is essentially just a fancy way to automatically send it AT commands. If your situation allows, you can just use a PC or microcontroller based system to send it AT commands so that it can be done that way, but if you want a standalone system, Python is the way to go.

Telit has several custom libraries that make things a lot easier:

  • MDM
  • MDM2
  • SER
  • SER2
  • GPIO
  • MOD
  • SPI
  • IIC
  • GPS

The most used libraries are the MDM interfaces. These are used to send commands to and from the module. MDM and MDM2 use different AT instances. The device can be controlled from either one. For my project, it came in handy to multitask a bit by using MDM to send Telnet packets directly to the SER interface while reading the connection status on the MDM2 interface.

SER interfaces are the hardware serial interfaces. Each one connects to a UART on the module, and depending on your hardware interface, these may be connected to a USB port or serial port. The one I used had SER1 connected to a RS232 port, and SER2 was 3.3volt TTL available on the large header connector on the bottom. AT commands can be sent directly into the SER, and data can be routed out from the SER interface.

GPIO is for controlling the limited I/O available on the module.

MOD is important because this has functions such as sleep and the watchdog timers.

SPI, IIC, and GPS are designed to control their respective functions. Just a quick explanation for those unfamiliar; SPI and IIC are chip level communication protocols, and are only useful if interfacing to other hardware.

Any library can be used by importing them at the beginning of the script.

import MDM
import SER
import GPIO

MDM/MDM2

These libraries are identical, but just access different AT instances. The really important parts of these two are the send and receive commands.

MDM.send(string,timeout)

The send command is used to send AT commands to the unit for instance.

A = MDM.send(‘AT+CMGR=1\r’,5)

It returns a 1 if successful, or a -1 if the timeout is reached. The timeout is in 1/10th of a second. So the example would wait 0.5s before timing out.

It will not return what the AT interface returned; to read this, you will need the receive command:

b = MDM.receive(10)

This will assign b with the receive buffer after a timeout of 1.0s. The library has functions to support sending and receiving individual bytes as well. The Python side is the easy part to learn. Learning the hundreds of AT commands the device responds to will take the longest. With the MDM interfaces and the SER interfaces to interact with the hardware, you’re on your way to starting a project. Future articles will cover more specific functions such as opening a telnet session or sending an SMS message, but for now, these are the fundamentals needed to add cellular functionality to your next project.

For lists of AT commands and more specifics on all the functions discussed here, a good resource is the Telit website. All documentation relevant to the GC864-Quad which is the module I used can be found here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionGPS data Pin
jernejgoricki15-Aug-11 3:28
jernejgoricki15-Aug-11 3:28 
Generalcan't activate script Pin
pmdomotics17-Oct-10 4:23
pmdomotics17-Oct-10 4:23 
GeneralCan' enable script Pin
pmdomotics17-Oct-10 4:22
pmdomotics17-Oct-10 4:22 
GeneralRe: Can' enable script [modified] Pin
jonbowen23418-Oct-10 9:48
jonbowen23418-Oct-10 9:48 
GeneralRe: Can' enable script Pin
pmdomotics21-Oct-10 9:09
pmdomotics21-Oct-10 9:09 
GeneralRe: Can' enable script Pin
jonbowen23425-Oct-10 4:30
jonbowen23425-Oct-10 4:30 
GeneralRe: Can' enable script Pin
pmdomotics25-Oct-10 21:42
pmdomotics25-Oct-10 21:42 
GeneralRe: Can' enable script Pin
jonbowen23426-Oct-10 3:28
jonbowen23426-Oct-10 3:28 
GeneralRe: Can' enable script Pin
pmdomotics27-Oct-10 7:13
pmdomotics27-Oct-10 7:13 
GeneralRe: Can' enable script Pin
jonbowen23429-Oct-10 3:12
jonbowen23429-Oct-10 3:12 
GeneralPython code example for Telit modems Pin
x89320-Sep-10 7:43
x89320-Sep-10 7:43 
GeneralRe: Python code example for Telit modems Pin
hasmodai7-Oct-10 1:33
hasmodai7-Oct-10 1:33 
GeneralRe: Python code example for Telit modems Pin
x8937-Oct-10 1:49
x8937-Oct-10 1:49 
GeneralRe: Python code example for Telit modems Pin
jonbowen2347-Oct-10 5:03
jonbowen2347-Oct-10 5:03 
GeneralRe: Python code example for Telit modems Pin
hasmodai7-Oct-10 20:33
hasmodai7-Oct-10 20:33 
GeneralRe: Python code example for Telit modems Pin
jonbowen2348-Oct-10 5:05
jonbowen2348-Oct-10 5:05 
GeneralRe: Python code example for Telit modems Pin
hasmodai10-Oct-10 19:58
hasmodai10-Oct-10 19:58 
GeneralRe: Python code example for Telit modems Pin
jonbowen23411-Oct-10 2:39
jonbowen23411-Oct-10 2:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.