HTTP(GET/POST) client see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Dependencies:   GSwifi mbed

Files at this revision

API Documentation at this revision

Comitter:
gsfan
Date:
Mon May 20 01:29:00 2013 +0000
Child:
1:eddcf7c7f8a1
Commit message:
1st build

Changed in this revision

GSwifi.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GSwifi.lib	Mon May 20 01:29:00 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/gsfan/code/GSwifi/#f5f40c92af00
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 20 01:29:00 2013 +0000
@@ -0,0 +1,70 @@
+/*
+ * HTTP client and NTP client
+ */
+
+#include "mbed.h"
+#include "GSwifi.h"
+
+#define HTTP_HOST "www.mbed.org"
+#define HTTP_PORT 80
+#define HTTP_URI "/"
+
+#define SECURE GSwifi::GSSEC_WPA_PSK
+#define SSID "SSID"
+#define PASS "PASSPHRASE"
+
+GSwifi gs(p13, p14, p20); // TX, RX, Reset (no flow control)
+//GSwifi gs(p13, p14, p12, P0_22, p20, NC, 115200); // TX, RX, CTS, RTS, Reset, Alarm
+
+Serial pc(USBTX, USBRX);
+DigitalOut led1(LED1), led2(LED2);
+
+extern "C"
+void HardFault_Handler() {
+    printf("Hard Fault!\r\n");
+    gs.disconnect();
+    exit(-1);
+}
+
+void onGsReceive (int cid, int len) {
+    int i;
+    char buf[GS_DATA_SIZE + 1];
+    
+    led2 = 1;
+    i = gs.recv(cid, buf, len);
+    buf[i] = 0;
+    pc.printf(buf);
+}
+
+int main () {
+    int r;
+    IpAddr ipaddr, netmask, gateway, nameserver;
+    Host host;
+
+    led1 = 1;
+    pc.baud(115200);
+    
+    pc.printf("connecting...\r\n");
+    if (gs.connect(SECURE, SSID, PASS)) {
+        return -1;
+    }
+    gs.getAddress(ipaddr, netmask, gateway, nameserver);
+    pc.printf("ip %d.%d.%d.%d\r\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
+
+    pc.printf("httpGet\r\n");
+    host.setName(HTTP_HOST);
+    host.setPort(HTTP_PORT);
+    r = gs.httpGet(host, HTTP_URI, 0, &onGsReceive);
+    if (r >= 0) {
+        for (;;) {
+            gs.poll();
+            if (! gs.isConnected(r)) break;
+
+            wait_ms(50);
+            led1 = !led1;
+            led2 = 0;
+        }
+    }
+
+    pc.printf("exit\r\n");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 20 01:29:00 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file