A simple Firmware Updating program.

Dependencies:   FirmwareUpdater NetServices RPCInterface mbed

Fork of NetServices_HelloWorld by Segundo Equipo

main.cpp

Committer:
segundo
Date:
2010-11-16
Revision:
1:57f922fe8fb5
Parent:
0:2419d81ee03d
Child:
2:16857d9ab50d

File content as of revision 1:57f922fe8fb5:

#include "mbed.h"
#include "EthernetNetIf.h"
#include "HTTPClient.h"
#include "NTPClient.h"

EthernetNetIf eth("mbedSE");
HTTPClient http;
NTPClient ntp;

int main() {

    printf("Setting up...\n");
    EthernetErr ethErr = eth.setup();
    if (ethErr) {
        printf("Error %d in setup\n", ethErr);
        return -1;
    }

    IpAddr ethIp = eth.getIp();
    printf("Connected ok, IP : %d.%d.%d.%d\n", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);

    printf("\nHTTPClient get...\n");
    HTTPText txt;
    HTTPResult r = http.get("http://mbed.org/media/uploads/donatien/hello.txt", &txt);
    if (r==HTTP_OK) {
        printf("Result ok : %s\n", txt.gets());
    } else {
        printf("Error %d\n", r);
    }

    time_t ctTime;
    ctTime = time(NULL);
    printf("\nCurrent time is (UTC): %d %s\n", ctTime, ctime(&ctTime));
    printf("NTP setTime...\n");
    Host server(IpAddr(), 123, "pool.ntp.org");
    printf("Result : %d\n", ntp.setTime(server));

    ctTime = time(NULL);
    printf("\nTime is now (UTC): %d %s\n", ctTime, ctime(&ctTime));

    printf("Done!\n");
    return 0;
}