Post a new topicPost a reply Page 1 of 1   [ 7 posts ]
Author Message
 Post subject: TCP error
PostPosted: Tue May 22, 2012 4:55 pm 

Joined: Tue May 15, 2012 6:47 pm
Posts: 8
I am having trouble with the GPRS module. It works well for a couple of times and then it stops working for a long while. then it works again. I wpould appreciate the help immensely!
Code:
Code:
unsigned long lastConnected=0;



void setup(){
 
  // setup for Serial port over USB
  USB.begin();
  USB.println("USB port setup ok");

  setupGPRS();
}

void setupGPRS(){
  // setup for GPRS seial port
  GPRS.ON();
   USB.println("GPRS module ready... Waiting for GPRS to Connect to Network");

  while(!GPRS.check());
   USB.println("GPRS connected to the network");


  // configure SMS and Incoming Calls
  if(GPRS.setInfoIncomingCall())
  {
     USB.println("Info Incoming Call OK");
  }
  if(GPRS.setInfoIncomingSMS())
  {
     USB.println("Info Incoming SMS OK");
  }
  if(GPRS.setTextModeSMS())
  {
     USB.println("Text Mode SMS OK");
  }
}

void loop()
{

  Utils.setLED(LED0, LED_ON);
  Utils.setLED(LED1, LED_ON);

  RTC.getTemperature();
  delay(2000);
  USB.print("RTC temperature is ");
  USB.print(RTC.temp,DEC);
  USB.println(" C.");
 
  // Configure GPRS Connection
  if(GPRS.configureGPRS())
  {
   USB.println("GPRS Configured waiting for socket to open");

    if(GPRS.createSocket("216.52.233.121","80",GPRS_CLIENT))//could replace GPRS_CLIENT with 0
    {
      USB.println("Socket Opened OK. Sending data to COSM");
     USB.println("Session Number: ");
      int i=0;
      while( GPRS.socket_ID[i]!='\r' )
      {
        USB.println(GPRS.socket_ID[i]-'0',DEC);
        i++;
      }
      i=0;
      USB.println("Socket All OK");

      /********************** Send Data to COSM *****************************************/
      lastConnected=millis();
      USB.println("Constructing Cosm Request ... ");
      char* COSMReq=makeCOSMRequest(RTC.temp);
      // Send data via socket
      USB.println("COSM Request Constructed");
      USB.println(COSMReq);
      if(GPRS.sendData(COSMReq,GPRS.socket_ID))
      {
        USB.println("Data sent to COSM");
      }
    }
    else
    {
      USB.println("Error: Failed to open TCP socket");
    }
    delay(2000);
    // Close socket
    if(GPRS.closeSocket(GPRS.socket_ID))
    {
      USB.println("Socket closed");
    }
    if(GPRS.deleteSocket(GPRS.socket_ID))
    {
      USB.println("Socket deleted");
    }
  }
  else
  {
    USB.println("Error: Failed to configure GPRS");
  }

}

char* makeCOSMRequest(float temp)
{
  char *pdata= (char*) calloc(300,sizeof(char));
  char *te = (char*) calloc(10,sizeof(char));
  char *data =(char*) calloc(50,sizeof(char));
  USB.println("Creating Arrays");
  Utils.float2String(temp,te,2);
  USB.println("convering string to float ");
  replaceChar(te,',','.');
  USB.println("change every . with te");
  sprintf(data,"%s%s%s","1,",te,"\n");
  USB.println("change data to lines");
  int len=Utils.sizeOf(data);
  USB.println("getting size of data");
  sprintf(pdata,"%s%d%s%s", "PUT /v2/feeds/60549.csv HTTP/1.1\r\nHost: api.cosm.com\r\nAccept: */* \r\nAuthorization: Basic a196aWtyeTphenphbmFkYQ==\r\nContent-Length: " ,len ,"\n\n",data);
  USB.println("change Pdata F");
  return pdata;
}
/********************************** Helper function for strings *********************************/
int indexOf(char* str,char find)
{
  int index=-1;
  int sz=Utils.sizeOf(str);
  for(int i=0;i<sz;i++){
    if(str[i]==find){
      index=i;
      i=sz+1;
    }
  }
  return index;
}

void replaceChar(char* str,char toReplace,char replaceWith)
{
  int index=indexOf(str,toReplace);
  str[index]=replaceWith;
}


Top
 Profile  
 
 Post subject: Re: TCP error
PostPosted: Tue May 22, 2012 4:57 pm 

Joined: Tue May 15, 2012 6:47 pm
Posts: 8
it shows me that socket is opened and everything is sent - but it is not received at the server.


Top
 Profile  
 
 Post subject: Re: TCP error
PostPosted: Wed May 23, 2012 8:46 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
k_zikry,

We kindly ask you to check a few things before going deep into your code.

  • Did you connect battery to GPRS module? also it should be properly charged. besides that, Antenna must be also connected.
  • Take a look into Waspmote checklist and read it carefully to see if you miss something.
  • Did you ran TCP example provided with Waspmote IDE? Did it work well?

Let us know this tips before going further.

Best Regards.


Top
 Profile  
 
 Post subject: Re: TCP error
PostPosted: Thu May 24, 2012 1:21 pm 

Joined: Tue May 15, 2012 6:47 pm
Posts: 8
Libeliumdev,
Yes i ran over the entire checklist, and it does send the data once or twice and then it stops. I'm thinking maybe something needs to be flushed in the headers or something?

Cheers,


Top
 Profile  
 
 Post subject: Re: TCP error
PostPosted: Fri May 25, 2012 9:23 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
Hi k_zikry,

could you please post the log you got at your serial port?

Regards.


Top
 Profile  
 
 Post subject: Re: TCP error
PostPosted: Fri May 25, 2012 11:28 am 

Joined: Tue May 15, 2012 6:47 pm
Posts: 8
it opens the socket and creates the http request file correctly, sends it and then closes, and deletes the socket. Note: it does send the data a couple of times and then stops for a while. i turn it off and on - it sends again.


Top
 Profile  
 
 Post subject: Re: TCP error
PostPosted: Tue May 29, 2012 3:59 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
k_zikry,

How is your issue going?

We think that your problem may be related with the pc side which manages the socket.

Did you achieve receive any data at socket side?

let us know

regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 7 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use