questo a me andava già da subito

Dependencies:   WIZ820ioInterface mbed

Fork of Seeed_Ethernet_Shield by Shields

main.cpp

Committer:
Wonderjack996
Date:
2018-07-11
Revision:
8:eb977ef6d2ab
Parent:
6:4bb23453ce91

File content as of revision 8:eb977ef6d2ab:

/* Copyright (c) 2010-2011 mbed.org, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "mbed.h"
#include "WIZ820ioInterface.h"

Serial pc(USBTX, USBRX);

/*
 * D11 - MOSI pin
JNH * D12 - MISO pin
 * D13 - SCK pin
 * D10 - SEL pin
 * NC - Reset pin; use D5 otherwise the shield might get into reset loop
 */
WIZ820ioInterface eth(D11, D12, D13, D10, D5);

const char * IP_Addr    = "10.51.23.95";
const char * IP_Subnet  = "255.255.255.0";
const char * IP_Gateway = "10.51.70.254";
unsigned char MAC_Addr[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
int main()
{
    wait(3);
    
    // Initialize the interface.
    // If no param is passed to init() then DHCP will be used on connect()
    int s = eth.init(IP_Addr,IP_Subnet,IP_Gateway);
    if (s != NULL) {
        printf(">>> Could not initialise. Halting!\n");
        exit(0);
    }

    printf(">>> Get IP address...\n");
    while (1) {
        s = eth.connect(); // Connect to network

        if (s == false || s < 0) {
            printf(">>> Could not connect to network! Retrying ...\n");
            wait(3);
        } else {
            break;
        }
    }
    printf(">>> Got IP address: %s\n", eth.getIPAddress());

    while(true);

    return 0;
}