Permalink
Browse files

ATS_ClientTest added.

  • Loading branch information...
1 parent d51b6c3 commit ad99823eed164141cb9602bb5ff1b12361e50b19 @ricklon ricklon committed Mar 29, 2012
Showing with 154 additions and 2 deletions.
  1. +58 −0 examples/ATS_ClientTest/ATS_ClientTest.ino
  2. +96 −2 examples/ATS_httpClientTest/ATS_httpClientTest.ino
@@ -0,0 +1,58 @@
+/*
+* ATS Client test
+ *
+ *
+ */
+#include <ArduinoTestSuite.h>
+#include <SPI.h>
+#include <Ethernet.h>
+
+byte mac[] = {
+ 0xCE,0x63,0xEB,0xBC,0x7A,0x1C };
+// 0xE1,0x3E,0x5A,0x49,0xEB,0xA9};
+
+EthernetClient client;
+
+void setup()
+{
+ int startMemoryUsage;
+ Ethernet.begin(mac);
+ startMemoryUsage = ATS_GetFreeMemory();
+ ATS_begin("Arduino 1.0", "ATS_httpClient Tests");
+
+ ATS_PrintTestStatus("1. DCHCP Address obtained", testDHCP());
+
+ ATS_ReportMemoryUsage(startMemoryUsage);
+ ATS_end();
+
+}
+
+//Test if IP DHCP address receieved
+boolean testDHCP()
+{
+ Serial.println("testDHCP");
+
+ int temp = 0;
+ IPAddress ip = Ethernet.localIP();
+ int length = Serial.println(ip);
+ Serial.println(length);
+
+ for (int nn = 0; nn < 4; nn++)
+ {
+ temp = temp + ip[nn];
+ }
+ if (temp == 0)
+ {
+ return false;
+ }
+ return true;
+}
+
+
+void loop()
+{
+
+
+}
+
+
@@ -5,22 +5,36 @@
*/
#include <ArduinoTestSuite.h>
#include <SPI.h>
+#include <HttpClient.h>
+#include <b64.h>
#include <Ethernet.h>
+#include <EthernetClient.h>
+
+const char* kHostname = "127.0.0.1";
+
+const char kPath[] = "/";
byte mac[] = {
0xCE,0x63,0xEB,0xBC,0x7A,0x1C };
// 0xE1,0x3E,0x5A,0x49,0xEB,0xA9};
+// Number of milliseconds to wait without receiving any data before we give up
+const int kNetworkTimeout = 30*1000;
+// Number of milliseconds to wait if no data is available before trying again
+const int kNetworkDelay = 1000;
+
+
EthernetClient client;
void setup()
{
int startMemoryUsage;
Ethernet.begin(mac);
startMemoryUsage = ATS_GetFreeMemory();
- ATS_begin("Arduino 1.0", "ATS_httpClient Tests");
+ ATS_begin("Arduino 1.0", "ATS_HttpClient Tests");
- ATS_PrintTestStatus("1. DCHCP Address obtained", testDHCP());
+ ATS_PrintTestStatus("1. DHCP Address obtained", testDHCP());
+ ATS_PrintTestStatus("2. HTTPClient single run", testHTTPClient());
ATS_ReportMemoryUsage(startMemoryUsage);
ATS_end();
@@ -48,6 +62,86 @@ boolean testDHCP()
return true;
}
+boolean testHTTPClient()
+{
+ int err =0;
+
+ EthernetClient c;
+ HttpClient http(c);
+
+ err = http.get(kHostname, 80, kPath);
+ if (err == 0)
+ {
+ Serial.println("startedRequest ok");
+
+ http.finishRequest();
+
+ err = http.responseStatusCode();
+ if (err >= 0)
+ {
+ Serial.print("Got status code: ");
+ Serial.println(err);
+
+ // Usually you'd check that the response code is 200 or a
+ // similar "success" code (200-299) before carrying on,
+ // but we'll print out whatever response we get
+
+ err = http.skipResponseHeaders();
+ if (err >= 0)
+ {
+ int bodyLen = http.contentLength();
+ Serial.print("Content length is: ");
+ Serial.println(bodyLen);
+ Serial.println();
+ Serial.println("Body returned follows:");
+
+ // Now we've got to the body, so we can print it out
+ unsigned long timeoutStart = millis();
+ char c;
+ // Whilst we haven't timed out & haven't reached the end of the body
+ while ( (http.connected() || http.available()) &&
+ ((millis() - timeoutStart) < kNetworkTimeout) )
+ {
+ if (http.available())
+ {
+ c = http.read();
+ // Print out this character
+ Serial.print(c);
+
+ bodyLen--;
+ // We read something, reset the timeout counter
+ timeoutStart = millis();
+ }
+ else
+ {
+ // We haven't got any data, so let's pause to allow some to
+ // arrive
+ delay(kNetworkDelay);
+ }
+ }
+ }
+ else
+ {
+ Serial.print("Failed to skip response headers: ");
+ Serial.println(err);
+ }
+ }
+ else
+ {
+ Serial.print("Getting response failed: ");
+ Serial.println(err);
+ }
+ }
+ else
+ {
+ Serial.print("Connect failed: ");
+ Serial.println(err);
+ }
+ http.stop();
+
+ return false;
+}
+
void loop()
{

0 comments on commit ad99823

Please sign in to comment.