WizFi310_DNS_TCP_HelloWorld edited with a new Interface
Dependencies: NetworkSocketAPI WizFi310Interface mbed
main.cpp
00001 /* NetworkSocketAPI Example Program 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "mbed.h" 00018 #include "TCPSocket.h" 00019 #include "mbed.h" 00020 #include "WizFi310Interface.h" 00021 #include "TCPSocket.h" 00022 00023 #if defined(TARGET_NUCLEO_F411RE) 00024 Serial pc(USBTX, USBRX); 00025 WizFi310Internet wifi(PA_11, PA_12, D6, D7, D3, NC, 115200); 00026 #endif 00027 00028 #if defined(TARGET_WIZwiki_W7500) 00029 Serial pc(USBTX, USBRX); 00030 WizFi310Interface wifi(D1, D0, D7, D6, D9, NC, 115200); 00031 #endif 00032 00033 #define AP_SSID "wizms1" 00034 #define AP_PASSWORD "maker0701" 00035 #define AP_SECURITY NSAPI_SECURITY_WPA2 00036 00037 int main() 00038 { 00039 pc.baud(115200); 00040 printf("WizFi310 NetworkSocketAPI TCP Client Example\r\n"); 00041 00042 wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY); 00043 00044 const char *ip = wifi.get_ip_address(); 00045 const char *mac = wifi.get_mac_address(); 00046 printf("IP address is: %s\r\n", ip ? ip : "No IP"); 00047 printf("MAC address is: %s\r\n", mac ? mac : "No MAC"); 00048 00049 SocketAddress addr(&wifi, "mbed.org", 80); 00050 printf("mbed.org resolved to: %s\r\n", addr.get_ip_address()); 00051 00052 TCPSocket socket(&wifi); 00053 socket.connect("4.ifcfg.me", 23); 00054 00055 char buffer[64]; 00056 int count = socket.recv(buffer, sizeof buffer); 00057 printf("public IP address is: %.15s\r\n", &buffer[15]); 00058 00059 socket.close(); 00060 wifi.disconnect(); 00061 00062 printf("Done\r\n"); 00063 00064 }
Generated on Mon Jul 18 2022 06:59:42 by
1.7.2