Work with nodejs server: https://github.com/bjo3rn/idd-examples/tree/ben-node-demo/web/nodeServerHTTPSocket
Dependencies: HTTPClient WebSocketClient cc3000_hostdriver_mbedsocket mbed
Fork of CC3000_demo by
Revision 14:efd42910791b, committed 2014-10-20
- Comitter:
- nebgnahz
- Date:
- Mon Oct 20 06:58:24 2014 +0000
- Parent:
- 13:26905142e97b
- Child:
- 15:ac15ec676d87
- Commit message:
- new revision that works with husk server
Changed in this revision
| HTTPClient.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/HTTPClient.lib Sun Oct 19 07:05:29 2014 +0000 +++ b/HTTPClient.lib Mon Oct 20 06:58:24 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/donatien/code/HTTPClient/#277279a1891e +http://developer.mbed.org/users/nebgnahz/code/HTTPClient/#25e3d3516a03
--- a/main.cpp Sun Oct 19 07:05:29 2014 +0000
+++ b/main.cpp Mon Oct 20 06:58:24 2014 +0000
@@ -1,18 +1,18 @@
/**
-* \brief CS294-84 demo
-* \author Ben Zhang, Antonio Iannopollo
-*
-* This sampel code illustrates how to connect the mbed KL25Z platform to internet
-* thorugh the CC3000 wifi breakout board (http://www.adafruit.com/product/1469).
-* Connections between the KL25Z and the CC3000 are made according to the
-* guide at https://learn.adafruit.com/adafruit-cc3000-wifi -- KL25Z and arduino
-* UNO are pin to pin compatible --
-*
-* This application uses the following libraries:
-* - cc3000_hostdriver_mbedsocket
-* (http://developer.mbed.org/users/Kojto/code/cc3000_hostdriver_mbedsocket/)
-* - HTTPClient (http://developer.mbed.org/users/donatien/code/HTTPClient/)
-*/
+ * \brief CS294-84 demo
+ * \author Ben Zhang, Antonio Iannopollo
+ *
+ * This sampel code illustrates how to connect the mbed KL25Z platform to internet
+ * thorugh the CC3000 wifi breakout board (http://www.adafruit.com/product/1469).
+ * Connections between the KL25Z and the CC3000 are made according to the
+ * guide at https://learn.adafruit.com/adafruit-cc3000-wifi -- KL25Z and arduino
+ * UNO are pin to pin compatible --
+ *
+ * This application uses the following libraries:
+ * - cc3000_hostdriver_mbedsocket
+ * (http://developer.mbed.org/users/Kojto/code/cc3000_hostdriver_mbedsocket/)
+ * - HTTPClient (http://developer.mbed.org/users/donatien/code/HTTPClient/)
+ */
#include "mbed.h"
#include "cc3000.h"
@@ -27,13 +27,15 @@
// - SPI MISO => (pin D12)
// - SPI CLK => (pin D13)
// plus wifi network SSID, password, security level and smart-configuration flag.
-mbed_cc3000::cc3000 wifi(D3, D5, D10, SPI(D11, D12, D13), "SSID", "PASSWORD", WPA2, false);
+mbed_cc3000::cc3000 wifi(D3, D5, D10, SPI(D11, D12, D13),
+ "EECS-PSK", "Thequickbrown", WPA2, false);
// create an http instance
HTTPClient http;
// str is used to hold the response data
char str[512];
+char url[80];
// setup the serial connection, and LEDs
Serial pc(USBTX, USBRX);
@@ -55,24 +57,31 @@
if(wifi.is_connected() == false) {
// try to connect
if (wifi.connect() == -1) {
- printf("Failed to connect. Please verify connection details and try again. \r\n");
+ pc.printf("Failed to connect."
+ "Please verify connection details and try again. \r\n");
} else {
- printf("IP address: %s \r\n", wifi.getIPAddress());
+ pc.printf("IP address: %s \r\n", wifi.getIPAddress());
//once connected, turn green LED on and red LED off
led_red = 1;
led_green = 0;
}
} else {
- int ret = http.get("http://www.eecs.berkeley.edu/~benzh/hello.txt", str, 128);
+ // get input url and then return the value
+ pc.printf("> ");
+ pc.scanf("%s", url);
+
+ int ret = http.get(url, str, 128);
if (!ret) {
- printf("Page fetched successfully - read %d characters\r\n", strlen(str));
- printf("Result: %s\r\n", str);
+ pc.printf("Requested %s\r\n", url);
+ pc.printf("Page fetched successfully - read %d characters\r\n",
+ strlen(str));
+ pc.printf("Result: %s\r\n", str);
} else {
- printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode());
+ pc.printf("Error - ret = %d - HTTP return code = %d\r\n",
+ ret,
+ http.getHTTPResponseCode());
}
}
- // repeat after waiting for 1 sec
- wait(1.0);
}
-}
\ No newline at end of file
+}
