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.
Dependencies: WizFi310Interface_Legacy mbed
Fork of WizFi310_OpenWeatherMap by
Prerequisite
This example is for obtainning and printting data from OpenWeatherMap(Server).
WIZwiki-W7500 and WizFi310 Shield act as TCP client mode.
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

- D0 is for RXD, D1 is for TXD
 - D6 is for CTS, D7 is for RTS
 - D9 is for RESET  
 
WizFi310 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  
 
Software
main.cpp
/* NetworkSocketAPI Example Program
 * Copyright (c) 2015 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#include "mbed.h"
#include "WizFi310Interface.h"
#if defined(TARGET_WIZwiki_W7500)
    WizFi310Interface wizfi310(D1, D0, D7, D6, D9, NC, 115200);
    Serial pc(USBTX,USBRX);
#endif
#define SECURE WizFi310::SEC_AUTO
#define SSID "SSID"
#define PASS "PASS"
#define CITY        "Seoul"
#define API_KEY     "API KEY"
int main()
{
    int errConnect;
    char http_cmd[1000] = "";
    char buffer[2048] = "";
    
    pc.baud(115200);
    printf("WizFi310 NetworkSocketAPI TCP Client OpenWeatherMap Example\r\n");
    
    wizfi310.init();
    if( wizfi310.connect(SECURE, SSID, PASS) )    return -1;
    
    const char *ip = wizfi310.getIPAddress();
    const char *mac = wizfi310.getMACAddress();
//    printf("IP address is: %s\r\n", ip ? ip : "No IP");
//    printf("MAC address is: %s\r\n", mac ? mac : "No MAC");
      
    TCPSocketConnection socket;
    socket.set_blocking(1000);   // Set Block Mode.
    errConnect = socket.connect("api.openweathermap.org", 80);    
    
    while (true) {
        if(errConnect!=0) {
            printf("\r\ncould not connect to socket : error = %d\r\n", errConnect);
            errConnect = socket.connect("api.openweathermap.org", 80);
        } else {
            printf("socket connected\r\n");
            break;
        }
    }    
     
    sprintf((char *)http_cmd,"GET /data/2.5/weather?q=%s,uk&appid=%s HTTP/1.0\r\nHost: api.openweathermap.org\r\nConnection: close\r\n\r\n",
    CITY, API_KEY);
    socket.send_all(http_cmd, sizeof(http_cmd));
    
    socket.receive_all(buffer, sizeof(buffer));
    printf("%s",buffer);
 
    socket.close();
    wizfi310.disconnect();
    
    printf("Done\r\n");
}
Caution
This example requires an API key that can be obtained by signning up to the openweathmap site. //
