Total newbie here, just a fair warning..
I'm looking to store an IP address into EEPROM. The IP is then read back from the EEPROM in serial.print fashion.
Would I format this code to make it display the IP address on a single line, seperated by ".", like this:
IP Address
"192.168.24.253"
Ultimately this is a bigger project planned with the following goals:
- Have user input to change/enter IP, Gateway, etc..
- network information gets stored into EEPROM
- will work from a server-based ethernet interface
The current I have shows the output like this:
IP Address
192
168
24
1
Any helpful tips would be appreciated!
-J
#include <EEPROM.h>
#include "EXROM.h"
void setup()
{
byte IP[] = {192,168,24,1};
byte IPsize[sizeof(IP)];
Serial.begin(9600);
EXROM.write(0, IP, sizeof(IP)); //write the IP to memory
EXROM.read(0, IPsize, sizeof(IPsize)); //read the IP from memory
Serial.println("IP ADDRESS");
for(int i=0;i<sizeof(IP);i++)
{
Serial.println(IP[i], DEC);
}
Your sample code writes the IP address to exrom and reads it back into IPsize but then prints out the original from IP.
Try this code:
#include <EEPROM.h>
#include "EXROM.h"
void setup()
{
byte IP[] = {192,168,24,1};
byte IPsize[sizeof(IP)];
Serial.begin(9600);
EXROM.write(0, IP, sizeof(IP)); //write the IP to memory
EXROM.read(0, IPsize, sizeof(IPsize)); //read the IP from memory
Serial.print("IP ADDRESS ");
for(int i=0;i<sizeof(IPsize);i++)
{
Serial.print(IPsize[i], DEC);
if(i != 3)Serial.print(".");
}
Serial.print("\n");
}
void loop(void)
{
}
I can't test the code with exrom but it prints IPsize like this when written to eeprom and read back again:
IP ADDRESS 192.168.24.1
Pete
Thank You, your code works well.
Shortly after I posted this, I figured out a couple things -- one thing being the difference between "print" & "println" ( I warned you that I was a newbie); so I got closer on my own..
Then I went further to add the periods, but took a different turn using a FOR loop (which added too many periods, etc..).
I may post more questions as I move along with my program -- thanks again..