My sketch is not saved while arduino power off

Hi All,

I have arduino leonardo R3 POE card.I am programming the card with small sketch which assign IP address to ethernet interface.

Once power is down in the card and we are restarting the card,IP address are not set and need to download the sketch again.Is that normal behavior of the card?

Regards,

Post your program.

Where are the IP address details being stored?

...R

#include <SPI.h>
#include <Ethernet2.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x38, 0x53 };
IPAddress ip(12, 215, 1, 99)
IPAddress subnet(255, 255, 255, 0)
IPAddress gateway(12, 215, 1, 1)

void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial){;} // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
Ethernet.begin(mac, ip, gateway, subnet);
}
Void loop ()
{}

Void loop ()Now post the actual code you're uploading.
In code tags, this time please.

Void loop is empty

The compiler will barf on "Void", so that code is not the code you're compiling.

So the above code should be shifted to void loop and not keep in the main.

Can you send me the code which keep the IP address of the interface saved even if i shutdown the card

You're not following me

void != Void.

Appreciate your support.

can you explain more about my problem.

Please reply.i didnt get your point.Please re explain

Void should be lowercase. So the code you posted will not compile.

Post your real code and post it between
** **[code]** **
and
** **[/code]** **
.

#include <SPI.h>
#include <Ethernet2.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for (;:wink:
;
}
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}

void loop() {

}

Above code is working perfectly and my IP is assigned to Ethernet interface but my problem that this IP are not saved while power goes off on the card.

but my problem that this IP are not saved while power goes off on the card.

What part of the code is supposed to save the IP address somewhere? Where is it supposed to save the IP address?

The data that the Arduino receives while it is running is NOT persisted, unless YOU write code to persist it.

I am beginner with arduino .Please let know how to write a code which can save the ip address.

Mahmoudjaa:
Above code is working perfectly and my IP is assigned to Ethernet interface but my problem that this IP are not saved while power goes off on the card.

The program you have posted makes no attempt to save the IP address. It just gets the address and prints it to the Serial Monitor.

And, even if the program did save the IP address there is no code in the program to use the IP address.

You need to tell us more about the project you are trying to implement so that we can understand the context of your questions.

It is possible to save data to the Arduino's EEPROM memory so that it won't be lost when the power is disconnected.

...R

PS I bet there is no smiley in the code on your PC. If you use the code button </>

so your code looks like this

we won't see smileys either. See How to use the Forum. It makes it much easier for people to help you

#include <SPI.h>
#include <Ethernet2.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 177);

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect.
}

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}

void loop() {}

i change my code to match above.I don't know any function can save IP address.

My project now only to configure Ethernet IP address permanetly even after shutdown.

Mahmoudjaa:
i change my code to match above.I don't know any function can save IP address.

What have you studied about using the EEPROM memory on the Arduino?

...R

i studied the EEPROM and NetEEPROM library and i run below example.values are stored in EEPROM but still when startup IP addresses are not automatically assigned to Ethernet interface.

#include <EEPROM.h>
#include <SPI.h>
#include <Ethernet.h>
#include <NetEEPROM.h>

/* Stores network configuration of a MAC address and manual IP setup

  • to EEPROM.
    */
    void setup() {
    byte mac[6] = { 0xCA, 0xFE, 0xBA, 0xBE, 0x00, 0x00 };
    byte ip[4] = { 192, 168, 1, 100 };
    byte dns[4] = { 8, 8, 8, 8 };
    byte gw[4] = { 192, 168, 1, 1 };
    byte subnet[4] = { 255, 255, 255, 0 };

NetEeprom.writeManualConfig(mac, ip, dns, gw, subnet);
}

void loop() {
}

i’m still missing something here.
in your sketch, you initialise the network values every time the board restarts, then call Ethernet.begin() as usual.

If you’re using a static IP, why do you need to store it anyway?
It will run the same startup code every time with the same result.

Now... if you said this is an experiment to see ‘if’ you can save the network parameters - that’s a different question.

Both cases have similar requirements, but the way you have framed the original question, the whole exercise is pointless - unless you also intend reading the IO configuration back later - possibly with some other values....

I’ve done the save/auto config method a few years ago, saving the addressing mode (static or dhcp), along with the various values for ‘statuc’ mode.
And on the next restart - if that saved data exists, it is sed in preference to the hard coded ‘default’ address details.

You need to tell the full story, ask the right question and read/practice with the EEPROM functions.
I’ve never used NetEEPROM, but it seems it may be excess baggage.