Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <EtherCard.h>
- #include <NanodeUNIO.h>
- byte mymac[] = { 0x88,0x88,0x88,0x88,0x88,0x88 };
- byte Ethernet::buffer[700];
- static uint32_t timer;
- char buf[20];
- NanodeUNIO unio(NANODE_MAC_DEVICE);
- boolean r;
- void setup () {
- Serial.begin(57600);
- Serial.println("Nanode Network Monitor");
- getmac();
- if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
- Serial.println( "Failed to access Ethernet controller");
- if (!ether.dhcpSetup())
- Serial.println("DHCP failed");
- ether.printIp("IP: ", ether.myip);
- ether.printIp("GW: ", ether.gwip);
- #if 1
- // use DNS to locate the IP address we want to ping
- if (!ether.dnsLookup(PSTR("www.google.com")));
- Serial.println("DNS failed");
- #else
- ether.parseIp(ether.hisip, "209.85.147.105");
- #endif
- ether.printIp("SRV: ", ether.hisip);
- // call this to report others pinging us
- ether.registerPingCallback(gotPinged);
- timer = -9999999; // start timing out right away
- Serial.println();
- }
- void loop () {
- word len = ether.packetReceive(); // go receive new packets
- word pos = ether.packetLoop(len); // respond to incoming pings
- // report whenever a reply to our outgoing ping comes back
- if (len > 0 && ether.packetLoopIcmpCheckReply(ether.hisip)) {
- Serial.print(" ");
- Serial.print((micros() - timer) * 0.001, 3);
- Serial.println(" ms");
- }
- // ping a remote server once every few seconds
- if (micros() - timer >= 5000000) {
- ether.printIp("Pinging: ", ether.hisip);
- timer = micros();
- ether.clientIcmpRequest(ether.hisip);
- }
- }
- // called when a ping comes in (replies to it are automatic)
- static void gotPinged (byte* ptr) {
- ether.printIp(">>> ping from: ", ptr);
- }
- void getmac(){
- boolean mactest; char buf[20];
- NanodeUNIO unio(NANODE_MAC_DEVICE);
- Serial.print("Reading MAC address... ");
- mactest=unio.read(mymac,NANODE_MAC_ADDRESS,6);
- if (mactest){
- Serial.println("success");
- }
- else{
- Serial.println("failure");
- }
- sprintf(buf,"%02X:%02X:%02X:%02X:%02X:%02X",mymac[0],mymac[1],mymac[2],mymac[3],mymac[4],mymac[5]);
- Serial.print("MAC address is ");Serial.println(buf);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement