Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

arduino, setup ethernet & network using data from SD config file

$
0
0

Im try to add to my sketch a dynamic way to setup the ethernet info (mac, ip, gateway, subnet) from a configuration file (config.txt). So running a webserver and serving htm files from sd card, user can go to setting page, fill a form with these info and when posted , the webserver parse the http form and save (update) the config.txt file. After that system do a restart, in order to start with the new settings (by read the config.txt file)

I have create succesfully all the parts (sd, ethernet, webserver, webclient, create the config file from posted form data) except the get params by reading the config.txt file.

I can read line by line the config, I can split the line to param & value, and now I need to fill some byte variables with the readed data. I can (after a month of google searching) to read IPs (decimal values) to byte array. Im stack to read the MAC ADDRESS hex into byte array. The config file contains the:

mac=8f:2c:2b:19:e0:b7;ip=192.168.1.200;netmask=255.255.255.0;gateway=192.168.1.254;dns=8.8.8.8;posturl=192.168.1.157;postport=8080;postscript=/itherm/update.php;interval=60000;

and the code that I use to read is:

byte myMAC[6];byte myIP[4];  File fset;  fset = SD.open("config.txt");  if (fset){    char ff[40];    while (fset.available()>1){      bool eol=false;      for (int i=0; !eol;i++){        ff[i]=fset.read();        if (ff[i]=='\n'){           eol=true;        }      }      String par="";      bool DONE=false;      for (int i=0; !DONE;i++){        par+=ff[i];        if (ff[i]== '='){DONE=true;}      }      String pval="";      DONE=false;//------------------------      if (par=="ip=" ){        int x=0;        while(!DONE){          for(int i=3;i<=i+21;i++){            if(ff[i]=='.'){              myIP[x]=pval.toInt();              x++;              i++;              pval="";            }            else if(ff[i]==';' || i>20){              myIP[x]=pval.toInt();              DONE=true;              break;            }            pval+=ff[i];          }        }      }    } //while (fset.available()>1)  } //if (fset)

I will appreciate any help. Please no answers with simple use of Serial.print(). I have found hundreds of suggestions but none, that work properly to read all the parameters (dec, hex, strings). After a month of effort & searching, I wonder why something so necessary and useful does not exist as an example in the community, completely functional !!

Best regards


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>