Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

TCP CONNECTING problem

Status
Not open for further replies.

susano

Junior Member level 1
Joined
Mar 30, 2009
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,441
hi all, i'm working on a mobile positioning project. i wana send some strings to a specified site, by using two gprs_init(only for initialization) and gprs_send functions as below:
//----------------------------------------
void gprs_init()
{

putsf("AT+CIPSHUT\r\n");
delay_ms(100);

putsf("AT+CGATT=1\r\n"); //gprs attachment
delay_ms(100);

putsf("AT+CGDCONT=1,"); //define PDP context
putchar('"');
putsf("IP");
putchar('"');
putchar(',');
putchar('"');
putsf("MTNIRANCELL");
putchar('"');
putsf("\r\n");
delay_ms(100);

putsf("AT+CSTT="); //set user/pass
putchar('"');
putsf("MTNIRANCELL");
putchar('"');
putchar(',');
putchar('"');
putsf("");
putchar('"');
putchar(',');
putchar('"');
putsf("");
putchar('"');
putsf("\r\n");
delay_ms(2000);

putsf("AT+CIICR\r\n");
delay_ms(3000);

putsf("AT+CIFSR\r\n");
delay_ms(1000);

putsf("AT+CIPSTATUS\r\n"); //Query current connection status
delay_ms(200);

putsf("AT+CIPHEAD=1\r\n");
delay_ms(100);

putsf("AT+CDNSORIP=0\r\n"); //Connect with IP address(0) or domain name(1) server
delay_ms(100);

}
//--------------------------------------------------------------
void gprs_send(char* buffer)
{
putsf("AT+CIPSTART=");
putchar('"');
putsf("TCP");
putchar('"');
putchar(',');
putchar('"');
putsf("50.22.151.7");
putchar('"');
putchar(',');
putchar('"');
putsf("80");
putchar('"');
putsf("\r\n");
delay_ms(15000);

putsf("AT+CIPSTATUS\r\n"); //Query current connection status

putsf("AT+CIPSEND\r\n");
delay_ms(1000);
printf("GET http://www.hamidrezaheydarian.com/save.asp?Data=%s;done\r\n\r\n%c",buffer,26);
}
the main problem is that in some cases the module can't be connected to the site;as a result, after issuing "AT+CIPSTATUS" command, i receive "TCP CONNECTING" instead of "CONNECT OK", and only after resetting the gprs connection(by calling gprs_init function) for several times, the connection to the site may be established again.
dose anyone know whats wrong with my code?:sad:
thanks in advance, waiting for your help...
 

You should NEVER depend on fixed delays between commands for this type of communications. There can be a LOT of variability in the amount of time some commands take. You should check the status returned from the module to see if it can execute the next command. For example, the `AT+CIICR` command can take a while before it returns "IP STATUS". If you don't get that status, subsequent commands may fail.
 

thanks GSM Man, I've experienced the variability in different commands to reply! i should have mentioned that to find failures, i use delays, run the system(mcu and module), and simultaneously monitor Rx and Tx lines by PC(hyper terminal).
concerning SIM508 datasheet(my GSM module), the order of connection states is as below:
0 IP INITIAL
1 IP START
2 IP CONFIG
3 IP IND
4 IP GPRSACT
5 IP STATUS
6 TCP/UDP CONNECTING
7 CONNECT OK
8 IP CLOSE

So, i think that it's enough to check IP status only twice:
1- after calling "AT+CIFSR" command, to check if "IP STATUS" is returned;
2- after calling "AT+CIPSTART", to check if "CONNECT OK" is received.
and you see that i did it by calling "AT+CIPSTATUS" in both situations. what i am getting through hyper terminal,is this:

SHUT OK //CIPSHUT

OK //AT+CGATT=1

OK //AT+CGDCONT=1

OK //AT+CSTT=...

+PDP: DEACT

OK //AT+CIICR

10.6.112.130 //AT+CIFSR

OK //AT+CIPSTATUS

STATE: IP STATUS:smile:

OK //AT+CIPHEAD=1

OK //AT+CDNSORIP=0

OK //AT+CIPSTART=...

OK //AT+CIPSTATUS

STATE: TCP CONNECTING:?

as you see, spite of getting "IP STATUS", the connection can't be established and i get "TCP CONNECTING" after calling "AT+CIPSTART".
i got really confused! what should i do more to receive "CONNECT OK" after receiving "IP STATUS"??? any commands? is 15 seconds few?!(I've tested it by 30 seconds too but not connected again)
 
Last edited:

What is the signal level you are seeing (AT+CSQ). If the signal is low it may take a LONG time for it to connect, or it make fail all together. It can take minutes for it to return a fail status; during which time it will continue to report "TCP CONNECTING".
 

I checked the signal level by "AT+CSQ" command and it returned "+csq: 24,0" (rssi=24,ber=0).
I dont know if these values are high enough for establishing a TCP connection or not(?).if no, maybe we can conclude that the signal level is blame! however i'm working indoor, here, other mobile phones receive a strong signal and can be connected through GPRS network in less than 15seconds.
 

is there anyone to answer my question?! I'm still waiting for your reply:-(
 

24 is a good signal strength,Have you checked that the IP and PORT which you are trying to connect is accepting your connection or rejecting.
That is have you checked for the error codes from the server side.e.g Timed_out, TCP_init_failure...so on.
 

thanks e shade, yes i'm sure of IP and PORT. because as i told,the problem arises only in 10-20% of cases. besides, when i try to send data by the URL through internet, there's not any problem and i always receive the expected reply of the sit. so, the problem must be elsewhere!(?)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top