[HOW]Configure and Open TCP connection to host


#1

Hello everyone… what i mean… i want to set up and open connection to remote host…

At fist we need to init TPC lib…

ed_Init

Ok next step we need to config GPRS struct…

ed_GprsSetConfig

now we need to start GPRS session

ed_DialupConnectionStart

and now we can config and open TCP socket?

ed_SocketSetConfig

ed_SocketTCPStart

WE CAN SEND AND RECIVE DATA?
ed_SendData

Or maybe enyone can tell how to init and create TCP connection to remote host… ? hm…


#2

Hello,
You are right in your notions regarding opening a socket. Just a few points I would like to mention:

  1. For TCP sockets, use ed_SendDataExt () API to send data.
  2. You must be attached to the GPRS, if you are using GPRS as the physical layer for the TCP socket.

Here are the points that you need to follow:

  1. Wait for +WIND: 4 indication to occur. You can do this by subscribing to +WIND: 4 unsolicited indication. THis is because, eDlib internally waits for ADL_SIM_EVENT_FULL_INIT (which is equivalent to +WIND: 4) and only after receiving this event, does it allows you to set the TCP parameters, and start the socket.
  2. When the +WIND: 4 is received, attach to GPRS network. You can use AT+CGATT=1 command using adl_atCmdCreate () API.
  3. When you are connected, (i.e. receive an OK for this command), call ed_DialupConnectionStart () API.
  4. When you receive ED_OK_GPRS_SESSION_SET (if you are using GPRS), then set the TCP parameters using ed_TCPSetConfig.
  5. Now start the socket using ed_SocketTCPStart () API.
  6. For sending data use ed_SendDataExt () API.

For more information, you can refer to the user guide for TCP/IP library.

Best Regards,
Open AT Fan.


#3

user guide for TCP/IP library where can we get this? I have all the openAT software since 2.0 to 4.0 but there is no ref. to user guide for TCP/IP library, please advise is it that it comes only with the TCP/IP stack version of the modem?


#4

Hi Samuel,
When you install Open-AT, the TCP/IP library is present in C:\OpenAT\Otherlibs directory. In this directory, you can find a folder named “doc” where the TCP/IP user guide is present.
In Open-AT 3.10, you can find the user guide for TCP/IP under the folder “C:\OpenAT\V310\TgtGen\Add-ons\TCPIP\v3.00\doc”

Best Regards,
Open AT Fan.


#5

Tnx you very much… this information is usefull for me…


#6

How you can wait for the Ok ? I do this:

adl_atCmdCreate("at+cgatt=1",TRUE, (adl_atRspHandler_t) CGATT_Response_Handler,"OK",NULL );

But what should I put in the CGATT_Response_Handler?


#7

Your CGATT_Response_Handler receives an adl_atResponse_t parameter - you check that for the “OK” response; eg,

bool CGATT_Response_Handler( adl_atResponse_t * the_response )
{
    if( the_response->RspID == ADL_STR_OK )
    {
        TRACE ((1, "OK received!" ));
    }
}

However, since you are only subscribing to the OK response, the handler won’t get called for any other response anyway!


#8

Hmm okay I understand, but If the handler don’t calld the cgatt don’t back OK. How can I set a gprs connection?

Here is my code:

void adl_main ( adl_InitType_e InitType )
{
     /* ed_gprsSetupParams_t *gprs_connect; */
      ed_gprsSetupParams_t gprs_connect; 
     s8 ret = 0;
     char buf[100];    
     
         
     TRACE (( 1, "Embedded Application : edinit" ));
     adl_atSendResponse (ADL_AT_UNS, "\r\nSTART\r\n");
     ret = ed_Init();
     
     if (ret < 0) {
      adl_atSendResponse(ADL_AT_UNS, "\r\ned_init failure\r\n");    
     }
     
     adl_atSendResponse (ADL_AT_UNS, "\r\nED_START2\r\n");
     
     gprs_connect.Cid = 1; 
     adl_atSendResponse (ADL_AT_UNS, "\r\nSet Cid\r\n");
     gprs_connect.Mode = 1; 
     adl_atSendResponse (ADL_AT_UNS, "\r\nSet Mode\r\n");
     wm_sprintf(gprs_connect.ApnServ, "internet"); 
     adl_atSendResponse (ADL_AT_UNS, "\r\nSet Apn\r\n"); 
             
     wm_sprintf(buf, "\r\nGPRS settings: Cid: %d Mode: %d Apn: %s\r\n", gprs_connect.Cid, gprs_connect.Mode, gprs_connect.ApnServ);
     adl_atSendResponse(ADL_AT_UNS, buf); 

     ret = ed_GprsSetConfig(&gprs_connect); 
          
     if (ret < 0) {
      adl_atSendResponse(ADL_AT_UNS, "\r\nGPRS Setup failure\r\n");        
     } else {
      adl_atSendResponse(ADL_AT_UNS, "\r\nGPRS Setup OK\r\n");
     }
     
     adl_atSendResponse(ADL_AT_UNS, "\r\nGPRS Connect start\r\n");
    ret = ed_DialupConnectionStart(GPRS_connect_handler);
    
    if (ret < 0) {
     wm_sprintf(buf, "\r\nGPRS connect error: %d\r\n", ret);
     adl_atSendResponse(ADL_AT_UNS, buf);
    } else {
     adl_atSendResponse(ADL_AT_UNS, "\r\nGPRS connect OK\r\n");         
    }         
}

This code give me error code -10 at the end (GPRS connect error) but it is false because it is a pin code error and i haven’t any pin on my SIM. I read the forum and it says use +CGATT=1 before edDialupConnectionStart and wait the OK. But I don’t know how can I do this. :frowning: Somebody could give me a sample code?
[/code]