Reading the IP address with the Arduino

I have Arduino MEGA 2560 + ethernet shield and I read a barometric sensor.

  1. I want to program Arduino to automatically read the IP address and the MAC, so that when I change LAN to get updated

  2. The constructure is on a LAN. I want to access the Arduino through my home when I am outside this LAN, from my home.

This instruction code here: https://www.arduino.cc/en/Tutorial/BarometricPressureWebServer

writes:

// assign a MAC address for the Ethernet controller.
// fill in your address here:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// assign an IP address for the controller:
IPAddress ip(192, 168, 1, 20);
  1. Can I do this procedure of reading operate automatically?
  2. Can I access the Arduino from my home ??

update: With this: https://www.arduino.cc/en/Tutorial/DhcpAddressPrinter I got this error:

Initialize Ethernet with DHCP:
Failed to configure Ethernet using DHCP
Ethernet shield was not found.  Sorry, can't run without hardware. :(

The Ethernet Shield is connected...

I want to program Arduino to automatically read the IP address and the MAC, so that when I change LAN to get updated

For the Ethernet Shield you have to specify the MAC address yourself because the hardware doesn't have one built-in. You can choose any MAC address as long as it's unique in the target network.
To get the IP address automatically just use the constructor that only specifies the MAC address and the library will do DHCP to get the IP.

The constructure is on a LAN. I want to access the Arduino through my home when I am outside this LAN, from my home.

So you have to provide the network features to provide such a service. This is completely unrelated to Arduino but is a question of the network infrastructure.

The Ethernet Shield is connected...

If it's connected and it's an Original Arduino Ethernet Shield the shield is broken and you should get a replacment.
If you use some other device, post a link to it and post a wiring diagram of your setup!

Thank you, I use: Arduino Ethernet Shield Rev3 - Compatible

I use: Arduino Ethernet Shield Rev3 - Compatible

Compatible may mean several things. A lot of these compatibles work only with an UNO and don't work on a Mega2560. Post a link to the product you bought!

  • Requires and Arduino board (not included)
  • Operating voltage 5V (supplied from the Arduino Board)
  • Ethernet Controller: W5100 with internal 16K buffer
  • Connection speed: 10/100Mb
  • Connection with Arduino on SPI port
  • without POE Module

Ok, I changed Shield to the original one, everything works perfect. Thanks...

How about question Number #2??
2) Can I access the Arduino from my home ?? How??

alex5678:
How about question Number #2??
2) Can I access the Arduino from my home ?? How??

Yes, but you would probably need to configure the router on the LAN to permit it.

  1. Can I access the Arduino from my home ?? How??

As wildbill already answered, this is theoretically possible but needs a lot of configuration in your router and some other work.
I strongly recommend that you use one of the cloud services (p.e. MQTT), write your measured values to it and request the values again.