I spent half a day setting up a demo RapidSMS system using Ubuntu 10.04, a Multitech MTCBA-G-U-F4 modem, and the RapisSMS-XForms application. I’m new to RapidSMS and revisiting DJango after many years so this will be the first of several posts documenting how I setup RapidSMS to accomplish various needs for mobile data collection in Nigeria.
RapidSMS on Ubuntu 10.04 with MultiTech MTCBA-G-U-F4
- Connect and Configure MultiTech Modem
- Install the Python Environment
- Installing pyGSM
- Installing RapidSMS
- Configure RapidSMS and RapidSMS-XForms
- Add a RapidSMS Project
- Add the MultiModem GSM Backend
- Add the XForms App
- Starting Up RapidSMS
- Getting Stated Collecting Data
Connect and Configure MultiTech Modem
Connecting to the MultiModem from Ubuntu is easy using the screen command.
screen /dev/ttyUSB0 115200,ctsrts
From here you can issue AT commands to view the modems status, configuration, as well as read and send messages.
AT+CREG? [enter] will tell you the status of the modem. The response 0,1 is typically what you are looking for.
To use the modem in Nigeria I needed to change the GSM band.
After this step I needed to disconnect and reconnect the modem for it to receive and send SMS messages.
Confirming that you can send and received SMS messages or even establish voice calls is a good next step before proceeding to installing and configuring pyGSM and RapidSMS. See the MultiModem guide referenced below for the SMS Examples (pg 27) and Establishing a Voice Call (pg 26) sections.
To end the MultiModem terminal issue the ctrl+a k and press y to confirm the killing of the session.
Install the Python Environment
sudo apt-get install python-setuptools python-dev build-essential
sudo easy_install pip
sudo pip install –upgrade pip
You will also need git installed (sudo apt-get install git-core) and the sqlite3 packages (sudo apt-get install sqlite3 sqlite3-doc).
sudo pip install pytz (an additional library needed by pygsm)
Retrieve the pygsm sources from the rapidsms repository on github and unpack to the /usr/local area for easy system access.
sudo git clone http://github.com/rapidsms/pygsm.git
Compile and Install pygsm
sudo python setup.py install
To check to make sure pygsm is working normally you can run the pygsm_demo program.
pygsm_demo /dev/ttyUSB0 baudrate=115200 rtscts=1
I installed the RapidSMS from the github repository using
pip install git+git://github.com/rapidsms/rapidsms.git#egg=RapidSMS
To be able to quickly create forms in installed the rapidsms-xforms app
pip install django-uni-form
sudo pip install rapidsms-xforms
Configure RapidSMS and RapidSMS-XForms
TODO: Understand what virtualenv settings are for
Add a RapidSMS Project
> cd ~
> mkdir ~/workspace
> rapidsms-admin.py startproject myproject
> cd myproject
Add the MultiModem GSM Backend
Edit settings.py (gedit settings.py) and add the following to the INSTALLED_BACKENDS section
Add the XForms App
In settings.py you need to add the following to the INSTALLED_APPS section:
INSTALLED_APPS = ( “rapidsms”,
.. other apps ..
In the instructions for XForms the is a step to configure the TABS section. However neither of the two configurations available in the documentation work without errors. TODO: Find a fix for this or find the correct configuration.
TABS = [
.. other tabs ..
TABS = [
.. other tabs ..
Starting Up RapidSMS
To configure and setup the database (default is sqlite3):
python manage.py syncdb
Run the the RapidSMS/DJango development server
python manage.py runserver (starts a server on the localhost using port 8000, this is only accessible on the local machine)
python manage.py runserver ipaddr:port (will run the development server on the specified ip address and port, allowing connection from other machines on the local network).
Startup the Message Router in a different terminal or screen session.
python manage.py runrouter
Getting Stated Collecting Data
You should now be able to send and SMS to your Modem’s number and receive a response (most likely “Sorry, RapidSMS could not understand your message”).
These messages will show up in the Message Log (ie http://192.168.25.209:8000/messagelog/). To get data into the RapidSMS using the XForms app we need to visit the XForms ADMIN area (ie http://192.168.25.209:8000/admin/rapidsms_xforms/).
- Add a New XForm. (ie ‘friends’, with the response ‘Your friend added!’)
- Add several XForm fields. (ie ‘name’, ‘age’, ‘phone’)
When these fields are added you can now send an SMS to your modem and have the input received successfully.
SMS: friends +name Adam Thompson +age 27 +phone 123456789
You can check the Message Log and ‘x form submissions’ to see if your data was successfully received and you should also receive your confirmation SMS.
- Installing RapidSMS on Ubuntu 9.04 Jaunty
- Multi-Tech Wireless Modems Getting Started
- MultiModem® GPRS USB Wireless Modem MTCBA-G-U-F4
- Installing RapidSMS in Debian Based Linux for development
- RapidSMS-XForms github repository README
- RapidSMS-XForms Documentation