Module software support includes GSM module library and an example of its typical usage for ATMega microprocessor family written in C/C++. The logic of interaction with SIM900D modem is enclosed in SIM900Modem.c, SIM900Modem.h
files and relies on enhanced version of HardwareSerial
class originally designed for Arduino project. As SIM900Modem.c
does not depend on AVR specific features it may be quite easy adopted for different microprocessor types. The library has the following low level functionality to control the modem:
- switch it on and off,
- send AT commands and analyse responses,
- extract certain parts from modem’s replies and convert them into other representations and formats.
On top of this logic more meaningful commands are implemented such as:
- getting manufacturer ID,
- getting IMEI,
- getting model ID,
- texting,
- waiting for GSM network registration,
- getting network operation,
- opening/closing GPRS content,
- etc.
Also there are two sets of methods, for sending data via HTTP and TCP protocols.
The first set utilises HTTP related AT commands, it hides a lot of things from end user and therefore much simpler for use. However, it does not allow to define arbitrary HTTP header and as a consequence, there is no way to send MIME-encoded POST requests and therefore no way for sending binary data such as pictures. In addition, the the commands do not provide functionality to set HTTP parameters separately and it is entirely user application responsibility to do URL-encoding. There is also no way to get response HTTP header fields, they are hidden by the modem. Yet this is fairly simple way to make HTTP requests by means of dedicated HTTP AT commands, the commands provide the following functionality:
- initialising HTTP request,
- setting target URL request,
- setting user data parameters and values,
- choosing action (either GET or POST),
- reading data,
- terminating connection.
The second group of methods facilitates sending/receiving data over TCP/UDP protocols and HTTP request might be generated on top of TCP. This way is more complex, it requires more efforts on user application side and utilises more RAM for intermediate buffer. At the same time it gives you all flexibility you need without limitations in number of parameters and binary data length as requests are sent by chunks. The following functionality is provided:
- starting IP connection,
- getting assigned local IP address,
- getting GPRS PDP status,
- sending data,
- getting HTTP response,
- parsing HTTP server current timestamp (for RTC synch),
- closing IP connection.
Let’s take a closer look at the list of commands starting from low-level layer:
uint8_t SIM900Modem::init()
initialises modem and powers it up it it has not been switched on yet via PWRK line. If this method returnsfalse
then there is something wrong with either modem itself or its connection to your microcontroller. Check SIM900D voltage, normally it should have 3.7V on 38-39 pins; then check serial connection to your host board and finally make sure that host board can control PWRK and has serial port properly initialised,uint8_t SIM900Modem::powerOff()
switches the modem off by sending appropriate AT command. In case if the modem stopped responding (very rare situation but still possible) use the next command,void SIM900Modem::forcedPowerOff()
switches the modem off by controlling PWRK line, works even if the modem is unresponsive to AT commands,uint8_t SIM900Modem::sendATCmdWaitResp(const char* cmd)
sends AT command and waits for eitherOK
orERROR
reply. If nothing has been received withinMDM_TIMEOUT x 100 ms
timeframe returnsfalse
. IfOK
has been received returnstrue
.cmd
param should not haveAT
prefix as it is appended automatically inside the method,uint8_t SIM900Modem::sendATCmdWaitResp_p(const prog_char cmd[])
does the same as the method above but readscmd
from program memory,uint8_t SIM900Modem::sendATCmdWaitResp(const char* cmd, const prog_char expectedResp[], uint8_t delayCntr)
allows to wait for modem reply different fromOK
orERROR
. It also waits longer, fordelayCntr x 100 ms
in addition to standardMDM_TIMEOUT x 100 ms
,uint8_t SIM900Modem::sendATCmdWaitResp_p(const prog_char cmd[], const prog_char expectedResp[], uint8_t delayCntr)
does the same as the method above but readscmd
from program memory,uint8_t findSubstr(const ring_buffer* buf, uint16_t len, const prog_char expectedResp[], uint16_t* posFound)
searches a specified string in receiving buffer without actual reading it, the number of bytes in buffer is defined bylen
value. If the method returnstrue
thenposFound
contains an index of a first byte of the searched string. Note that this method does not allocate memory forposFound
, it should be done by user code,uint8_t SIM900Modem::extractReply(char* outBuf, uint16_t len, uint8_t line)
extracts a line of characters from modem receiving buffer into provided bufferoutBuf
with maximum number of characters to be copied defined inlen
. The desired line number isline
. The method returns number of characters copied andoutBuf
filled with copied characters in case of success.
A list of auxiliary methods is given below:
uint8_t SIM900Modem::getManufacturerID(char* buf, uint16_t len)
gets modem’s manufacturer ID,uint8_t SIM900Modem::getModelID(char* buf, uint16_t len)
gets modem’s model ID,uint8_t SIM900Modem::getTARevision(char* buf, uint16_t len)
gets modem’s revision,uint8_t SIM900Modem::getIMEI(char* buf, uint16_t len)
gets modem’s IMEI number,uint8_t SIM900Modem::getNetworkRegistration()
returnstrue
if modem has successfully registered in GSM network andfalse
otherwise,uint8_t SIM900Modem::waitForNetworkRegistration()
waits until modem is registered in GSM network but no more thanMDM_TIMEOUT x 3000 ms
,uint8_t SIM900Modem::getNetworkOperator(char* buf, uint16_t len)
gets GSM operator name.
Methods for SMS functionality:
uint8_t SIM900Modem::setTxtSMSMsgFormat()
hardcoded for setting txt message format, should be invoked every time modem is restarted before sending/reading SMS,uint8_t SIM900Modem::setGSMCharSet()
hardcoded for settingGSM
charset, should be invoked every time modem is restarted before sending/reading SMS,uint8_t SIM900Modem::sendSMS(char* destAddr, char* msg)
sends a text messagemsg
to a phone addressed by numberdestAddr
, returnstrue
in case of success.
A list of methods for making HTTP connections by means of embedded HTTP AT commands:
uint8_t SIM900Modem::openGPRSContext(char* buf)
opens GPRS context,buf
parameter containsAPN
string.APN
is different for different mobile providers, for instance, APN value for Australian Vodafone isvfinternet.au
. Returnstrue
if GPRS context has been openedfalse
otherwise,uint8_t SIM900Modem::closeGPRSContext()
closes opened GPRS context, returnstrue
in case of success,uint8_t SIM900Modem::httpInit()
initisalises HTTP request,uint8_t SIM900Modem::httpSetURL(char* buf)
sets URL to connect to a remote HTTP resource,uint8_t SIM900Modem::httpSetData(char* buf, uint16_t len, uint16_t timeout)
sets HTTP user data,buf
parameter contains a string of URL-encoded parameter-value pairs withlen
characters in the biuffer,uint8_t SIM900Modem::httpAction(uint8_t isPostMethod, uint16_t* responseLen)
does actual sending of HTTP request and reading of HTTP reply.isPostMethod
set totrue
creates POST HTTP request and GET otherwise,uint8_t SIM900Modem::httpRead(char* buf, uint16_t startIdx, uint16_t len)
reads HTTP reply, this method is not implemented in Rev1.1 GPS/GSM AVR Libraryuint8_t SIM900Modem::httpTerm()
closes HTTP connection, should be invoked at the end of each HTTP request.
A list of methods for making HTTP connections over TCP AT commands (which is primarily used by the example):
uint8_t SIM900Modem::startSingleIPConnMode()
issuesAT+CIPMUX=0
command to handle only one TCP connection at a time, should be invoked before even opening GPRS connection,uint8_t SIM900Modem::setGPRSPDPAPN(char* apn, char* username, char* pwd)
sets APN value, username and password. If username and password are not required by your mobile operator these two parameters might be set toNULL
,uint8_t SIM900Modem::actGPRSPDPContext()
opens GPRS context and returnstrue
in case of success orfalse
otherwise,uint8_t SIM900Modem::deactGPRSPDPContext()
closes opened GPRS context, returnstrue
in case of success,uint8_t SIM900Modem::getLocalIP(char* buf, uint16_t len)
retrieves local IP address after successfully opened GPRS context and puts it intobuf
buffer with maximum length no longer thanlen
,uint8_t SIM900Modem::sendIPConn(char* buf, uint16_t len, uint16_t delayCntr)
sendslen
bytes frombuf
to remote side and waitsdelayCntr x 100 ms
in addition to standardMDM_TIMEOUT x 100 ms
,uint8_t SIM900Modem::sendAndCheckHTTPRespIPConn(char* buf, uint16_t len, uint16_t bufsize, uint16_t delayCntr, RtcTimeType* rtc)
sendslen
bytes frombuf
to remote side, retrieves remote side response, puts it intobuf
with maximum lengthbufsize
, searches forHTTP/1.1 200 OK
orHTTP/1.0 200 OK
in reply content and if found parses server current datatime in UTC format into providedRtcTimeType
variable. This method should be used for sending the very last block of data of your HTTP request,uint8_t SIM900Modem::closeIPConn()
is currently not used as sometimes modem becomes unresponsive after it. Useuint8_t SIM900Modem::deactGPRSPDPContext()
method, it automatically closes opened IP connection if it has not been closed already by remote side.
To be continued…
Hello,
I visited your website and I am extremely and pleasantly surprised by the quality of its content and I congratulate you for all that.
First, let me introduce myself. I’m Koné, I am a student in business school in the south of France.
I am contacting you to seek your assistance in a project mixing electronics and telecommunications and in the framework of a humanitarian project.
In fact, I want to design an electronic box that would serve “poor” people in Africa.
Many people in Africa suffer from both a geographical separation (rivers, deserts, dense forests, …), or political (borders, wars, conflicts, …) pushing members of the same family not being able to meet. Add to that, these limitations, combined with poverty, reduce the access of these populations to the growth and development of the world economy.
Having done a little research with African friends students in France, it turns out that mobile networks are often present as fixed networks are almost inextants.
My project can be summed up as follows:
I intend to install in some big african cities an electronic and autonomous box able to connect one side to other similar boxes using internet (adsl). These boxes should serve as a bridge to the GSM/3G network (ideally 16 or 32 simultaneous channels). In remote villages, I intend to install a small box mounted on a wall using the GSM/3G network to make and receive calls using the cases installed in major cities. These little boxes will be managed by local associations. People will be able to call their families at low cost (using the Internet) and also build their small economic ties to improve their financial resources.
So, I contact you to hope that you could help me in the design of this technical solution. I have a friend who helps me in electronic issues and our current concerns are as follows:
1-What processor to choose to have embedded linux and asterisk and ideally for 16 or 32 simultaneous calls sip-gsm (if we can put only 8 channels, we will have to install at least 2 boxes per major city)?
2- Can we use boards like alix, OpenVox, … ?
3 – We do not know how to connect several gsm/3g modules on the motherboard where there will be the processor.
My goal is to make these boxes for less than one 1000euros order to install 10 boxes in the first place. Since this is a personal investment, I wish I won’t have to exceed this limit because my budget is 10000euros at all (for 10 boxes using ideally 16 simulatenous gsm channels and expandable to 32).
I saw that there are gateways gsm-sip that look a bit like what I want. But they are too expensive and do not correspond exactly to the fact that it is autonomous, ie without the presence of a computer that manages communications using asterisk.
I hope I was clear enough and sincerely hope that you adhere to my project and that you would help me to achieve these boxes …
Thank you in advance for your help and your understanding …
Koné
Hi Koné,
Sorry for such a long delay and thank you for your comment.
I believe that your questions are not topical anymore but I will try to address them anyway.
First of all, you are trying to design and deploy something on a global scale (‘in … big african cities’). This task is not for a few enthusiasts but for serious businesses if not corporations – basically, you need major investments. Secondly, you are trying to cover… what? GSM networks, voice over IP telephony or internet or all of them? It sounds like reinventing wheel. And at the same time you are trying to reuse already existing (?) infrastructure, such as GSM networks and internet services (which is not even available in most of African locations). How are you going to achieve ‘low cost calls’ if you project heavily relies on the above mentioned things and at the same time you add extra hardware on top of it which, in its own turn, needs maintenance and therefore additional costs.
You are trying to make industrial things that already exist (yes, they are expensive but they de-facto standards and they work) using some kind homemade components – it is just not going to work, believe me. At this stage it is pointless to choose hardware without knowing the actual system’s requirements, the overall picture and kind of services the system is required to provide.
Regards,
Dmitry
Hello Sir/Ma’am,
I, Nitin Gote working in Ahmedabad placed Company called Hidden Brains Infotech Pvt Ltd.
I want to buy this GPS/GSM Modem for my project. Also need the datasheets of this modem and
the SIM900D module. So, please guide me to meet my requirement.
I look forward to hearing for you.
Regards,
Nitin Gote
Hi Nitin!
Thank you for your comment.
Unfortunately, GSM/GPS module is a non-stock item. On ‘Kits for sale’ at http://magictale.com/kits-for-sale/ its status is marked as ‘End of life’.
I believe that the quantity that you’re after is one-two items so it is just not enough for us to manufacture a new batch.
However, it is an openhardware project – you can find Gerber files at http://magictale.com/711/gpsgsm-module-pcb-component-layout/ so you can basically manufacture the module yourself. Bill of materials, circuit diagram, how-to guide, firmware support – all this is also available for free, take advantage of it.
Thank you,
Dmitry
Hi Dmitry,
Thanks for reply and suggestion. You saved my time.
Thank you,
Nitin