Hello all,
I've done lots of searching and hours of trying to figure this out myself and am stuck. I'm working with some local high school students to make a machine that needs to know the local ocean tide height as an input.
NOAA has a very rich API that can provide me this data; the exact information I need (should) be visible to you if you load http://tidesandcurrents.noaa.gov/api/datagetter?date=latest&station=8516945&product=one_minute_water_level&datum=STND&units=metric&time_zone=gmt&application=web_services&format=xml
(The height data we need is tagged with "v". If you want to read NOAA's API documentation, head over to http://tidesandcurrents.noaa.gov/api/.)
I've modified the built-in "Web Client" example to request this data. Here is the code I'm running:
/*
Web client modified to read wave height data
This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x9C, 0xEB };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "http://tidesandcurrents.noaa.gov"; // name address for Google (using DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,177);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /api/datagetter?date=latest&station=8516945&product=one_minute_water_level&datum=STND&units=metric&time_zone=gmt&application=web_services&format=xml HTTP/1.0");
client.println("Host: tidesandcurrents.noaa.gov");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
}
}
However, though I've confirmed that the Ethernet shield is online and functioning (running the original, unmodified version of this code works as it should), I get the following serial output when I run the above sketch:
connecting...
connecteddisconnecting.
I've tried to modify the code posted in Getting Weather Data from XML with Ehernet Shield - Programming Questions - Arduino Forum for the present purpose but 1) the Google API is long gone so I can't even use it as a test case and 2) regardless, even configuring that code to retrieve from NOAA, I don't get any data back.
Any help is greatly appreciated! I've been stumped with this all afternoon.