Hey,
I've used the Arduino XML weather parser for more than two years to get data from this website: http://www.ivb.at/...
Until last week, the code worked just fine. Now it just connects but can't retrieve any data. Obviously, there was a server-update and a slight change in the structure of the XML file, but the tags stayed the same.
So here is the code (I just replaced the mac/ip address):
//1/6/08 Bob S. - Created
#include <string.h>
#include <Ethernet.h>
#include <SPI.h>
#define MAX_STRING_LEN 20
char tagStr[MAX_STRING_LEN] = "";
char dataStr[MAX_STRING_LEN] = "";
char tmpStr[MAX_STRING_LEN] = "";
char endTag[3] = {'<', '/', '\0'};
int len;
boolean tagFlag = false;
boolean dataFlag = false;
byte mac[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte ip[] = {
000, 00, 000, 000 };
byte server[] = {
83, 175, 126, 90 };
EthernetClient client;
void setup()
{
Serial.begin(9600);
Serial.println("connecting...");
Ethernet.begin(mac, ip);
delay(1000);
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /smartinfo/ivb_smartinfo_kernel.php?olifServerId=84&autorefresh=20&default_autorefresh=20&routeId=&stopId=Absam%20Dorf&optDir=-1&nRows=4&showArrivals=n&optTime=now&time=&allLines=y&app=sionline HTTP/1.1");
client.println();
delay(2000);
} else {
Serial.println("connection failed");
}
}
void loop() {
while (client.available()) {
serialEvent();
}
if (!client.connected()) {
client.stop();
for (int t = 1; t <= 15; t++) {
delay(60000);
}
if (client.connect(server, 80)) {
client.println("GET /smartinfo/ivb_smartinfo_kernel.php?olifServerId=84&autorefresh=20&default_autorefresh=20&routeId=&stopId=Absam%20Dorf&optDir=-1&nRows=4&showArrivals=n&optTime=now&time=&allLines=y&app=sionline HTTP/1.1");
client.println();
delay(2000);
} else {
Serial.println("Reconnect failed");
}
}
}
void serialEvent() {
char inChar = client.read();
if (inChar == '<') {
addChar(inChar, tmpStr);
tagFlag = true;
dataFlag = false;
} else if (inChar == '>') {
addChar(inChar, tmpStr);
if (tagFlag) {
strncpy(tagStr, tmpStr, strlen(tmpStr)+1);
}
clearStr(tmpStr);
tagFlag = false;
dataFlag = true;
} else if (inChar != 10) {
if (tagFlag) {
addChar(inChar, tmpStr);
if ( tagFlag && strcmp(tmpStr, endTag) == 0 ) {
clearStr(tmpStr);
tagFlag = false;
dataFlag = false;
}
}
if (dataFlag) {
addChar(inChar, dataStr);
}
}
if (inChar == 10 ) {
/*
Serial.print("tagStr: ");
Serial.println(tagStr);
Serial.print("dataStr: ");
Serial.println(dataStr);
*/
if (matchTag("<route>")) {
Serial.print(dataStr);
}
if (matchTag("<direction>")) {
Serial.print(dataStr);
}
if (matchTag("<time>")) {
Serial.print(dataStr);
}
clearStr(tmpStr);
clearStr(tagStr);
clearStr(dataStr);
tagFlag = false;
dataFlag = false;
}
}
void clearStr (char* str) {
int len = strlen(str);
for (int c = 0; c < len; c++) {
str[c] = 0;
}
}
void addChar (char ch, char* str) {
char *tagMsg = "<TRUNCATED_TAG>";
char *dataMsg = "-TRUNCATED_DATA-";
if (strlen(str) > MAX_STRING_LEN - 2) {
if (tagFlag) {
clearStr(tagStr);
strcpy(tagStr,tagMsg);
}
if (dataFlag) {
clearStr(dataStr);
strcpy(dataStr,dataMsg);
}
clearStr(tmpStr);
tagFlag = false;
dataFlag = false;
} else {
str[strlen(str)] = ch;
}
}
boolean matchTag (char* searchTag) {
if ( strcmp(tagStr, searchTag) == 0 ) {
return true;
} else {
return false;
}
}
There is no problem with the internet connection or with the server. The Arduino Ethernet Example (WebClient) retrieves the whole XML file. Probably it's a problem with the tags or with the inChar...
Any help is appreciated
Max