Example program for the C027Interface

Dependencies:   C027Interface NetworkSocketAPI mbed

main.cpp

Committer:
sam_grove
Date:
2015-06-17
Revision:
9:da5a230fa4f4
Parent:
7:6787b920b496
Child:
11:b7e531a4d661

File content as of revision 9:da5a230fa4f4:

/* 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 "WiFiRadioInterface.h"

DigitalOut myled(LED1);

WiFiRadioInterface wifi;
// or
//NetworkInterface *wifi = new WiFiInterface;

//TCPSocket tcp(wifi.getInstance());
// or
//SocketInterface tcp = new TCPSocket(wifi->getInstance();

//UDPSocket udp(wifi.getInstance());
// or
//SocketInterface udp = new UDPSocket(wifi->getInstance();

int main()
{
    puts("NetworkSocketAPI Example");

    wifi.init();
    wifi.connect("apname", "phrase", WI_WPA2);

    printf("Wifi is %s\n", (wifi.isConnected() > 0) ? "Connected" : "Disconnected");

    printf("IP: %s\n", wifi.getIPAddress());
    printf("Gateway: %s\n", wifi.getGateway());
    printf("Mask: %s\n", wifi.getNetworkMask());
    printf("MAC: %s\n", wifi.getMACAddress());
    
    //Endpoint google;
    wifi.set_address(wifi.get_host_by_name("www.google.com"));
    wifi.set_address("216.58.192.46");
    wifi.set_port(80);
    
    //Socket socket;
    char buf[1024];
    wifi.connect(*wifi.endpoint);
    wifi.recv(buf, 1024);
    wifi.send(buf, sizeof(buf));
    wifi.close(*wifi.endpoint);

    wifi.disconnect();

    while(1) {
        myled = !myled;
    }
}