gs fan
/
GSwifi_accesspoint
Limited AP for GSwifi see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
main.cpp@1:8787738dafcb, 2012-08-22 (annotated)
- Committer:
- gsfan
- Date:
- Wed Aug 22 00:49:34 2012 +0000
- Revision:
- 1:8787738dafcb
- Parent:
- 0:62a5cb194da6
- Child:
- 2:0fff24372b0b
fix
;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gsfan | 0:62a5cb194da6 | 1 | #include "mbed.h" |
gsfan | 0:62a5cb194da6 | 2 | #include "GSwifi.h" |
gsfan | 0:62a5cb194da6 | 3 | |
gsfan | 0:62a5cb194da6 | 4 | #define PORT 10464 |
gsfan | 0:62a5cb194da6 | 5 | |
gsfan | 0:62a5cb194da6 | 6 | #define SECURE GSSEC_WEP |
gsfan | 0:62a5cb194da6 | 7 | #define SSID "SSID" |
gsfan | 0:62a5cb194da6 | 8 | #define PASS "1234567890" // 10 or 26 hexadecimal digits |
gsfan | 0:62a5cb194da6 | 9 | |
gsfan | 1:8787738dafcb | 10 | GSwifi gs(p13, p14); // TX, RX (no flow control) |
gsfan | 1:8787738dafcb | 11 | // GSwifi gs(p13, p14, p12, P0_22); // TX, RX, CTS, RTS |
gsfan | 0:62a5cb194da6 | 12 | Serial pc(USBTX, USBRX); |
gsfan | 0:62a5cb194da6 | 13 | DigitalOut led1(LED1), led2(LED2); |
gsfan | 0:62a5cb194da6 | 14 | |
gsfan | 0:62a5cb194da6 | 15 | void onGsReceive (int cid, int len) { |
gsfan | 0:62a5cb194da6 | 16 | int i, j; |
gsfan | 0:62a5cb194da6 | 17 | char buf[100]; |
gsfan | 0:62a5cb194da6 | 18 | Host host; |
gsfan | 0:62a5cb194da6 | 19 | |
gsfan | 0:62a5cb194da6 | 20 | led2 = 1; |
gsfan | 0:62a5cb194da6 | 21 | |
gsfan | 0:62a5cb194da6 | 22 | i = gs.recv(cid, buf, sizeof(buf), host); |
gsfan | 0:62a5cb194da6 | 23 | for (j = 0; j < i; j ++) { |
gsfan | 0:62a5cb194da6 | 24 | pc.printf(" %02x", buf[j]); |
gsfan | 0:62a5cb194da6 | 25 | } |
gsfan | 0:62a5cb194da6 | 26 | pc.printf("\r\n"); |
gsfan | 0:62a5cb194da6 | 27 | } |
gsfan | 0:62a5cb194da6 | 28 | |
gsfan | 0:62a5cb194da6 | 29 | int main () { |
gsfan | 0:62a5cb194da6 | 30 | |
gsfan | 0:62a5cb194da6 | 31 | led1 = 1; |
gsfan | 0:62a5cb194da6 | 32 | pc.baud(115200); |
gsfan | 0:62a5cb194da6 | 33 | |
gsfan | 0:62a5cb194da6 | 34 | pc.printf("limitedap\r\n"); |
gsfan | 0:62a5cb194da6 | 35 | if (gs.limitedap(SECURE, SSID, PASS, IpAddr(192,168,15,5), IpAddr(255,255,255,0))) { |
gsfan | 0:62a5cb194da6 | 36 | return -1; |
gsfan | 0:62a5cb194da6 | 37 | } |
gsfan | 0:62a5cb194da6 | 38 | |
gsfan | 0:62a5cb194da6 | 39 | pc.printf("listen\r\n"); |
gsfan | 0:62a5cb194da6 | 40 | gs.listen(PORT, GSPROT_UDP, &onGsReceive); |
gsfan | 0:62a5cb194da6 | 41 | |
gsfan | 0:62a5cb194da6 | 42 | for (;;) { |
gsfan | 0:62a5cb194da6 | 43 | gs.poll(); |
gsfan | 0:62a5cb194da6 | 44 | |
gsfan | 0:62a5cb194da6 | 45 | wait_ms(50); |
gsfan | 0:62a5cb194da6 | 46 | led1 = !led1; |
gsfan | 0:62a5cb194da6 | 47 | led2 = 0; |
gsfan | 0:62a5cb194da6 | 48 | } |
gsfan | 0:62a5cb194da6 | 49 | } |