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();
}