Hello there!
I try to get data from a website, it's only plain text, with json format. Sadly I'm not able to receive the data, it seems like the server is refusing my request.
The code I'm using is based on the webclient example from EtherCard.
Here is my code:
// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
/*
* Pin VCC -> +3.3V (rightmost, when facing the display head-on)
* Pin GND -> GND
* Pin CS -> Arduino digital pin 8
* Pin SI -> Arduino digital pin 11
* Pin SO -> Arduino digital pin 12
* Pin SCK-> Arduino digital pin 13
*/
#include <EtherCard.h>
#include <PCD8544.h>
#define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)
#if STATIC
// ethernet interface ip address
static byte myip[] = { 10,0,0,200 };
// gateway ip address
static byte gwip[] = { 10,0,0,138 };
#endif
//Display
static unsigned const int led = 10;
static PCD8544 lcd;
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
static uint32_t timer;
char website[] PROGMEM = "www.wienerlinien.at";
// called when the client request is complete
static void my_callback (byte status, word off, word len) {
Serial.println(">>>");
Ethernet::buffer[off+300] = 0;
Serial.print((const char*) Ethernet::buffer + off);
Serial.println("...");
lcd.setCursor(0, 0);
lcd.print((const char*) Ethernet::buffer + off);
}
void setup(){
// PCD8544-compatible displays may have a different resolution...
lcd.begin(84, 48);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
lcd.setCursor(0, 0);
lcd.print("U4-OSV");
Serial.begin(57600);
Serial.println("\n[Starting program to connect to wienerlinien.at]");
Serial.println( "Initialize ethernet controller");
timer = millis();
if (ether.begin(sizeof Ethernet::buffer, mymac, 8) == 0) {
Serial.println( "Failed to access Ethernet controller");
}
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup()) {
lcd.setCursor(0, 3);
lcd.print( "DHCP failed");
}
#endif
Serial.println( "DNS Lookup, might take a while");
if (!ether.dnsLookup(website)) {
Serial.println("DNS failed");
}
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
ether.printIp("SRV: ", ether.hisip);
Serial.println( "Setup finished!");
}
void loop(){
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
lcd.setCursor(0, 1);
lcd.print( "checking...");
timer = millis() + 150000;
Serial.println();
Serial.print("<<< REQ ");
ether.browseUrl(PSTR("/ogd_realtime/monitor?"), "rbl=4403&sender=te0KFsznWK", website, my_callback);
}
}
Side note: I needed to set the ip manually to make it work
I do get a correct ip and dns:
IP: 10.0.0.200
GW: 10.0.0.138
DNS: 8.8.8.8
SRV: 193.178.171.175
The error I get is this one:
HTTP/1.1 415 Unsupported Media Type
Date: Thu, 06 Feb 2014 16:31:29 GMT
Server: Apache
X-Powered-By: Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0
Content-Length: 1048
Connection: close
Content-Type: text/html;charset=utf-8
Set-Cookie: NSC_MCwtsw-Q-...
The data I want to get can be found here: http://www.wienerlinien.at/ogd_realtime/monitor?rbl=4403&sender=te0KFsznWK
Any help is highly appreciated, I've got no clue, whats wrong.