This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3100 Simple loop to send message to Server

Other Parts Discussed in Thread: MSP430F5529, ENERGIA, CC3100BOOST

I have a simple program that I started in Energia that runs on a MSP430F5529 with a CC3100Boosterpack that connects to my AP, then sets up a TCP socket to the Server and sends a message and displays the response from the Server. It works 100% of the time on the first try after a reset. If I put it in a loop and do the complete sequence (connect to AP, connect to Server, Send Message, display response)  then sending message and getting a response are very intermittent. I put in a loop counter that is included in the message sent to the Server and it looks like only one out of 8 or 16 messages make it to the Server and send a response.

I can't figure out why it is intermittent. It looks like something is not being loaded or reset like it is when it first starts from a hardware Reset. Maybe some uninitialized variable that's zeroed on reset. CCS keeps crashing when I try to debug the code. So I'm looking for a solution.

// your network name also called SSID
char ssid[] = "MY_AP";
// your network password (key)
char key[] = {0x63, 0x79, 0x23, 0x52, 0x15, 0x76, 0x10, 0x67, 0x67, 0x89, 0x10, 0x71, 0x83,0x00};

// your network key Index number
int keyIndex = 1;


uint16_t port = 80;     // port number of the server
IPAddress server(199, 195, 142, 144);   // IP Address of the server
WiFiClient client;
uint16_t loop_cnt = 0;

String  UNIT_ID="12345678";


void loop() {
  // send the message every few seconds
  this_works();
  loop_cnt++;
  delay(10000);
 // printCurrentNet();
}

void this_works() {
  // attempt to connect to Wifi network:
  Serial.print("Attempting to connect to Network named: ");
  // print the network name (SSID);
  Serial.println(ssid);
  // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
  WiFi.begin(ssid, keyIndex, key);
  while ( WiFi.status() != WL_CONNECTED) {
    // print dots while we wait to connect
    Serial.print(".");
    delay(300);
  }
 
  Serial.println("\nYou're connected to the network");
  Serial.println("Waiting for an ip address");
 
  while (WiFi.localIP() == INADDR_NONE) {
    // print dots while we wait for an ip addresss
    Serial.print(".");
    delay(300);
  }

  Serial.println("\nIP Address obtained");

  //??printCurrentNet();
  //??printWifiData();
 
 
 
  // attempt to connect to the server
  Serial.println("Attempting to connect to server");

uint8_t tries = 0;
  while (client.connect(server, port) == false) {
    Serial.print(".");
    if (tries++ > 100) {
      Serial.println("\nThe server isn't responding");
      while(1);
    }
    delay(100);
  }
 
  //we've connected to the server by this point
    Serial.println("\nConnected to the server!");
 
    Serial.println("\nstart!");
  //  delay(2000);

   String theMSG;
  
   theMSG=String(loop_cnt);
  // Serial.println(theMSG);
   
    // send the HTTP PUT request:
    client.print("PUT /callhome/service.php?");
    client.print("uniqueID=");
    client.print(UNIT_ID);       //   client.print("12345678");
    client.print("&message=");
    client.print(theMSG);

    client.println(" HTTP/1.1");
    client.println("Host: www.rollscout.com");
    client.println();
    client.println();
    client.println();

     delay(3000);
 
 
  if (client.available()) {
    char buffer[255] = {0};
    client.read((uint8_t*)buffer, client.available());
    Serial.print("Received: ");
    Serial.println(buffer);
  }
 
 
   delay(1700);
   client.stop();
   client.flush();
   Serial.println("\nend!");       
   WiFi.disconnect();
 
}

  • Gerry,

    Allow me to check it on my platform and get back.

    -/Praneet

  • BTW, I've also tried   GET

      // send the HTTP GET request:
        client.print("GET /callhome/service.php?");

    .

    .

    .

    .

    I also found that changing the contents of the message (which changes the length) also affects how often it works after the first time. It is 100% repeatable for a given message length which tries work and which ones don't. This also makes it sound like a pointer not being reset and depending on the size of the message the buffer wraps around at a repeatable location.

  • Hi Gerry,

    I tried above mentioned scenario on MSP430F5529+CC3100BOOST using CCS IDE and its perfectly working for me without skipping a single request. Below is code snippet, can you try it at your end?  I am using latest service pack (1.0.0.1.2).

    Code snippet:

    while(1)
    {
    /* Connecting to WLAN AP - Set with static parameters defined at the top
    After this call we will be connected and have IP address */
    retVal = establishConnectionWithAP();
    if(retVal < 0)
    {
    CLI_Write(" Failed to establish connection w/ an AP \n\r");
    LOOP_FOREVER();
    }

    CLI_Write(" Connection established w/ AP and IP is acquired \n\r");


    Addr.sin_family = SL_AF_INET;
    Addr.sin_port = sl_Htons((_u16)80);
    Addr.sin_addr.s_addr = sl_Htonl((_u32)0xC7C38E90);//199, 195, 142, 144
    AddrSize = sizeof(SlSockAddrIn_t);

    SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
    if( SockID < 0 )
    {
    CLI_Write(" [TCP Client] Create socket Error \n\r");
    ASSERT_ON_ERROR(SockID);
    }

    retVal = sl_Connect(SockID, ( SlSockAddr_t *)&Addr, AddrSize);
    if( retVal < 0 )
    {
    sl_Close(SockID);
    CLI_Write(" [TCP Client] TCP connection Error \n\r");
    ASSERT_ON_ERROR(retVal);
    }

    i++;
    sprintf(buf, "PUT /callhome/service.php?uniqueID=%d&message=%s%d HTTP/1.1\nHost: www.rollscout.com\n\n\n\n", 12345, "Hello", i);

    retVal = sl_Send(SockID, buf, pal_Strlen(buf), 0 );
    if( retVal <= 0 )
    {
    CLI_Write("Data send Error \n\r");
    retVal = sl_Close(SockID);
    ASSERT_ON_ERROR(-1);
    }

    retVal = sl_Recv(SockID, buf, 1024, 0);
    if(retVal <= 0)
    {
    CLI_Write("Data recv Error \n\r");
    ASSERT_ON_ERROR(-1);
    }

    buf[retVal] = '\0';
    CLI_Write("HTTP Response from server-------\n\r");
    CLI_Write(buf);
    CLI_Write("\n\r");
    CLI_Write("\n\r");

    retVal = sl_Close(SockID); //
    retVal = sl_WlanDisconnect();
    if(0 == retVal)
    {
    /* Wait */
    while(IS_CONNECTED(g_Status)) { _SlNonOsMainLoopTask(); }
    }


    }

  • Gerry,Did you get a chance to try w/ above snippet?
    I'm closing this thread - Please let me know if you need any further assistance. Suggest you file a new thread and give references to the current one in there for us to track it better.
    -/Praneet