Connecting to the Internet via GPRS
by Khaled Raed Sharaf on Feb.06, 2010, under GSM/GPRS
Now lets get this party started!
OK, now we are ready to go into details on how to make an internet connection from the PIC18F450. This sounds fun!
We need some login information that enables us to access the internet. This is called by the network provider “internet settings” , “internet setting file” or something like that. For example if you bought a brand new Nokia phone, and when you insert the SIM card into it, some providers sends the internet settings as soon as they detect that this phone is for the first time to be connected to there network (they do that by IMEI). Other providers, you have to call the customer service so that they send you the internet settings. So, we really need to know the contents of the internet setting file that the provider send so that we can know: APN, username and password.
Before going into details, the first thing that you must do, is call the customer service from the SIM that you are going to use from any cellular phone, and ask them if SIM is GPRS enables or not. Because some providers are not default enabled, so you need to call them first.
What is APN?
It stands for Access Point Name. This name gives you a gateway rout to the network that you want to connect to like WAP or internet or VPN. The question now is how am I going to get the APN of my network provider?
Two ways to get the APN:
1- You can go to MIG33 (link below). This website shows a table of all APNs with username and password of all cellular provider around the globe. But the problem is, it might not be updated. So try it out first and if things work then skip the second way.
CLICK HERE
2-Another way to get the APN, username and password from the operator customer service. But the thing is, they will want to know your phone model, and if you say TELIT they will go like “what….??” or they will say “you will not be able to access the internet with this phone” or any excuse which has no meaning. They best way to do this is to tell them that you have an i-MATE phone version 6.0, or any pocket PC that has a windows mobile edition on it, and you need to configure it manually. Ofcourse you don’t need a phone like this. Just get a piece of paper and a pen, and go with them through the steps (something like: Go To start->settings… and so on). And then they will tell you for the “APN” or “Access Point Name” type something, so you need to write this down, and then for the username and password you need to write it down as well. Note that some providers leaves the username and password blank so don’t be surprised. Now you should have APN, username and password (if they are needed) on a piece of paper.
Think of connecting your Telit module to the internet as connecting the 56k modem to the internet (back to these miserable days
). In the GPRS manual it gives you an example on page 54, using the new AT commands that they have added to the module. I tried this example, but I had no luck at all to make the module connect to the GPRS. So, instead I used the old AT commands that actually do the job just perfect!
Telit Easy GPRS User Manural Guide
AT+CGDCONT=1,"IP","ETISALAT"\r OK AT#USERID=""\r OK AT#PASSW=""\r OK AT#GPRS=1\r +IP: 10.254.3.1 OK AT#SKTD=0,80,"www.embed21.com"\r //Delay: This delay depend on how fast your network connects you to the internet. CONNECT GET / HTTP/1.1\r\n Host: www.embed21.com\r\n Connection: keep-alive\r\n \r\n //DELAY: This delay depend on the GPRS class (your GPRS speed) and the webpage size. HTTP/1.1 200 OK Date: Sat, 06 2010 10:21:58 GMT Server: Apache/1.3.27 (Unix) Last-Modified: Sat, 06 2010 10:21:58 GMT Content-Type: text/html Connection: close <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN"> <HTML> //Here where the html of our page show up </HTML> //As you want to go to the command prompt of the module you shall use the following code to escape +++ //delay or sometime called pause in the manual /r
In my case my network provider has an APN “ETISALAT”, so what you should do is, you will have to rename it, and put your network APN. Etisalat, doesn’t need a username or password to access the GPRS, but in most other countries you will need a username and password, so double check first before leaving it blank.
When we send At#GPRS=1, it replies back with a local IP address, when you obtain this IP address then this means that you are successfully connected to the internet.
All what is left is some socket programing and HTTP requests, and this can be shown as a above.
The problem that I am still facing till now is; the socket makes the first connection to the web page successfully and return a 200 code. GREAT!! But when it access the website one more time, it gives me a 402 error and sometime other errors. One person told me that this problem is due to the server, as it closes the session and he tried it on a Java EE server, and he had no problem at all, but when he tested it on an Apache web server this problem showed up, but I will have to investigate and double check if that is true or not.
So if you know the solution to this problem please tell us how to solve it.
If you have questions please post them here.



February 7th, 2010 on 1:06 AM
First of all. thank you very much for this tutorial.
>GREAT!! But when it access the website one more time,
>it gives me a 402 error and sometime other errors
do you mean socket dialing 2nd time or sending request headers 2nd time ? For me,doing the later one again shows some error. SO, whenever i want to ping a website i do both. but still after html is seen it ends with NO CARRIER (may be i’m missing the Line 38 & 40 of your code. guessing what it means!!??)
February 7th, 2010 on 5:04 AM
I mean both, as I have tried to use socket dialing and sending multiple HTTP requests. I have tested several method using the socket dialing. I used socket number 1 and obtained the data that is returned successfully. But when I use socket number 2 to access the same website it gives an error.
So is your server running on Apache or not?
Line 38 & 40: +++ is an escape sequence to get back to the command mode.
February 8th, 2010 on 10:24 PM
i thought when you post comment it’ll send alert mail.but it didn’t. I came back to see the comment.
>used socket number 1 and obtained the data that is returned
>successfully. But when I use socket number 2 to access the
>same website it gives an error.
oh! i didn’t try this one. As pinging the website once (on one socket) was enough for me. (..Guessing why dialing 2nd time on 2nd socket !!?? )
>So is your server running on Apache or not?
ya.its Apache version 2.2.14
February 8th, 2010 on 10:43 PM
Hello Rajesh,
I am not enabling the option of sending emails. Sorry about that.
Now, as I said, I was testing to access the website more than one time. I tried to use the same socket, but no luck. And tried to use another socket and still doesn’t work. So everything might seem beautiful from the first PING or HTTP request. But did you try to rePINGing the website again for a 2nd or 3rd time??
February 8th, 2010 on 11:20 PM
no i haven’t. i’ll check it & reply back
February 10th, 2010 on 5:17 PM
This is a great web site that that was referenced in a sparkfun link. I want to purchase a Telit GSM/GPRS and intially wanted the 862 with the sparkfun breakout board as it seemed to be the easiest way to get started using hyperterm on a PC before moving to a PIC. But sparkfun is not selling the 862 anymore but they do have a full breakout board for the 863 and 864. From what I have read on your web site the power supply can be tricky to set up and a breakout board seems to handle all this for you. From what I read all 3 units seem very similar in their command sets. I need to be able to send SMS data, and also FTP data to a web site. Do you know if the 862,863 and 864 will all do this ? Thank you !
February 10th, 2010 on 8:39 PM
AT+CGDCONT=1,”IP”,”internet”,”0.0.0.0″,0,0
Received:
OK
AT#USERID=”web”
Received:
OK
AT#PASSW: =”web”
Received:
OK
AT#GPRS=1
Received:
+IP: 10.94.6.164 OK
AT#SKTD=0,80,”www.google.ie”
Received:
CONNECT
Then A Delay Then
NO CARRIER
—————————————————-
As you can see i am recieving no data from web page, any ideas, it worked a couple of times and then stopped
February 10th, 2010 on 11:20 PM
@Jim Kruk
First, I will only talk about the GM862 because I have tested about everything in it.
In the GM862 you can make FTP, HTTP, SMTP (TCP) and UDP connections via GPRS and you can make Phone calls, send SMS and Data calls.
Now opening the datasheet of GM863 and GM864, they basically have the same specs, but what is different in them (in my point of view) is the Ball-Grid-Array (BGA) as it reduces in the board size and it will be a bit of a hassle to get it connected to the board. But this will not affect you that much, as you will buy a breakout board from sparkfun which will be already connected to the board. So it is a matter of physical property.
So, in my point of view, you can go for the GM863 or GM864. Test your code and get everything working fine. And yes you can move your AT code from one GM module to another GM module as they uses the same AT commands.
I hope I was helpful, and if you have any questions please don’t hesitate to ask!
February 10th, 2010 on 11:25 PM
@Derek Hodge,
I think you miss understood the code, or it seems that I wasn’t clear in writing it.
After you received the CONNECT message you are allowed to send HTTP request to the server. So what you need to do is add the following line after you get the CONNECT message.
GET / HTTP/1.1\r\n
Host: http://www.google.ie\r\n
Connection: keep-alive\r\n
\r\n
You might have thought that this was something that you receive from the server. But no, this is a request that we send to the server. This is also done by our web browsers as well.
Keep me updated when it works!
February 16th, 2010 on 12:12 AM
sorry for late.i have not tried my modem for more than a week. ya! when i request for the second time it shows some error. but not exactly 402. I’ll try find a solution & share with you
February 16th, 2010 on 12:03 PM
I was connecting but there was no time before no carrier came up.
Its all working now.
Ref only being able to access the website once, I had the same problem and have a solution.
It seems that if you repeatedly use the same url it gives a problem so i pass a parameter in the url which is ignored by the server, i change this parameter each time and hey presto it works.
Have been connecting repeatedly to the same page for 2 hours now.
I wonder though why I had to do it in this way, any thoughts would be appreciated.
February 24th, 2010 on 8:53 PM
Just thought i would send an update.
Comms every minuite with the same webpage has now worked for 6 days.
Any feedback on the above post would be greatly appreciated.
February 24th, 2010 on 9:22 PM
Hello Derek,
Just a question, you said that you pass a parameter that is ignored by the server.
for example:
http://www.embed21.com/index.php?l=1
where l is the ignored variable,
then in the second url I write:
http://www.embed21.com/index.php?l=2
and so on…
Is that what you are trying to say??
As I said in the article, I had no solution for this problem at all, and I was in dead end.
March 25th, 2010 on 11:35 PM
Hi there!
I’m trying the procedure that you (Khaled) describe above. The problem that when I type AT”SKTD=0,80,”www.google.pt” I can’t get the CONNECT response from GM862. I wait more than 5 minutes and nothing. The GM862 does not shut down… it seems to hang while the status led blinks with an interval of 3 seconds. The access point name, userid and password are right cause they where given by the operator.
I can’t see where is the problem… can you help on this one? Thanks
March 27th, 2010 on 7:35 PM
Sorry Diego for my late reply, as I was having some exams
Ok did the module reply you back with the IP when you send this command AT#GPRS=1 ?
waiting for your reply…
March 28th, 2010 on 11:29 AM
Thanks for the reply.
Yes, I get the IP response. All the following steps run successfully:
AT+CGDCONT=1,”IP”,”internet”,”0.0.0.0″,0,0
OK
AT#USERID=”"
OK
AT#PASSW: =”"
OK
AT#GPRS=1
+IP: 95.69.38.252
OK
When I send: AT#SKTD=0,80,”www.google.pt” or try to access to my personal webserver, I get nothing from the module and I need to reset. Hyperterminal seems to wait for the module response and doesn’t let me send more instructions.
I tried to call the network operator but can’t get any help because they don’t know the module.
Do you have any ideia what is happenning?
March 28th, 2010 on 12:05 PM
Hey Khaled,
Now I got this:
AT#SKTD=0,80,”www.google.pt”
+CME ERROR: can not resolve DN
Any clue?
March 28th, 2010 on 4:05 PM
Tell you what Diego,
Take your SIM card, and try it on your phone with the same configuration setting, and see if it access the website or not…
I think that this is a WAP connection not an internet connection…
Preferable to use a windows CE phone where you have to put the configuration with manually.
Try it and tell me if your phone does access the website or not.
March 28th, 2010 on 11:39 PM
Well, I have access to the website with my cell phone. But can’t figure it out if it is a WAP connection or not. Tomorrow I’ll try another SIM card from other network… I’ll let you know the results.
Thanks Khaled
March 30th, 2010 on 9:15 PM
Hey Khaled!
No luck with the new SIM card, but I made some progress. I tried de command AT&K0 during the RS232 configuration then I connected to the GPRS network and receive the IP response… like before. But now I also have the CONNECT and some time later receive the NO CARRIER response. The problem is during that time I can’t write anything (like GET / HTTP/1.1)…
I don’t know what is happening again lol. What you think about this?
April 26th, 2010 on 5:46 AM
I was connecting but there was no time before no carrier came up.
Its all working now.
Ref only being able to access the website once, I had the same problem and have a solution.
It seems that if you repeatedly use the same url it gives a problem so i pass a parameter in the url which is ignored by the server, i change this parameter each time and hey presto it works.
Have been connecting repeatedly to the same page for 2 hours now.
I wonder though why I had to do it in this way, any thoughts would be appreciated.
April 26th, 2010 on 12:32 PM
Hi there!
I’m trying the procedure that you (Khaled) describe above. The problem that when I type AT”SKTD=0,80,”www.google.pt” I can’t get the CONNECT response from GM862. I wait more than 5 minutes and nothing. The GM862 does not shut down… it seems to hang while the status led blinks with an interval of 3 seconds. The access point name, userid and password are right cause they where given by the operator.
I can’t see where is the problem… can you help on this one? Thanks
April 26th, 2010 on 1:54 PM
I was connecting but there was no time before no carrier came up.
Its all working now.
Ref only being able to access the website once, I had the same problem and have a solution.
It seems that if you repeatedly use the same url it gives a problem so i pass a parameter in the url which is ignored by the server, i change this parameter each time and hey presto it works.
Have been connecting repeatedly to the same page for 2 hours now.
I wonder though why I had to do it in this way, any thoughts would be appreciated.
May 1st, 2010 on 8:00 PM
Hi Khaled,
i have a partial success in sending continuous request with using different during the socket dial [u already mentioned it in your 2nd reply. I really understand your words better now than my 1st time read]. my question on your code is
1.why do u suspend your connection using “+++”
2.did u get the reply as OK for using the above
3.In line 40 /r [ordinary slash]. is it really that or u misspelled the “\r”
4. If 3 in correct, is the line 40 essential is suspending the connection
5. how far your are doing ? have you succeed in sending multiple request
May 1st, 2010 on 11:33 PM
Hello Rajesh,
Long time no see…
1-I did suspend the connection to do something else on the module.
2-What “above” are you talking about??
3-Yes it is written wrong, it is \r!
4-I tried some advice to send a changing variable each time I make a request but no luck. Another one told me that this is a problem from the server, but I really want to a know a website or a server that doesn’t close the connection. In other words it makes the connectiontype: keep-alive… so do you any??
May 2nd, 2010 on 7:56 AM
Hi,
i was busy with regular college works last few months. Moreover my server was down for few weeks. It took this much time to get back to normal.
what i meant was after you send “+++” did get the “OK” response. Are you sure that connection socket was suspended. I mean did you get “SRING” notification. or did it show up in “AT#SS”. suspending seems to be not not working for me.
Because instead to doing thing in different socket. suspending and resuming the same would make things easy. I feel hard believe that server would be responsible for this failure on sending repeated request. If time permit i’ll try that too.
no success yet for me. but i’m trying hard to figure out…
May 10th, 2010 on 3:20 AM
Hi Khaled,
Great site – been very helpful.
I got it working more or less ok using some of the new commands as follows:-
at#gprs = 1 //set gprs – returns with IP number
at#sktd = 0,80,”www.gsmmadeeasy.com” //socket dial
//replies with Connect
//Now type in the HTML
GET / HTML/1.0
Connection: keep-alive
Then the page comes down..but it then does a No Carrier. No worries just do the at#sktd again.
May 10th, 2010 on 3:22 AM
OOPS error in my last post..
correct line is
GET / HTTP/1.0
May 10th, 2010 on 10:56 AM
Hello John,
So you are saying that if I changed the HTTP/1.1 to HTTP/1.0, this will make it work?
Do you know why?
Anyways, I will give it a try and reply you back.
May 11th, 2010 on 7:51 AM
Hi Khaled,
Congratulations on the awards!!!!
As per your comment above … no, I really have no idea why.
I got the sequence of commands from the RoundSolutions RSTERM Hyperterminal. When I use 1.1 I get a “Bad request” response.
As you pointed out in an earlier posting it is important to terminate each HTML line with a cr and lf as well as having a cr and lf at the end. Some hyperterminals do not seem to do the cr and lf when you press the enter key. To be sure I use ctrl-m and ctrl-j, very little of the literature makes this as clear as you have in your earlier post.
Best wishes from sunny Melbourne
May 17th, 2010 on 1:41 AM
Hello John,
Sorry for my late reply…
I really want to go and test the modification that you made. But right now, I am stuck with my final exams
So wish me luck!!
Did you insert any changeable variable with the HTTP request or not?
If this thing did work, I will make a special blog post just for you!!!
Once Again thank you!