I have a GSM module sim900A. How i could connect my pi to internet via that module. this module is connected to usb port and i am able to send sms from it. Now kindly help me to connect internet via it. i am using following code to send sms.

    gsm=serial.Serial("/dev/ttyUSB0",baudrate=9600  ,timeout=1.0)
  • What exactly do you mean by "Connect to the Internet" ? Are you trying to connect to a specific website to download pages / upload some data you have on the Pi ? Commented Sep 24, 2016 at 7:03
  • I want to access pi remotely via internet.
    – Akash Nil
    Commented Sep 24, 2016 at 7:12
  • My pi will act as a remote server. it will store some live data to it's mysql database. i want to monitor the data from home. for this i have to put both the computer on internet. for raspberry pi side i want to do this via gprs module. how could i achieve that?? @ Shreyas Murali
    – Akash Nil
    Commented Sep 26, 2016 at 5:51
  • I had left an answer with 2 suggestions - one online and one offline. unfortunately the suggestions did not sit well with certain folks who down voted (i dont mind that) without leaving a comment why (so that i could have improved or corrected). as a result, i decided to delete my answer. i will try to re-write a new answer when i get the time. Commented Sep 26, 2016 at 6:03

1 Answer 1


It is my belief that modules like the SIM900a are intended to enable a device (Pi in this case) to connect to a remote machine, pull or push some data over mobile networks (2G/3G etc). To do that the module will

  • use the SIM card inserted to connect to a mobile network
  • get a dynamic IP address assigned (leased is the term if I am not mistaken) for the duration of connectivity.

Up and down speeds depend on the network and are typically asymmetrical (meaning download speeds are higher than upload speeds)

This mode of usage is pretty much opposite to what you are looking for.

Typically there are number of considerations that would go into configuring a system that is going to be exposed to public such as security, load balancing etc.

Assuming your use case doesn't require such rigorous effort or considerations but just a simple system that allows you to remotely access some information on your Pi from another system, you will need to deal with at least the following

  • have a "server" application that hosts the files (say using apache) you intend to serve or a dynamically generated files (Ruby On Rails, Django or CherryPy using Python, ASP.NET/Mono etc)

  • firewall that limits the ports accessible and controls the request traffic

  • register a domain name and keep the dns current with the dynamic IP address assigned - this is only required during final deployment to allow external machines to find the current IP address. For testing you can skip this and just directly use entering the IP address assigned (by querying the module via AT commands) on the external machine's browser.

this, this and this should get you started.

Couple of things to remember are

  • data transfer up or down on mobile networks are generally much more expensive and or limited compared to wired networks
  • mobile networks might not be as reliable as wired networks (depending on where you deploy the setup)


Update based on comments below

Given the challenges I've mentioned above, Here is how I'd approach the problem

Online setup

I have decribed them in the above 3 bullet points

Offline setup using a intermediate server / cloud storage such as google drive

PI side of things

  • create a (incremental) backup of your MySQL database into a file say named backup_<hh_mm_dd_mmm_yyyy> using a tool such as mysqldump
  • if the backup files are large, use a compression such as 7z or tar.gz to produces smaller backups
  • write a python script the will upload the backup archive to google drive using an API such as this
  • create cron jobs to execute the above 2 tasks every hour or as frequently as required

Desktop side of things

  • connect (programatically if required) to the google drive, check for updates and download the latest backups
  • decompress if required and restore or update a local copy of the database using a tool such as mysqlimport
  • make all queries against the local database in the VB program

some pros/cons of this approach I can think of

  • if there are problems on the Rpi side of things like corrupted file system, h/w failure, bad network etc, at least the last uploaded backups would still be available instead of a completely offline system
  • the client (Desktop) and server(Rpi) are decoupled so it becomes easier to access the data from other client machines
  • as this is a non real time setup the latest data available wont be available until the backup is uploaded and restored on the client machine
  • the cloud service limits will apply on storage capacity and/or total data traffic assuming this is not a violation of the terms of use

Further Updates on SIM900A module

In the spirit of improving on my answer, I dug a little deeper and came across this blog post which describes a similar attempt to host a web server behind a SIM900A module. Sorry to be bearer of bad news but, unfortunately the blogger's experience matches mine own suspicion on the way the module operates. Here's a extract from his blog

Are you thinking to use your SIM900 GSM/GPRS module as TCP server then you should re consider your decision. Because although SIM900 can run as a TCP server and has all the commands and software support inside, it cannot be directly used.

SIM900 supports TCP communication in both client mode and server mode. Client mode is straight forward and you can see the tutorial at this link,


How to get SIM900 running as a TCP server?

Now if you want to use SIM900 as TCP server you need to get its Public IP address and not the one you get when you issue the command AT+CIFSR because it is a local IP address. To get the public IP address you need to connect to some server and note down the IP address shown there.

Shocking part!!

If you are thinking, "Yes, we got the public IP and now we can just configure SIM900 as TCP server and connect to it." ... No you can't !!

I too was shocked when i came to know about this. The network service provider companies don't allow inbound connections, so no external device can directly connect to the SIM900 running as a TCP server. Because they use shared IP addresses and a single public IP address is shared by many more devices like SIM900.

Whats the Solution?

So if you want to use a SIM900 as a TCP server you need to get a private APN and a static IP from the network provider and connect. Its expensive and not affordable for small players and hobbyists. But there is no other option. Without this, its not possible !

Source: Reply from M2M company,

While using our test package, IP addresses are assigned dynamically to the devices because the test package includes our shared APN m2m.tag.com.

this APN we are using the NAT method, which means that privates IP addresses are assigned to the devices, which are NATed to the public IP

Therefore inbound connections to the SIM cards are not possible while using this APN (or any other APN with NAT).

If you need these functionalities ins the future, we recommend to order a private APN with VPN/IPsec connection. Another advantage of a private APN is, that

you can define if the IP address assignment should be dynamic or static.

and more bad experiences.

Even an arduino example hints it might not work which quotes

if you cannot connect to the IP address, make sure your network operator enables incoming traffic.

In conclusion, I also understand the need for such measures from mobile carriers though .. imagine each mobile phone or device with such a sim900a like module potentially becoming a web server (ignoring other concerns such as security), I doubt there are enough ipv4 addresses available.

  • my pi will remain a remote location and store some data to it's mysql database. my home desktop contain a vb program which can show the data from pi. now to access pi i have to put both computer to internet. i want to use gsm module at raspberry pi side to get internet connection.my question is how could i connect my pi to internet via gsm module??
    – Akash Nil
    Commented Sep 24, 2016 at 8:32
  • I have written this answer based on personal experience and it worked for me. To those who wish to down vote, please leave a comment as to why you feel this is a bad answer and I will try to improve/correct it the best i can. Commented Sep 26, 2016 at 6:42
  • Kudos for writing such an elaborate answer! Few remarks though: what you are really saying is "the SIM900 can accept incoming connections but your GSM provider may do NAT and/or block incoming connections" so I would maybe emphasize a bit more that it is a provider problem, not a SIM900 problem - and so people in other parts of the world with different providers may not have a problem at all. Secondly, as you hinted at with "I doubt there are enough ipv4 addresses available", you could try to find a provider that offers ipv6 (and doesn't block incoming connections)?
    – hertitu
    Commented Nov 29, 2016 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.