I have sketch that sends the same message out thru the ethernet bridge. It always works for the first or second (sometimes 3 times) as the logic passes thru section K but eventually it starts to fail. I've tried experimenting with long delay times but nothing seems to help. I even tried a programmatic reset of the ethernet board (not recommend, I know) but that didn't even help.
#include <stdio.h>
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
// Wired Ethernet
EthernetClient client;
byte MAC_ADDR[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x28, 0x43 }; // MAC of Arduino Ethernet Shield
IPAddress MY_IP(192, 168, 1, 177);
char* SERVER = "www.XXXXXXXX.com";
unsigned int PORT = 80;
// Miscellaneous
int WS_SUB;
int WS_SUBQ;
int WS_SUBT;
int WS_SUB_MAX = 5;
String WS_TEXT_MSG;
String WS_STRING;
String WS_TRACE_VALUE;
int WS_DISPLAY_CTR = 0;
String WS_DISPLAY_TRACE = "Y";
String WS_YES = "Y";
// PROCEDURE DIVISION
void setup()
{
// one time setups are in section B
}
void loop()
{
A_MAINLINE_SECTION:
A010_MAINLINE:
A020:
{
B_INITIALIZE();
}
A050_SEND_TEXT:
{
WS_TEXT_MSG = "TestTextABCDEFG";
K_SEND_TEXT();
delay(1000);
goto A050_SEND_TEXT;
}
}
void B_INITIALIZE()
{
B010_INIT_SERIAL_COMM:
{
Serial.begin(9600);
delay(1000);
}
B020_INIT_ETHERNET:
{
Ethernet.begin(MAC_ADDR, MY_IP);
delay(1000);
}
}
void K_SEND_TEXT()
{
K010_CONNECT:
{
Serial.print("Connecting to: ");
Serial.print(SERVER);
Serial.print(" ");
Serial.print("Port: ");
Serial.print(PORT);
if (client.connect(SERVER, PORT) <= 0)
{
goto K090;
}
}
K040_CONNECTION_OK:
{
Serial.println(" connected.");
}
K050_SEND:
{
Serial.print("TextMsg:");
Serial.println(WS_TEXT_MSG);
client.println("GET /arduino/YYYYYYYYYY/" +
WS_TEXT_MSG.substring(0,10) +
" HTTP/1.1");
client.println("Host: www.XXXXXXXX.com");
client.println("Connection: close");
client.println();
delay (2000);
// WAIT until server has sent bytes to this client and then
// read and print the message
while (client.available())
{
char READ_BUFFER = client.read();
Serial.print(READ_BUFFER);
WS_STRING += READ_BUFFER;
}
// Serial.println("Message returned from server:");
// Serial.println (WS_STRING);
}
K090:
{
Serial.println("Disconnecting.");
client.stop();
}
}
void T_TRACE()
{
T010:
{
if (WS_DISPLAY_CTR >= 1)
goto T020;
// first time, send CR & LF
Serial.print ("\n");
}
T020:
{
if (WS_DISPLAY_TRACE == WS_YES)
{
Serial.print(WS_TRACE_VALUE);
Serial.print("\n");
WS_DISPLAY_CTR = WS_DISPLAY_CTR + 1;
}
}
}