Set Static IP for Arduino Mega

Does Ether.isLinkUp() exist, and if so can you put a line such as:
if (ether,isLinkUp()) serial.PrintLn ("Link is up");
at the end of setup.

I also spotted that it should be possible to detect if the Arduino has been pinged, by using a callback function.

If you define a function such as:

static void gotPinged (byte* ptr) {
  ether.printIp ">>> ping from: ", ptr);
}

Then in setup register that function so:
]

ether.registerPingCallback(gotPinged);

Whenever the arduino is pinged a message should be displayed.

This may tell us whether things are being received even if not being sent.

Hello,

I have tried the following and got the following error:

#include <EtherCard.h>
 
static byte mac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };
static byte ip[] = { 192, 168, 1, 10 };
byte Ethernet::buffer[500];
 
void setup () {
    Serial.begin(9600);
    if (ether.begin(sizeof Ethernet::buffer, mac, 8) == 0) 
        Serial.println("Failed to access Ethernet controller");
    if (!ether.staticSetup(ip))
        Serial.println("Failed to set IP address");

    ether.registerPingCallback(gotPinged);
}
 
void loop() {
    Serial.println(F("loop"));
    ether.packetLoop(ether.packetReceive());
    
    if ( !ether.isLinkUp() ) {
        Serial.println(F("No Link"));
    }
    else {
        Serial.println(F("Link"));
    }
}

static void gotPinged (byte* ptr) {
  ether.printIp ">>> ping from: ", ptr);
}

Error:

/Users/mattgraff/Documents/Arduino/sketch_mar27b/sketch_mar27b.ino: In function 'void gotPinged(byte*)':
sketch_mar27b:30:9: error: invalid use of member function 'static void EtherCard::printIp(const __FlashStringHelper*, const uint8_t*)' (did you forget the '()' ?)
   ether.printIp .">>> ping from: ", ptr);
   ~~~~~~^~~~~~~
sketch_mar27b:30:18: error: expected unqualified-id before string constant
   ether.printIp .">>> ping from: ", ptr);
                  ^~~~~~~~~~~~~~~~~
exit status 1
invalid use of member function 'static void EtherCard::printIp(const __FlashStringHelper*, const uint8_t*)' (did you forget the '()' ?)

/Users/mattgraff/Documents/Arduino/sketch_mar27b/sketch_mar27b.ino: In function 'void gotPinged(byte*)':
sketch_mar27b:30:9: error: invalid use of member function 'static void EtherCard::printIp(const __FlashStringHelper*, const uint8_t*)' (did you forget the '()' ?)
ether.printIp .">>> ping from: ", ptr);

*/Users/mattgraff/Documents/Arduino/sketch_mar27b/sketch_mar27b.ino is the name of the sketch where an error is found.
*In function 'void gotPinged(byte*)' means that the error is in function gotPinged().
*invalid use of member function [..] printIp means there is syntax error in the call to that function.
*(did you forget the '()' ?) is a question. It says: "did you forget the '()' ?".

Yep, it looks like I missed the ( out and that it should be:

ether.printIp (">>> ping from: ", ptr);

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.