Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "GSwifi.h" 00003 00004 #define SECURITY GSSEC_WPA_PSK 00005 #define SSID "WIFISSID" 00006 #define PASSPHRASE "TESTPASS" 00007 00008 00009 Serial pc(USBTX, USBRX); 00010 DigitalOut myled(LED1); 00011 00012 GSwifi gs(p13, p14, p12, P0_22); // TX, RX, CTS, RTS 00013 00014 00015 int main() { 00016 Host host; 00017 int sk; 00018 00019 pc.baud(115200); 00020 pc.printf("Gainspan\r\n"); 00021 00022 if (gs.connect(SECURITY, SSID, PASSPHRASE)) { 00023 pc.printf("Can't connected.\r\n"); 00024 return -1; 00025 } 00026 // if (gs.setAddress(IpAddr(192,168,1,123), IpAddr(255,255,255,0), IpAddr(192,168,1,1), IpAddr(192,168,1,1))) { 00027 if (gs.setAddress()) { 00028 pc.printf("error: dhcp\r\n"); 00029 return -1; 00030 } 00031 00032 host.setName("mbed.org"); 00033 host.setPort(80); 00034 if (! gs.getHostByName(host)) { 00035 pc.printf("resolv %d.%d.%d.%d\r\n", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3]); 00036 00037 sk = gs.open(host, GSPROT_TCP); 00038 if (sk >= 0) { 00039 int i; 00040 char buf[1500]; 00041 00042 gs.send(sk, "GET / HTTP/1.0", 18); 00043 gs.send(sk, "\r\n", 2); 00044 gs.send(sk, "\r\n", 2); 00045 wait_ms(1000); 00046 00047 i = gs.recv(sk, buf, sizeof(buf)); 00048 if (i) { 00049 buf[i] = 0; 00050 pc.printf("\r\n"); 00051 pc.printf(buf); 00052 } 00053 00054 gs.close(sk); 00055 } 00056 } 00057 00058 myled = 1; 00059 for (;;) { 00060 if (pc.readable()) gs.putc(pc.getc()); 00061 if (gs.readable()) pc.putc(gs.getc()); 00062 } 00063 }
Generated on Sun Jul 24 2022 02:59:40 by
1.7.2