Access Internet with 8/16 bit controllers…

Woah, Its been days, since my last post!  Actually I was busy out doing nothing..:)
You may declare me as the most LAZY guy ever!!

So, this time I actually come up with an idea to share upon, that is  how to have internet access on my 8 or 16 bit Embedded controllers.  A random thought gives me ideas like WiFi, USB dongle,  Ethernet, or a modem!!

Thats it!! I can`t  get some other ways(currently).  You are getting??,…Please do tell me over the comment box!!.

So I have my micro controller like that of 8051/AVR or PIC either of them.  Its actually not a problem at all, the concept remains same for all of them.  Ohh I forget the exceptional one our Open Source player Arduino!! yeah, for this the rules are quite different for different hardware(one may use shields with it).

Adding wifi/usb dongle support to 8-bit devices is like doing Insane work! (at least for me…lolz).  Also, making it work over ethernet ia also a mess because you will have to interface ethernet driver also and then write the  protocol!!!!!!!!!
I can`t! So, the only thing remained with me was GSM/GPRS modem.

Making the internet work out of it was really a bad experience for me for the first time.  Literally, It took me almost 3 days at my second try for such a simple work!!!!

I would really like to thank GsmMan at EDABOARD and  my friend Avik Dhupar for helping me in this.

Applications:
Web server based Data logger,
Remote data aquisition etc.

What actually a GSM/GPRS modem is?
It is basically a simple modem(the old skool one…in not much ancient days, we use it at the pc of ours to make the internet work).  Yeah, its the same sort of thing but this time we interface it with the microcontroller.

In order to interface our microcontroller  with the GSM/GPRS modem we need to learn a bit of ultra simle AT commands, (thats how they work!).  We will just send AT commands from our microcontroller or PC to the modem and the modem will reply us back.  We will be learning to interface the GSM/GPRS modem with PC first, the case with microcontrollers is simple then, just send commands serially!!!

1.Connect the GSM modem to PC via serial Cable and power it up.

2.Open the terminal software like Putty/Hyperterminal etc.(based on your OS and distribution) and then choose the required communication port i.e.COM port or ttyS* device.

3.Write the command “at” then press enter, so should be getting an OK response.  If yes, then you are all set now to work.

4.You may first check with the basic works like calling and sending a message with the modem and then making the internet work of it.  So there are two options

  • Read the complete user manual and the documents of  your modem!!!!

  • Try to get the concept and find the relevant commands for your modem and then work accordingly.

I am having a GSM/GPRS modem SIM300 from Vegarobokit India.  So, everything here will be specific to it. I will try to be generic wherever I can.  The following are the few mostly useful AT commands.

  • atd 9910118292;(press enter then)                         – (to make the call to a number)

  • ath (press enter then)                                               – (to cut the call)

  • at+cmgs=”9910118292″(press enter then)             –  (to send a message to a number)

    it will be followed by a prompt where you will be able to write the text.  Write the text and then press ^Z i.e. ctrl+Z so as to end the message! and there you go, You have just sent a text message!

There are a lot of other AT commands to interact with which will give you your device IMEI number, signal strength, your hardware name, and many other things.. Please do consult with the documentation for these easy and fun works.

5. For an active internet connection i.e GPRS just like in our mobile phones, we have to configure our modem too! along with the GPRS settings i.e. just the APN name, provided by the operator.(vodafone in my case)

6.We will be issuing commands as they are, not even a single mistake otherwise we have to re-type them!

(CLICK on the image to enlarge it)

All this work is particular to my Vodafone delhi Sim, So  consider changing the APN(portalnmms) and username/password for any other carrier.

set or check if the modem is in GPRS mode.

  • AT+CGATT=1

defines PDP context, tell the context number, then the protocol, then APN

  • AT+CGDCONT=1,”IP”,”portalnmms”

portalnmms is the  APN name for the vodafone settings.  In my case it didn`t work, I have to go with APN as “www”

set apn, username and password

  • AT+CSTT=”portalnmms”,””,””   or AT+CSTT=”www”,””,””

sets wheather the remote server is ip(0) or domain name(1)

  • AT+CDNSORIP=0

 i.e. whether  you will enter the name or the ip address of the desired web location.

add IP headers when receiving data

  • AT+CIPHEAD=1

Activate the gprs connection

  • AT+CIICR

Returns the local ip

  • AT+CIFSR

———————————————–

By now, it’s connected and ready for data tx/rx

———————————————–

Start a tcp connection to the server(74.125.235.18 is www.google.com),port(80 is http)

  • AT+CIPSTART=”TCP”,”74.125.235.18″,”80″

Do wait for CONNECT OK!!!

 (you may ping google and get the address that time)

send data through the connection

  • AT+CIPSEND

after this, you get a prompt where you can send any data…[max 1024 bytes]

eg:

>GET / HTTP/1.1^j^m^j^m^z

then wait for SEND OK

Here GET is standard HTTP request, / is the root page and HTTP/1.1 or 2.0 or whatsoever is applicable is standard protocol.  Also you will be recieving a lot of output as you just requested a home page from  google server.

To set whether to display IP/Port of data sender when receiving data

  • AT+CIPSRIP=1

To check status

  • AT+CIPSTATUS

To close connection

  • AT+CIPCLOSE

To shutdown pdp context

  • AT+CIPSHUT

Now, I ts my prototype that I prepared for the same project that is taking any random data, it may be your GPS data, data from sensors or whatsoever that You want to upload.

So for this I created a php file that logs the data thrown to it.
(I do need to thanks a few people who gave me this idea :Avik Dhupar and  Aman Verma )

Ugh, My half day was wasted up in revising the php, though it doesn`t require you to devote that much time..one hour is enough if you know C and html.

So the script works like this:

Whenever I request any HTTP page from the GSM modem side using PC or microcontroller, like GET /log.php?DATA=123456789 HTTP/1.1

where “/log.php”   means the request is for log.php file stored at the home directory only and if you have studied a little php then you may have guessed by now that ?DATA=123…

is the data that I am giving it as variable.  So I am just opening a file in php and saving the variable DATA into the file at server side..

You may download the php file at

http://www.4shared.com/file/JSk_4vfg/log.html

It will create a welcome.txt file at the server root directory as in my case with the data you supplied at php variable DATA=123…

And there you  finally get your data uploaded on the server.
Here I had My local server at 59.177.25.245

So I tested it easily, You may require some space on the server..!!

About Beyond

an electronics hobbyst, 8 bit microcontroller(8051/AVR/Arduino) programmer, Linux lover, in love with Embedded Linux systems ... TGL: just push it "BEYOND THE LIMITS"..

Posted on July 23, 2012, in 8-Bit Embedded World, Projects and tagged , , , , , , . Bookmark the permalink. Leave a comment.

Leave a comment