# Application is reseting

**URL:** <https://forum.sierrawireless.com/t/application-is-reseting/268>\
**Category:** Open AT\
**Created:** [February 7, 2006, 4:40pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268 "2006-02-07T16:40:56Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 7, 2006, 4:40pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/1 "2006-02-07T16:40:56Z")

</div>

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:

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

```auto

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

---

<div class="post-metadata">

**Author:** ![OpenAT\_Fan](https://avatars.discourse-cdn.com/v4/letter/o/f07891/32.png) [@OpenAT\_Fan](https://forum.sierrawireless.com/u/OpenAT_Fan)\
**Post date:** [February 7, 2006, 5:25pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/2 "2006-02-07T17:25:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 7, 2006, 5:33pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/3 "2006-02-07T17:33:59Z")

</div>

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?

```auto
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

---

<div class="post-metadata">

**Author:** ![OpenAT\_Fan](https://avatars.discourse-cdn.com/v4/letter/o/f07891/32.png) [@OpenAT\_Fan](https://forum.sierrawireless.com/u/OpenAT_Fan)\
**Post date:** [February 7, 2006, 5:44pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/4 "2006-02-07T17:44:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 7, 2006, 6:37pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/5 "2006-02-07T18:37:49Z")

</div>

HereÂ´s what IÂ´m doing now:

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 8, 2006, 5:05pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/6 "2006-02-08T17:05:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jan](https://forum.sierrawireless.com/u/jan)\
**Post date:** [February 8, 2006, 5:51pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/7 "2006-02-08T17:51:45Z")

</div>

Hi Henrique,

> [@sanabiovilela](#):
>
> Do I have to set ed\_SocketTCPStart to listening mode (Listen = 1) mode after sending the HTTP string with Client mode (Listen = 0)?

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.

> [@sanabiovilela](#):
>
> In the Socket sample, the function tcp\_pfResponseCbk starts the socket on Listening mode.

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

---

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 9, 2006, 2:01pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/8 "2006-02-09T14:01:40Z")

</div>

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

Thanks,

Henrique

---

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 9, 2006, 3:01pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/9 "2006-02-09T15:01:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jan](https://forum.sierrawireless.com/u/jan)\
**Post date:** [February 9, 2006, 3:14pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/10 "2006-02-09T15:14:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 9, 2006, 3:38pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/11 "2006-02-09T15:38:37Z")

</div>

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:

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jan](https://forum.sierrawireless.com/u/jan)\
**Post date:** [February 9, 2006, 3:45pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/12 "2006-02-09T15:45:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 9, 2006, 4:51pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/13 "2006-02-09T16:51:57Z")

</div>

Unfortunately i would need several GET strings like:

```auto
(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

---

<div class="post-metadata">

**Author:** ![OpenAT\_Fan](https://avatars.discourse-cdn.com/v4/letter/o/f07891/32.png) [@OpenAT\_Fan](https://forum.sierrawireless.com/u/OpenAT_Fan)\
**Post date:** [February 9, 2006, 6:08pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/14 "2006-02-09T18:08:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [February 17, 2006, 4:13pm UTC](https://forum.sierrawireless.com/t/application-is-reseting/268/15 "2006-02-17T16:13:54Z")

</div>

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
