WizFi310 DNS TCP Helloworld library 2.0 version

Dependencies:   WizFi310Interface_Legacy mbed

Prerequisite

This example shows that Wizwiki-W7500 and WizFi310 connect to a DNS server and get a its ip address. And then, It connects to '4.ifcfg.me' that returns an ip addess as TCP client.

To implement this function, you need a Platform board and Wi-Fi board. Below are what we used.

  • WIZwiki-W7500 from WIZnet (Platform board)
  • WizFi310 from WIZnet (Wi-Fi board)

Hardware Configuration

WIZwiki-W7500 Pin map

pin map

  • D0 is for RXD, D1 is for TXD
  • D6 is for CTS, D7 is for RTS
  • D9 is for RESET

WizFi310 Pin map

pin map

  • J1 is for RXD, J3 is for TXD
  • SW6-1 is connected to D6 for RTS, SW6-2 is connected to D7 for CTS
  • SW5-3 is connected to D9 for RESET

Connect to Wi-Fi

wizfi310.connect(SECURE, SSID, PASS);

Get information

const char *ip = wizfi310.getIPAddress();
const char *mac = wizfi310.getMACAddress();

Access to a 'mbed.org' website and get its ip addess

Endpoint addr;
addr.set_address("mbed.org", 80);
printf("mbed.org resolved to: %s\r\n", addr.get_address());

Access to a '4.ifcfg.me' as a TCP client and get its ip addess

TCPSocketConnection socket;
socket.connect("4.ifcfg.me", 23);
 
char buffer[64];
int count = socket.receive(buffer, sizeof(buffer));
printf("public IP address is: %.15s\r\n", &buffer[15]);

Committer:
stkim92
Date:
Thu Apr 20 00:33:05 2017 +0000
Revision:
0:5a020a26f32e
WizFi310 DNS TCP Helloworld library 2.0 version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stkim92 0:5a020a26f32e 1 /* NetworkSocketAPI Example Program
stkim92 0:5a020a26f32e 2 * Copyright (c) 2015 ARM Limited
stkim92 0:5a020a26f32e 3 *
stkim92 0:5a020a26f32e 4 * Licensed under the Apache License, Version 2.0 (the "License");
stkim92 0:5a020a26f32e 5 * you may not use this file except in compliance with the License.
stkim92 0:5a020a26f32e 6 * You may obtain a copy of the License at
stkim92 0:5a020a26f32e 7 *
stkim92 0:5a020a26f32e 8 * http://www.apache.org/licenses/LICENSE-2.0
stkim92 0:5a020a26f32e 9 *
stkim92 0:5a020a26f32e 10 * Unless required by applicable law or agreed to in writing, software
stkim92 0:5a020a26f32e 11 * distributed under the License is distributed on an "AS IS" BASIS,
stkim92 0:5a020a26f32e 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
stkim92 0:5a020a26f32e 13 * See the License for the specific language governing permissions and
stkim92 0:5a020a26f32e 14 * limitations under the License.
stkim92 0:5a020a26f32e 15 */
stkim92 0:5a020a26f32e 16
stkim92 0:5a020a26f32e 17 #include "mbed.h"
stkim92 0:5a020a26f32e 18 #include "WizFi310Interface.h"
stkim92 0:5a020a26f32e 19
stkim92 0:5a020a26f32e 20
stkim92 0:5a020a26f32e 21 #if defined(TARGET_NUCLEO_F411RE)
stkim92 0:5a020a26f32e 22 Serial pc(USBTX, USBRX);
stkim92 0:5a020a26f32e 23 WizFi310Internet wifi(PA_11, PA_12, D6, D7, D3, NC, 115200);
stkim92 0:5a020a26f32e 24 #endif
stkim92 0:5a020a26f32e 25
stkim92 0:5a020a26f32e 26 #if defined(TARGET_WIZwiki_W7500)
stkim92 0:5a020a26f32e 27 Serial pc(USBTX, USBRX);
stkim92 0:5a020a26f32e 28 WizFi310Interface wizfi310(D1, D0, D7, D6, D8, NC, 115200);
stkim92 0:5a020a26f32e 29 #endif
stkim92 0:5a020a26f32e 30
stkim92 0:5a020a26f32e 31 #define SECURE WizFi310::SEC_AUTO
stkim92 0:5a020a26f32e 32 #define SSID "wizms1"
stkim92 0:5a020a26f32e 33 #define PASS "maker0701"
stkim92 0:5a020a26f32e 34
stkim92 0:5a020a26f32e 35 int main()
stkim92 0:5a020a26f32e 36 {
stkim92 0:5a020a26f32e 37 pc.baud(115200);
stkim92 0:5a020a26f32e 38 printf("WizFi310 NetworkSocketAPI TCP Client Example\r\n");
stkim92 0:5a020a26f32e 39 wizfi310.init();
stkim92 0:5a020a26f32e 40 wizfi310.connect(SECURE, SSID, PASS);
stkim92 0:5a020a26f32e 41
stkim92 0:5a020a26f32e 42 const char *ip = wizfi310.getIPAddress();
stkim92 0:5a020a26f32e 43 const char *mac = wizfi310.getMACAddress();
stkim92 0:5a020a26f32e 44 printf("IP address is: %s\r\n", ip ? ip : "No IP");
stkim92 0:5a020a26f32e 45 printf("MAC address is: %s\r\n", mac ? mac : "No MAC");
stkim92 0:5a020a26f32e 46
stkim92 0:5a020a26f32e 47 Endpoint addr;
stkim92 0:5a020a26f32e 48 addr.set_address("mbed.org", 80);
stkim92 0:5a020a26f32e 49 printf("mbed.org resolved to: %s\r\n", addr.get_address());
stkim92 0:5a020a26f32e 50
stkim92 0:5a020a26f32e 51 TCPSocketConnection socket;
stkim92 0:5a020a26f32e 52 socket.connect("4.ifcfg.me", 23);
stkim92 0:5a020a26f32e 53
stkim92 0:5a020a26f32e 54 char buffer[64];
stkim92 0:5a020a26f32e 55 int count = socket.receive(buffer, sizeof(buffer));
stkim92 0:5a020a26f32e 56 printf("public IP address is: %.15s\r\n", &buffer[15]);
stkim92 0:5a020a26f32e 57
stkim92 0:5a020a26f32e 58 socket.close();
stkim92 0:5a020a26f32e 59 wizfi310.disconnect();
stkim92 0:5a020a26f32e 60
stkim92 0:5a020a26f32e 61 printf("Done\r\n");
stkim92 0:5a020a26f32e 62
stkim92 0:5a020a26f32e 63 }