gs fan
/
GSwifi_https_get
HTTPS(SSL) client and NTP client for GSwifi see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
Diff: main.cpp
- Revision:
- 0:4916aa89d55c
- Child:
- 1:b06de786490e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Aug 21 07:55:16 2012 +0000 @@ -0,0 +1,63 @@ +#include "mbed.h" +#include "GSwifi.h" + +#define SECURE GSSEC_WPA_PSK + +#define SSID "SSID" +#define PASS "password" + +#define HTTP_HOST "secure.domain.name" +#define HTTP_URI "/index.html" + +GSwifi gs(p13, p14, p12, P0_22); // TX, RX, CTS, RTS +Serial pc(USBTX, USBRX); +DigitalOut led1(LED1), led2(LED2); + +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; + time_t time; + struct tm *t; + + led1 = 1; + pc.baud(115200); + + pc.printf("connect\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("ntpdate\r\n"); + host.setName("ntp.jst.mfeed.ad.jp"); + gs.ntpdate(host); + time = gs.getTime() + (9 * 60 * 60); + t = localtime(&time); + pc.printf("%04d-%02d-%02d, %02d:%02d:%02d\r\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); + + pc.printf("httpGet\r\n"); + host.setName(HTTP_HOST); + r = gs.httpGet(host, HTTP_URI, 1, &onGsReceive); + if (r >= 0) { + for (;;) { + gs.poll(); + if (! gs.isConnected(r)) break; + + wait_ms(50); + led1 = !led1; + led2 = 0; + } + } +}