Application is reseting

Hi, I´m sending an Array of GET string command to a web server… I don´t know how… but as soon as I send the tcpStart command the application is reseted.

I´ve been sending single strings with no problems at all.

Here´s the code:

Header:

#define MAX_BUFFER 256
#define GPS_MASK MAX_BUFFER-1
u16 GPS_Entrada = 0;
u16 GPS_Saida = 0;
ascii GPS_String[MAX_BUFFER][100];



void tcp_pfDataRequest ( u16 MaxLen, u32 id )
{

    if (envia_liberado==TRUE)
	{
	   ascii request[100];// [4][100]; 
	   u16 GPS_Indice, len, i; 


	   if ((GPS_Entrada - GPS_Saida)>3)
	   {
			for (i=0 ; i <4; i++)
			{
			GPS_Indice = GPS_Saida&GPS_MASK;


			wm_sprintf(request[i], GPS_String[GPS_Indice]);
			GPS_Saida++;
			}

			adl_atSendResponse(ADL_AT_RSP, "\r Enviando Comand GET para o servidor.\r\n");



			adl_atSendResponse(ADL_AT_UNS, request);


			len = wm_strlen(request); 

			ed_SendDataExt ( request, len , FALSE, ED_ID_TCPSOCKET_1 ); 
	
			envia_liberado=FALSE;

	   }

	 }

}

Any ideas?

Best Regards,

Henrique

Hi Henrique,
There are a few things for which I would like to draw your attention:

  1. “request” is a single dimensional array whereas, the GPS_String is a two dimensional array. In the code:
    wm_sprintf(request[i], GPS_String[GPS_Indice]);
    I think the desired behavior will not be achieved. Probably you wanted to declare request as two dimensional array and would like to copy the GPS_String in the array.

  2. In case, request contains large amount of data, and the application sends the data using adl_atSendResponse() API, the module might crash if it is not able to allocate the amount of memory which is needed to send the data. Hence, it is advisable to send small amount of data using adl_atSendResponse(). In case, you are sending data for debugging purposes, you can use the TRACE macro. If this is not possible, then you can implement a timer from which you can send the data to the external application using adl_atSendResponse() in small chunks.

  3. I am not sure about this point, but if the “request” array does not contain an ending NULL (’\0’) character then wm_strlen () function might crash. So, it is advisable to clean the array at startup using wm_memset () API.

Best Regards,
Open AT Fan.

Hi Open Fan! Thanks for the response…

Yeah, I forgot to change request to two dimensional array (It was commented on the side for test purposes).

I also forgot about the adl_atSendResponse length limitation.

If I hava an array [x][100]
What “x” should I consider maximum?

What do you think about this code now?

void tcp_pfDataRequest ( u16 MaxLen, u32 id )
{


    if (envia_liberado==TRUE)
	{
	   ascii request[4][100]; 
	   u16 GPS_Indice, len, i; 



	   envia_liberado=FALSE;

	   if ((GPS_Entrada - GPS_Saida)>3)
	   {
			for (i=0 ; i <4; i++)
			{
			GPS_Indice = GPS_Saida&GPS_MASK;

			wm_sprintf(request[i], GPS_String[GPS_Indice]);
			GPS_Saida++;
			}

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


			len = wm_strlen(request); 

			ed_SendDataExt ( request, len , FALSE, ED_ID_TCPSOCKET_1 ); 
	

	   }

	 }

}

Best Regards,

Henrique

Hi Henrique,
You should clear the request array before filling the data in it. Hence, put the wm_memset() call before the "if ((GPS_Entrada - GPS_Saida)>3) " condition.
For the purpose of debugging, first try to send the data using the TRACE () macro. This would help you eliminate the case in which the applicaiton is resetting because of length limitation of adl_atSendResponse () API.
If your code works fine, the you can replace TRACE () macro calls to adl_atSendResponse () API but with smaller length sent with each call.

Best Regards,
Open AT Fan.

Here´s what I´m doing now:

void tcp_pfDataRequest ( u16 MaxLen, u32 id )
{

    if (envia_liberado==TRUE)
	{
	   ascii request[4][100]; 
	   u16 GPS_Indice, len, i; 


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

	   if ((GPS_Entrada - GPS_Saida)>3)
	   {
		    envia_liberado=FALSE;

			for (i=0 ; i <4; i++)
			{
			GPS_Indice = GPS_Saida&GPS_MASK;

			wm_sprintf(request[i], GPS_String[GPS_Indice]);
			GPS_Saida++;
			}

			len = wm_strlen(request); 

			ed_SendDataExt ( request, len , FALSE, ED_ID_TCPSOCKET_1 ); 

	   }

	 }


}

As I´m sending 4 strings of 100, am I calling the wm_memset correctly?

wm_memset (request, ‘\0’,400);

I´m feeding the GPS_String on the GPS Handler this way:

bool gps_GpsHandler ( adl_gpsEvent_e Event, adl_gpsData_t * GPSData )
{
	u8 Tamanho1;
	u8 Tamanho2;


    // Switch on event
    switch ( Event )
    {
        case ADL_GPS_EVENT_POLLING_DATA :
        {


            adl_gpsPosition_t Position;

			
			adl_gpsGetPosition ( gps_GpsHandle, &Position );


			Tamanho1 = wm_strlen(Position.latitude);
			Tamanho2 = wm_strlen(Position.longitude);

			if ((Tamanho1>0)&&(Tamanho2>0))
			{
				 wm_sprintf(GPS_String[GPS_Entrada & GPS_MASK],"GET 

/grava.asp?latitude=%s&latind=%s&longitude=%s&lonind=%s&ERRO=%s 

HTTP/1.0\r\nHost:sanabiovilela.sytes.net\r\nContent-Type: text/html\r\n\r\n",Position.latitude, 

Position.latitude_Indicator, Position.longitude, Position.longitude_Indicator, Position.UTC_time); 
				
				GPS_Entrada++;

			}


        }
        break;
    }
	return gps_GpsAutoStart;
    
}

And the module crashed.

Best Regards,

Henrique

  1. About ed_SocketTCPStart function.

I´m sending and HTTP string and the server is returning another string for confirmation.

Do I have to set ed_SocketTCPStart to listening mode (Listen = 1) mode after sending the HTTP string with Client mode (Listen = 0)?

In the Socket sample, the function tcp_pfResponseCbk starts the socket on Listening mode.

Thanks,

Henrique

Hi Henrique,

No. The server won’t establish a connection to your device. It will rather send the answer back on socket connection that is already open.

This is only because the example implements the server side…

Unfortunately, I don’t know why your program crashes. You should check if len <= MaxLen before ed_SendDataExt(…) - but maybe that is not the problem…

Best Regards,
Jan

Can I use the function wm_strlen to retrieve the Array length as I used with a sigle string?

Thanks,

Henrique

I think I´m getting and sending wrong parameters to the server!

See if I hava a good point:

Here´s the string I´m trying to put inside the array:

“GET /grava.asp?latitude=%s&latind=%s&longitude=%s&lonind=%s&ERRO=%s HTTP/1.0\r\nHost:sanabiovilela.sytes.net\r\nContent-Type: text/html\r\n\r\n”

Isn´t the \r\n characters making the next characters go to the next line of the array?

Like: ONE\r\nTWO\r\nTHREE

I would like to store the whole string in one line… but it might be storing like:

ONE
TWO
THREE

What do you think?

Best Regards,

Henrique

Hi Henrique,

I don’t think they should go to the next line. That maybe happens when you use MFC classes but not with a sprintf()! Every character is treated equally and they are copied to the destination into consecutive bytes… There is no line feed processing of any kind…

Best Regards,
Jan

I used sprintf to the GET string and then I put the following data on the screen:

adl_atSendResponse(ADL_AT_UNS, GPS_String[Index];

And I got:

GET /grava.asp?latitude=1958.07256&latind=S&longitude=04357.29783&lonind=W&ERRO=
153251.00 HTTP/1.0
Host:sanabiovilela.sytes.net
Content-Type: text/html

Then… i used the following command (right below the last one): adl_atSendResponse(ADL_AT_UNS, GPS_String[Index+1];

And I got:

Host:sanabiovilela.sytes.net
Content-Type: text/html

I noticed that when I try to send string after string using a loop I send the first as showed and then the second… that doesn´t make sense to the server…

Any ideas?

Thanks!

Henrique

My suggestion is: don’t use 2-dimensional string arrays. I don’t know how to use them, and it looks like you have problems with that, too… Can you just use simple char arrays?

Best Regards,
Jan

Unfortunately i would need several GET strings like:

(Line 1)GET /grava.asp?latitude=%s&latind=%s&longitude=%s&lonind=%s&ERRO=%s HTTP/1.0\r\nHost:sanabiovilela.sytes.net\r\nContent-Type: text/html\r\n\r\n
(Line 2)GET /grava.asp?latitude=%s&latind=%s&longitude=%s&lonind=%s&ERRO=%s HTTP/1.0\r\nHost:sanabiovilela.sytes.net\r\nContent-Type: text/html\r\n\r\n
(Line 3)GET /grava.asp?latitude=%s&latind=%s&longitude=%s&lonind=%s&ERRO=%s HTTP/1.0\r\nHost:sanabiovilela.sytes.net\r\nContent-Type: text/html\r\n\r\n
(Line 4)GET /grava.asp?latitude=%s&latind=%s&longitude=%s&lonind=%s&ERRO=%s HTTP/1.0\r\nHost:sanabiovilela.sytes.net\r\nContent-Type: text/html\r\n\r\n
......

So… I would need a 2-Dimensional Array… Array[lines][string length]

That´s my problem…

I need to work on that… I´ll let you know when I find out!

Best Regards,

Henrique

Hi Henrique,
Sorry for the delayed reply (I was too busy to login to Forum). The fact that you are trying to send too much data to the server in one call to ed_SendDataExt () API might also be the cause of the problem. Please verify that the return value of ed_SendDataExt () API. Also check if you are allowed to send the data you are sending using ed_SendDataExt () API (by checking for the MaxLen parameter of the tcp_pfDataRequest () function.

In order to find the cause of module reset, you should use Debug mode of execution and then step through the application (using breakpoints and other stuff provided by Microsoft Visual Studio). The statement on which your Visual Studio gives exception will be the most probable cause of the module reset.
For target mode, you should enable the RTK level 1 of traces and see if the module gives any RTK exception while crashing (or ARM exception). In case, you receive an ARM exception like 1 xxxx, it means that the application has performed some invalid memory related operation (like trying to write beyond its allocated address space, or writing to a NULL pointer). This will help me find the actual cause of the problem.

Another problem which I found in your code is that in tcp_pfDataRequest () function, you are using wm_sprintf () function without providing a format specifier.
You are using “wm_sprintf(request[i], GPS_String[GPS_Indice]);”
but actually it should be “wm_sprintf(request[i],”%s", GPS_String[GPS_Indice]);

Ideally, you should try to use wm_memcpy() or wm_strncpy() for these kind of operations.
Please modify your code and let me know.

Best Regards,
Open AT Fan.

Thanks for the replies. I really noticed these errors. They came from previous “comments”.

Here´s the solution I found:

I´m working with 1 dimensional array and putting all data after the other. I´ll let the server handle and manipulate the information that is getting there.

Best Regards,

Henrique