I'm having a strange and intermittent problem with an application on a tm4c1294xl. I'm working with Energia 12, on windows 8.1.
The launchpad is plugged straight into a router, and I'm trying to make GET requests from a local network server when a button is pressed... which could happen twice per second, or once per day. The frustrating part is... it MOSTLY works. By mostly, I mean the first 10 or so connections after power up usually fail... then it starts connecting successfully and snappily, returning a response in less than a second... but then frequently it starts lagging after a few connections.... sometimes taking ten seconds to return a 'connection failed.' After a few of these laggy requests... it comes back up to realtime and usually just works for the several dozen more requests that I attempt, though not always. I haven't found any pattern to 'how many times it works, followed by how many times it fails, or how many times or seconds it's laggy for... it varies with every boot... but follows a sort of general pattern, frustratingly!
Things I've tried - Powering the board through both ports - both from a laptop and from a known-good 110v to USB adapter.
Adding an led that turns on just before the connection is attempted and turns off at the end of the connection routine- when the board lags the led stays on during the hang... then goes off when the 'connection failed' is returned.
Deleting the section that reads input back from the ethernet client and prints it to the terminal - along with varying the terminal speed to make sure that the buffer is getting cleared promptly....
Also I've tried adding a client.close(); when the client.available() goes to zero... which made it stop even attempting the connection most times... and at the end of the button press routine... which didn't seem to change anything...
And I've tried pointing the client at www.google.com instead of the local server, in case the problem was there... but it failed in exactly the same way... and at about the same frequency.
Here's the code...
#include <Ethernet.h>
int buttonState = 0; // variable for reading the pushbutton status
int button2State = 0; // variable for reading the pushbutton status
const int buttonPin = PUSH2;
const int button2Pin = PUSH1;
byte server[] = { 192, 168, 1, 84 };
EthernetClient client;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
Serial.begin(115200);
// start the Ethernet connection:
if (Ethernet.begin(0) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
IPAddress ip = Ethernet.localIP();
Serial.print("IP Address:\t");
Serial.println(ip);
}
void loop()
{
while (client.available()) {
char c = client.read();
Serial.print(c);
}
buttonState = digitalRead(buttonPin);
button2State = digitalRead(button2Pin);
if (buttonState==LOW){
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /telemachus/datalink?a=f.sas HTTP/1.1");
client.println();
} else {
Serial.println("connection failed");
}
delay(200);
}
if (button2State==LOW){
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /telemachus/datalink?a=f.rcs HTTP/1.1");
client.println();
} else {
Serial.println("connection failed");
}
delay(200);
}