Fair enough, I didn't post the code initially because, as mentioned, it works fine on other networks.
Here it is:
/*
* http client that get new zealand 'felt' earthquake data from http://www.geonet.org.nz/quakes/
* Parses returned XML to get magnitude and approximate location from XML title
* Based on Twitter Client example from Arduino.cc
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
//0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
0x90, 0xA2, 0xDA, 0X0D, 0XB1, 0XA7}; //FROM STICKER ON BOTTOM OF SHIELD
IPAddress ip(192,168,1,20);
// initialize the library instance:
EthernetClient client;
const unsigned long requestInterval = 60000; // delay between requests
char serverName[] = "www.geonet.org.nz";
boolean requested; // whether you've made a request since connecting
unsigned long lastAttemptTime = 0; // last time you connected to the server, in milliseconds
String currentLine = ""; // string to hold the text from server
String xmlData = ""; // string to hold the tweet
String previousXmlData = "";
boolean readingXmlData = false; // if you're currently reading the tweet
String magnitudeString;
//String [] dataBits;
int ledPin = 12;
//Motor
int motorPin = 9;
int numbers [10] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int decNumbers [10] = {
48, 49, 50, 51, 52, 53, 54, 55, 56, 57};
void setup() {
pinMode (ledPin, OUTPUT);
// reserve space for the strings:
currentLine.reserve(256);
xmlData.reserve(150);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// attempt a DHCP connection:
Serial.println("Attempting to get an IP address using DHCP:");
if (!Ethernet.begin(mac)) {
// if DHCP fails, start with a hard-coded address:
Serial.println("failed to get an IP address using DHCP, trying manually");
Ethernet.begin(mac, ip);
}
Serial.print("My address:");
Serial.println(Ethernet.localIP());
connectToServer();
}
void loop()
{
if (client.connected()) {
//delay (2000);
if (client.available()) {
// read incoming bytes:
char inChar = client.read();
// add incoming byte to end of line:
currentLine += inChar;
// if you get a newline, clear the line:
if (inChar == '\n') {
currentLine = "";
}
//if the current line ends with <item>, it will
// be followed by the title:
if ( currentLine.endsWith("<title>Magnitude ")) {
// tweet is beginning. Clear the tweet string:
readingXmlData = true;
xmlData = "";
}
// if you're currently reading the bytes of data,
// add them to the data String:
if (readingXmlData) {
if (inChar != '<') {
xmlData += inChar;
}
else {
// if you got a "<" character,
// you've reached the end of the tweet:
readingXmlData = false;
Serial.print("xmlData:");
Serial.println(xmlData);
// close the connection to the server:
client.stop();
//check its different
if (xmlData != previousXmlData){//
Serial.println("NEW EARTHQUAKE");
// CHECK FOR PHRASE 'CHRISTCHURCH'
if(xmlData.endsWith("Christchurch")){
// does it say 'christchurch'?
parseData(xmlData);
previousXmlData = xmlData;
Serial.print("previousXmlData:");
Serial.println(previousXmlData);
}
else{
Serial.println("EARTHQUAKE NOT LOCATED NEAR CHRISTCHURCH");
}
}else{
Serial.println("NO NEW EARTHQUAKES");
}
}
}
}
else if (!client.available()){
//tweet status CLIENT NOT AVALABLE
Serial.println ("client not available");
delay (5000);
}
}
else if (millis() - lastAttemptTime > requestInterval) {
// if you're not connected, and two minutes have passed since
// your last connection, then attempt to connect again:
connectToServer();
}
}
void connectToServer() {
// attempt to connect, and wait a millisecond:
Serial.println("connecting to server...");
if (client.connect(serverName, 80)) {
Serial.println("making HTTP request...");
// make HTTP GET request:
client.println("GET /quakes/services/felt.rss HTTP/1.1");
client.println("HOST: www.geonet.org.nz");
client.println();
Serial.println ("Just Connected");
}
// note the time of this connect attempt:
lastAttemptTime = millis();
}
// EXAMPLE RESPONSE: 2.3, Wednesday, March 6 2013 at 12:06:18 am (NZDT), 5 km east of Porangahau
void parseData(String data){
// parse the earthquake title to get data
//String dataArray [] = split(data, ',');
String buffer = "";
//buffer = data.toCharArray(buffer, data.length());
Serial.print("data length: ");
Serial.println(data.length());
for (int i=0; i<data.length();i++){
char x = data.charAt(i);
if (x != ',') {
buffer += x;
}
else {
// if you got a "," character,
// you've reached the end this bit of data:
if(buffer.length() == 4){
magnitudeString = buffer;
magnitudeString.trim();
byte magBytes[magnitudeString.length() + 1];
magnitudeString.getBytes(magBytes, magnitudeString.length() + 1);
int magIntBuffer;
char magCharBuff [4];
magnitudeString.toCharArray(magCharBuff, 4);
float magFloat = atof(magCharBuff);
Serial.print ("magFloat: ");
Serial.println (magFloat);
int magInt = map(magFloat*100, 100, 800, 100, 255);
//
int durationInt = map(magInt, 100, 255, 1000, 5000);
Serial.print ("duration: ");
Serial.println (durationInt);
driveMotor(magInt, durationInt);
}
else{
// ignore
}
}
}
}
So is it possible that there's an error that gets through other networks, but causes it to fail on this particular one? Might it be caused by specifying an IP address and then attempting to get one with DHCP?
Other details - its the Official Arduino ethernet shield with POE