Sendind DATA through GPRS


#1

Hi, i´m just starting with wavecom and im a little bit lost. I understood the PING Sample that cames with the product but I still don´t have a clue where to start sending data through GPRS.

Can I send a String of Data to a website that will handle the data with PHP or ASP?

Can anyone give me a light?

Thanks,

Henrique Sanábio Vilela
sanabiovilela@yahoo.com.br


#2

Hello,

Ping is a service for testing the TCP/IP network connection, see the socket sample if you want to send data with the related pages of IP connectivity guide.

tom


#3

Hi Tom, thanks for your reply.

This Socket Sample acts like a Web Server right? It expects a remote user to send it a “GET” command to start it´s work.

Well… now I would like to Send a GET command to a Web Server. So the program must act as a client. I assume the settings will remain with the default configuration as we´re only changing the data direction.

Some questions about this task:

  • Can I build a sentence in pure ASCII chacters? eg.: “htt://somesite.com/data.asp?latitude=47”

  • In Socket Sample it awaits some client to connect
    How can I try a connection specifying a URL to it?

I´m still a little confused. Some people tryed to help me with TCP/IP tutorial, etc but the the union with WaveCom OpenAT still make me dizzy.

Thanks to you and everybody else!


#4

Hi sanabiovilela,
You can easily send a GET request to a web server. I will tell you the steps which you can follow to successfully send a GET request. However, before this, I would like you to explain how Open-AT will send the GET request to the server.

  1. First of all, to be able to send HTTP request, you need to have complete TCP/IP stack. Please note that HTTP protocol works on top of TCP/IP. Hence, the necessity of TCP/IP is a must. The functionality of TCP/IP stack is provided by eDLib. The APIs of eDLib allow you to make a TCP socket with any listening server in the world.
  2. Once, a TCP socket is established, you can sent an HTTP request to the web server. Please note here that in this case, the HTTP request is not simply the name of the web site followed by the page to retrieve. You have to send the complete HTTP request. Usually, when you type the name of a web site in your normal browser (like Internet Explorer, or Netscape), the browser creates an HTTP request based on the values that you type. However, when you are trying to connect to a server from the module (Open-AT), there is no web browser. Hence, you have to make the complete request yourself. This HTTP request can be sent using ed_SendDataExt () API. Please note that the TCP socket which you have opened will carry the information (which is the HTTP request) to the web server. The web server will parse the request and will send the response back to the client (wavecom module) which will receive the data in the TCP data handler.

I think now, the concept has become pretty clear. I will now tell you the steps how to create an applicaiton which will perform the required task:

  1. Create an Open-AT applicaiton using ADL mode and wait for +WIND: 4 indication.
  2. When you receive a +WIND: 4 indication, issue AT+CGATT = 1 command to attach to GPRS network (I assume that you are using GPRS to connect to the service provider).
  3. After receiving an “OK” response for AT+CGATT=1 command in the command handler function, set the parameters for your GPRS session (like APN server name, APN username, and APN password) using ed_GPRSSetConfig () API.
  4. Call ed_DialupConnectionStart () API to establish an IP session with the service provider and receive an IP address. When you receive ED_OK_GPRS_SESSION_SET event in the dialup handler, you have received an IP address. Now, you need to open the socket with the web site.
  5. In case, you have provided the DNS IP address and used ed_DNSSetConfig () API to set the DNS settings in the Open-AT applicaiton, you can provide the name of the server to which you want to connect in the TCPServ parameter. Otherwise, you give the IP address and port of the TCP server to which you want to connect and use ed_SocketSetConfig () API to set the parameters.
  6. Now use ed_SocketTCPStart () API to send the TCP socket opening request. If socket connection with the server is successful, you will receive ED_INFO_WAITING_FOR_DATA event in the TCP event handler (which you provided while calling ed_SocketTCPStart () API).
  7. The ed_DataRequest_f () will be automatically called which means that eDlib is asking you to send data to the server.
  8. Here you need to form your HTTP request and send it to the server. A sample HTTP GET request can be:
    ascii request [100];
    u16 len;
    wm_memset (request, ‘\0’,100);
    sprintf(request,“GET /index.html\nHTTP/1.0\nHost:
    yahoo.com\nContent-Type: text/html\n”);
    len = strlen(request);
    ed_SendDataExt ( BData, len , FALSE, ED_ID_TCPSOCKET_1 );
  9. As you can see, the ed_SendDataExt () API will send the newly formed HTTP request to the “www.yahoo.com” web server. You can refer to the API description for more information on how to use these APIs.
  10. The response from the web server will come in the TCP data handler which you can display using TRACE () macro. Please note that if the resposne from the server is too large, then don’t use adl_atSendResponse () API to print the values (as it has some limiation on the number of bytes to send as response).

I think this solves some of the queries in your mind.

Best Regards.


#5

Hi all,

Good information [color=blue]OpenAT_Fan :slight_smile:

I just have to add a small correction:

Isn’t it so, that the data you wanted to send was in the [color=red]request ascii array?

So I guess the correct code would be:

ascii request [100]; 
u16 len; 

wm_memset (request, '\0',100); 

sprintf(request,"GET /index.html\nHTTP/1.0\nHost:www.yahoo.com\nContent-Type: text/html\n"); 

len = strlen(request); 

ed_SendDataExt ( request, len , FALSE, ED_ID_TCPSOCKET_1 );

/Snoooze


#6

Hello everybody,

I have another remark on the request:

This may work fine with yahoo, but I had a problem with webserver accepting a request similar to the one given here.

My webserver refused to accept the request and just terminated the socket connection without sending an answer at all. However, it worked just fine after I repleaced the line breaks “\n” by “\r\n”. I always thought the simple line breaks should be enough but they didn’t work for me before - so this might be worth mentioning… ( I don’t know what the HTTP spec says about that, it’s too hard to read :wink: )

Best Regards,
Jan


#7

Hi all,
Thanks for the correction snoooze. I agree by the point raised by Jan that some web servers expect a '\r" character in front of “\n”. It depends upon the server.
However, as per I know, a “\n” is what is specified by HTTP recommendations and HTTP also specifies how the web server should interpret incorrectly formulated HTTP requests.
But it is always better to send a “\r” character in front of “\n” as pointed by Jan as it would allow the application to become more robust.
The sample request which I showed worked fine with the “yahoo.com” web server.

Best Regards.


#8

Hi everybody, at first place I would like to thank you all for the whole awsome help! I really appreciate.

Let´s stick to the point… Step 5 above.
Do I have to know the server IP I want to connect (like yahoo.com IP from the Sample)? Or this IP is the one from my Service Provider?

The Port is 80 as Im going to send a GET request.

Thanks once again!

Best Regards,

Henrique


#9

Hello

You have 2 options:

  1. If you know the IP address of the server you want to connect to, then you can enter this in the numerical IP-address form (xxx.yyy.zzz.nnn) in the socket setup.

The IP you get from your service provider after ed_DialupConnectionStart() is your own IP-address. This address can be dynamic or static, private or public, all depending on the subscription you have got from your GPRS network and/or service provider.

  1. If you want to enter a domain name, you have to use a DNS so the TCP/IP stack can get (lookup) the IP-address from the domain name. You do this by using the DNS API ed_DNSSetConfig (as OpenAT_Fan wrote in point 5).
    If you know an IP-address to a DNS server that you want to use, then you enter it directly in the DNS API or if you do not know it, you can get the address after you have made a successful ed_DialupConnectionStart() with adl_gprsGetCidInformations() (if your network operator provides that information)

You should connect to the port that the server is listening on and port 80 is the most used port for http (but in theory it could be any port).

/Snoooze


#10

Hi sanabiovilela,

Just a quick note that even if you know the IP address of the server where the site is located, it might not work to reference a page by IP when the hosting provider uses shared hosting. Then there are more sites hosted with the same IP address and selecting the appropriate pages would only work when you use the option 2 described by Snooze: in that case you need to use the domain name of the sever in the GET request which requires DNS.

(If you can open the page correctly when you enter the IP in a regular web browser, then it should be OK to use the IP directly instead of DNS - but the DNS API is quite easy to use anyway)

Best Regards,
Jan


#11

Hi once again!
Here´s the thing: my service provider expect the GPRS user to dial for service requirement.
The information they provide are so incomplete that sometimes there are missing ones.
They say that to stablish connection, I need to dial a number (*600) and provide APN, UN and PW.

So… to do that I think I have to send the ATD command and then do the whole steps said from you people above, am I correct?

Anyway… even with the ATD command… I couldn´t ATTACH to the GPRS Network. The CGATT is always 0 and force the 1 with Hyper Terminal is useless.

If a force a CGATT=1 I get and ERROR.

Any thoughts?

Thanks!

Best regards,

Henrique


#12

Just to let you know:

I´m Using Visual C++ 6.0 and the Hardware Module is: Q2501B

Thanks,

Henrique


#13

Hello,

Normally, the procedure to activate the PDP context via AT-commands is with the ATD99# or ATD99***1#.

The tech support usually do not have any good information and its nothing else do to except to stay put in telephone queues for half an hour just to get a stupid answer on your question. But eventually there is a bright answer or a person that knows what he/she is talking about and then its recommended to write down that persons contact information for later use…
However, some network operators do have a specific M2M/Vertical market or another specialized tech support. They usually knows what they are talking about…

I have never heard of any dial code like 600 to activate GPRS context. All over the world (as far as I know) its only been 99# or 991#.

Yeah, but you need to be attached (AT+CGATT=1) to the GPRS network first (AT+CGREG? must give 1 or 5). And I suggest you to first test the module with the AT-command controlled TCP/IP stack and a terminal. Its easier and more clean and eliminates programming errors that could mess up things in an OAT embedded application.

Try to enable extended error result codes with AT+CMEE=1 and you will probably get an error code together with the error message. That could give you a clue of whats going wrong.

Some other things to check is of course the usual stuff:
-Do you really have GPRS enabled on your subscription (SIM card),
-Do the SIM work in a GPRS mobile phone?
-If answer is no the questions above: Check with your network operator :frowning:
-Do you have enough signal strength in the area you are testing (check with AT+CSQ)
-Are you using the correct parameters APN/UN and PW?
-Are you really sure your module software supports the GPRS feature (it can be disabled… and in this case you need to contact your Wavecom distributor/contact)?

see also the thread:
http://wavecom.profileo.com/modules/movie/scenes/forums/viewtopic.php?t=161

/Snoooze


#14

I entered AT+CMEE=1 command as I was told to.

This way I started the Sample With “AT+SOCKETSTART=1”

Then I set the AT+IPGPRS=3,"gprs.oi.com.br,“oi”,“oi”

So I entered the command “AT+CGATT=1”

The Returned ERROR was: +CME ERROR: 11

I Couldn´t find the reason for ERROR 11.

I can´t go forward because of this error.

Thanks for your patience!

Henrique

PS: Sorry, I posted this message on another forum by mistake.


#15

I´ve just figured out it was the PIN Code missing.

I´ll be posting soon! You know I will! Thank you!

Henrique


#16

Ok, now I received a OK answer from the hardware after the CGATT=1.

The IP session has been stablished and I got a Local IP.

Local IP = 10.126…99.105
The Distant IP = 0.0.0.0
And the Gateway = 0.0.0.0

Something must be missing.

As I followed the Socket Sample, the only thing I added was a Function to send a HTTP GET request and it´s called from a Timer a set.

How can I receive the server answer after the Data I sent through my ed_SendDataExt?

Is there anyway I can show you the code… if you want of course.

Thanks!

Henrique


#17

The Socket Sample uses IPConnect Library, and so I used AT commands recommended from it.

AT+IPGPRS=3,“gprs.oi.com.br”,“oi”,“oi”
AT+IPCONNECT=1,1

Then:

AT+SOCKETSTART=1

That´s when the program send the AT+CGATT=1 and then it tryes to send the HTTP GET Request I added.

The ASP scritpt I wrote didn´t get any information yet.
How can I be aware of the data that is being sent and it´s status?

I put the code on the page below:
bb.1asphost.com/bhmais/gps/socket.htm

Thanks!

Henrique


#18

I tryed the following code do retrieve some response:

But when I try to pull some info for reading the system crashes and reset.

Any thoughts?

Thanks,

Henrique


#19

Hello Henrique,

You pass an s8 to adl_atSendResponse() which you should pass an ascii* to… that could be a problem…

What do you mean by “pull some info for reading”? Actually, when you receive data, the handler function for the socket will be called. How does that code look like?

Best Regards,
Jan


#20

Hi Henrique,

        Please make sure that you send the HTTP request only after the TCP socket is opened. 

To solve the problem, try sending the HTTP request from the “tcp_pfDataRequest ()” function. This function is automatically called when the socket is successfully opened with the server. This function gives you the indication of how much data you can send to the server. Note the “MaxLen” parameter of this function which will be having the maximum length of data (which in your case is the HTTP request) that you can send.
Note that the data (which you expect from the server after you send the HTTP request) will be received in the tcp_pfDataHnd () function. Please note here that the parameters of this functions will contain the length of received data, pointer to the data and the ID of the socket for which the data is received. From here you can print the data using TRACE macro.

You can comment the contents of tcp_pfDataRequest () function (of the sample application you are using) and instead call your own function to send the data (HTTP request).

Also check the size of buffer in which you are storing the HTTP request and the actual length of HTTP request. This can also be a cause of module reset in addition to the point raised by “Jan”.

One more thing which I would like to point to is that you should check the TCP socket parameters. As the socket example is meant to be a server socket, it has a setting of “255.255.255.255” for the TcpServ parameter. For a client socket, this parameter should have the IP address of the server to which you want to connect. Also the second parameter of ed_SocketTCPStart () should be a 0. Please check the above mentioned points in your application.

Hope this will solve your problem.

HAPPY NEW YEAR TO YOU AND ALL THE OPEN AT FORUM MEMBERS.

Best regards.