24 #include <FlowScanner.h>
32 #define DHCP_ENABLE true
34 static const uint8_t
CS_PIN = 10;
54 DEFINE_FLOWPATTERN(temperaturePattern,
"\"temp\":%7[^,]");
65 request(F(
"api.openweathermap.org"), F(
"/data/2.5/weather?q=Madrid,es&units=metric"));
76 ACTRACE(
"HTTP status=%d", statusCode);
79 Serial.print(F(
"Server error, status code="));
80 Serial.println(statusCode);
88 scanner.setPattern(temperaturePattern);
93 ACTRACE(
"HTTP bytes received=%d", len);
95 byte* buf = (byte*)data;
97 if (temperaturePattern.signaled)
100 if (scanner.scan(&buf, &len, temp))
102 float t = atof(temp);
104 Serial.print(F(
"The temperature is "));
114 ACTRACE(
"HTTP session end");
120 unsigned long waitTimer = 0;
124 Serial.begin(115200);
126 Serial.println(F(
"EtherDune HTTPClient sample"));
127 Serial.print(F(
"Free RAM: ")); Serial.println(ACross::getFreeRam());
129 Serial.println(F(
"Press any key to start..."));
131 while (!Serial.available());
137 ACERROR(
"failed to start EtherDune");
138 Serial.println(F(
"failed to start EtherDune"));
141 ACINFO(
"waiting for link...");
145 ACINFO(
"link is up");
149 Serial.println(
"Obtaining DHCP configuration...");
153 Serial.println(F(
"DHCP setup failed"));
157 Serial.println(F(
"DHCP setup OK"));
159 Serial.println(F(
"DHCP config:"));
160 Serial.print(F(
"Local IP: "));
162 Serial.print(F(
"Network mask: "));
164 Serial.print(F(
"Gateway IP: "));
166 Serial.print(F(
"DNS IP: "));
178 Serial.println(
"Connecting...");
void request(const String &hostName, const String &resource, uint16_t port=80)
Starts a new HTTP request.
virtual void onResponseReceived()
Called immediately after the first line is received and there is a status code, e.g.
#define IPAddress_P
helper macro to store an IP address in PROGMEM
virtual void onBodyBegin()
Called when all HTTP headers have been received and the body of the response is about to arrive...
static IPAddress_P gatewayIP
static bool begin(uint8_t cspin)
Initializes EtherDune and the underlying hardware
static IPAddress netmask
Subnet mask.
static IPAddress gatewayIP
IP address of the gateway in this network.
static const uint8_t CS_PIN
bool dhcpSetup()
Attempts to configure the IP settings: local IP, subnet mask, gateway and DNS via DHCP...
static MACAddress_P mymac
static bool isLinkUp()
Determines whether the network link is ready
static const uint16_t HTTP_RESPONSE_OK
The request has succeeded.
Provides an easy way to query a web server.
static IPAddress dnsIP
IP address of the DNS server to use.
static MACAddress localMAC
Ethernet MAC address.
virtual void onBodyReceived(uint16_t len, const byte *data)
Called once for each fragment of the body that is received.
static void loop()
Gives processing time to EtherDune so that it can check for incoming packets or send queued packets...
void terminate()
Immediately shuts down the socket and makes it available for a new task.
static IPAddress localIP
IP address of this application.
virtual void onHeaderReceived(uint16_t len, const byte *data)
Called once for each fragment of the header portion of the response
virtual void onResponseEnd()
Called after all the body has been received
void close()
Attempts to gracefully close a connection.
static IPAddress_P netmask