HoYa's MBED (Nucleo-F401RE)
Dependencies: NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed
main.cpp@1:b2b7580e09d7, 2017-07-20 (annotated)
- Committer:
- HoYa
- Date:
- Thu Jul 20 07:50:49 2017 +0000
- Revision:
- 1:b2b7580e09d7
- Parent:
- 0:63d30ec829b6
- Child:
- 2:d7647babe160
DNS Testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
HoYa | 0:63d30ec829b6 | 1 | #include "mbed.h" |
HoYa | 0:63d30ec829b6 | 2 | #include "SpwfInterface.h" |
HoYa | 1:b2b7580e09d7 | 3 | #include "TCPSocket.h" |
HoYa | 0:63d30ec829b6 | 4 | |
HoYa | 0:63d30ec829b6 | 5 | Serial pc(USBTX, USBRX, 115200); |
HoYa | 0:63d30ec829b6 | 6 | DigitalOut led(LED1); |
HoYa | 0:63d30ec829b6 | 7 | |
HoYa | 1:b2b7580e09d7 | 8 | SpwfSAInterface spwf(D8, D2, false); |
HoYa | 0:63d30ec829b6 | 9 | |
HoYa | 0:63d30ec829b6 | 10 | int main() { |
HoYa | 0:63d30ec829b6 | 11 | pc.printf("\r\n"); |
HoYa | 0:63d30ec829b6 | 12 | pc.printf("Start Application\r\n"); |
HoYa | 0:63d30ec829b6 | 13 | |
HoYa | 1:b2b7580e09d7 | 14 | pc.printf("\r\n"); |
HoYa | 0:63d30ec829b6 | 15 | pc.printf("Connecting to AP...\r\n"); |
HoYa | 0:63d30ec829b6 | 16 | if (spwf.connect("hRPi3-AP", "rlawjdgh", NSAPI_SECURITY_WPA2)) { |
HoYa | 1:b2b7580e09d7 | 17 | // if (spwf.connect("RP_RND_A", "radio1106", NSAPI_SECURITY_WPA2)) { |
HoYa | 0:63d30ec829b6 | 18 | pc.printf("=> Success.\r\n"); |
HoYa | 0:63d30ec829b6 | 19 | } else { |
HoYa | 0:63d30ec829b6 | 20 | pc.printf("=> Failed to connect.\r\n"); |
HoYa | 0:63d30ec829b6 | 21 | return -1; |
HoYa | 1:b2b7580e09d7 | 22 | } |
HoYa | 0:63d30ec829b6 | 23 | const char* ip = spwf.get_ip_address(); |
HoYa | 0:63d30ec829b6 | 24 | pc.printf("=> IP Address is: %s\r\n", (ip) ? ip : "No IP"); |
HoYa | 0:63d30ec829b6 | 25 | const char* mac = spwf.get_mac_address(); |
HoYa | 0:63d30ec829b6 | 26 | pc.printf("=> MAC Address is: %s\r\n", (mac) ? mac : "No MAC"); |
HoYa | 1:b2b7580e09d7 | 27 | |
HoYa | 1:b2b7580e09d7 | 28 | pc.printf("\r\n"); |
HoYa | 1:b2b7580e09d7 | 29 | pc.printf("DNS Testing...\r\n"); |
HoYa | 1:b2b7580e09d7 | 30 | SocketAddress addr(&spwf, "st.com"); |
HoYa | 1:b2b7580e09d7 | 31 | pc.printf("<st.com> is resolved to: %s\r\n", addr.get_ip_address()); |
HoYa | 0:63d30ec829b6 | 32 | |
HoYa | 0:63d30ec829b6 | 33 | while (1) { |
HoYa | 0:63d30ec829b6 | 34 | led = !led; |
HoYa | 0:63d30ec829b6 | 35 | wait(0.5); |
HoYa | 0:63d30ec829b6 | 36 | } |
HoYa | 0:63d30ec829b6 | 37 | } |
HoYa | 0:63d30ec829b6 | 38 |