Go Down

Topic: Save IP Address EEPROM (Read 7476 times) previous topic - next topic


I want save IP Address to EEPROM.

To my user running webserver is possible change IP Address.

My problem is convert string to Byte

My Complete Code :
Code: [Select]

/*  Ethernet shield attached to pins 10, 11, 12, 13 */

#include <SPI.h>
#include <Ethernet.h>
#include <EEPROM.h>
#include <C:\Temp\Eletronica\arduino-0022\libraries\TextFinder\TextFinder.h>

Server server(80);
//Server TelnetServer(23);

const int buttonPin = 2;          // the number of the pushbutton pin
int buttonState = 0;             // variable for reading the pushbutton status
String readString = String(30);  //string for fetching data from address
int address = 0;
boolean gotAMessage = false;

   int IP[4] = {192, 168,1, 170};
   int gat[4] = {192,168,100,2};
   int Sub[4] = {255,255,0,0};

void setup()

  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  byte ip[] = { IP[0],IP[1],IP[2], IP[3] };
  byte gateway[] = { gat[0],gat[1],gat[2],gat[3]};
  byte subnet[] = { Sub[0], Sub[1], Sub[2], Sub[3] };

  Ethernet.begin(mac, ip, gateway, subnet);
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
// Serial.begin(9600);

void loop()

  int varBateria;
  int varRede;
  long varTemperatura;
  boolean varAlarme = true;
  boolean varPagina = false;

  // listen for incoming clients
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
              if (client.available()) {
                            char c = client.read();
                            if (readString.length() < 100)
                              readString += c; //replaces readString.append(c);
                            if (c == '\n' && currentLineIsBlank) {
                                      client.println("HTTP/1.1 200 OK");
                                      client.println("Content-Type: text/html");
                                      if(readString.indexOf("Reset=1") > 0){
                                              client.println("<font face=verdana size=3><b>O Nobreak sera reiniciado!!</b></Font>");
                                              digitalWrite(3, HIGH);
                                              digitalWrite(3, LOW);
                                       if(readString.indexOf("SalvaConf") > 0){
                                             //TextFinder  finder(client);
                                             //finder.find("GET /");
                                             //finder.findUntil("IP", "\n\r");
                                             //char type = client.read();
                                             int posA;int posB;int posC;int posD;int posE;
                                             //char IP1;char IP2;char IP3;char IP4;
                                             //char SUB1;
                                             //byte Sub2;byte SUB3;char SUB4;
                                             //char GT1;char GT2;byte GT3;char GT4;                                             
                                             client.println("<font face=verdana size=3><b>As configuracoes foram salvas!!</b></Font>");
                                             posB=readString.indexOf(".", posA+1);
                                             posC=readString.indexOf(".", posB+1);
                                             posD=readString.indexOf(".", posC+1);
                                             posE=readString.indexOf("&", posD+1);

                                             String IP1 = String(readString.substring(posA+3,posB));
                                             String IP2 = String(readString.substring(posB+1,posC));
                                             String IP3 = String(readString.substring(posC+1,posD));
                                             String IP4 = String(readString.substring(posD+1,posE));
                                             int x;
                                             x = atoi(IP1);
                                             // gravaConf(IP1, IP2, IP3, IP4, Sub1, Sub2, Sub3, Sub4, GT1, GT2, GT3, GT4);
                                             // client.println(readString);

My answer code:

Code: [Select]

                                             String IP1 = String(readString.substring(posA+3,posB));
                                             String IP2 = String(readString.substring(posB+1,posC));
                                             String IP3 = String(readString.substring(posC+1,posD));
                                             String IP4 = String(readString.substring(posD+1,posE));

Please how to??


Something like this:

Code: [Select]

unsigned char IP [4];
char temp[4];

temp[3] = '\0';

String IP1 = readString.substring(posA+3,posB));
IP1.toCharArray(temp, 3);
IP[0] = (unsigned char) atoi(temp, 10);


Of course you could try to change your code to use char arrays and string.h and wouldn't have these conversions. :\ But it's up to you. I didn't compile this code or tested it in any way, but it should work.
This... is a hobby.



Slightly drifitng away from your topic sorry, and it probably won't affect operation of your sketches or network, but you're using a Class B subnet mask with a Class C IP address.  You should probably use as your subnet mask unless you're going to be splitting your network down further.


I'm starting to add page in my projects, and now face the problem of inserting ip web.
You conseguil?
Can you post the code?
thank you very much

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131