Hello all,
I'm trying to extract the imformação ip allocated to an XML file on the SD card and load it on arduino.
I'm using an Arduino Uno REV3 and an Ethernet Shield.
I can read the content on the card but I can not isolate the text XML.
this is my XML file
#################################################
192
168
0
20
################################################
any one can tell me the best way to do this? exist a command or library to extract text beetween and ?
Hey PaulS tks for help.
in fact i try so many diferent ways, that i don´t know the better to post.
I try using tynixml but i didn´t find a helpfull documentation.
I try a string search to but it was too big.
I´m begginner with arduino so if you, or anyone else have any idea about how to do this, I appreciate
Why do you want to do this? If you simply need to set the IP address from a config file, a simple comma separated file would be easier for the Arduino to parse. Do you have other constraints that mean you must use XML?
Serial.println("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization SD Card done.");
myFile=SD.open("conf.xml");
Serial.println("set ip address:");
int i=0;
while(myFile.available())
{
chtr = myFile.read();
Serial.println(sFourthOct);* // Entre com um endereço MAC para o arduino. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Entre com um endereço IP para o arduino: IPAddress localip = (192,168,0,18);
Ethernet.begin(mac, localip);* } But MY terminal response is. Initializing SD card... initialization SD Card done. set ip address: My XML File <?xml version="1.0" ?>
*
192*
168*
0*
20*
*
end My XML File Char Response 192 168 0 20 End Char Response Int Response 144 144 0 20 End Int Response 144.144.0.20 Wy the two first octects change to 144? anyone can help?
After populating a char array, why are you wrapping it in a String? There is no reason for that. People developed extensive text processing applications without the crutch of a String class for 40 years before it was created.
By the way, that still isn't the proper way to post code.
Hey PaulS,
Tks for your answer.
in fact you are right, the 5 should be a 4, because a null caracter
I change to String because is very simple to use and extract caracter using this function.
I need a way to convert the String "192" to a int 192. but I didn´t find this funtion in String.
I only find the atoi function that why I use toCharArray function.
but the two first octects give me the same number as result 144.
in fact you are right, the 5 should be a 4, because a null caracter
No. The 5 should be a 3, because that is how big the array is. Now, clearly, the arrays are too small, so they need to be made bigger, and the new size used where the 5 is now.
I need a way to convert the String "192" to a int 192. but I didn´t find this funtion in String.
Not to encourage the use of the String class, but it does have a toInt() method.
but the two first octects give me the same number as result 144.
Did you know why?
You are writing outside the bounds of your array(s).
No. The 5 should be a 3, because that is how big the array is. Now, clearly, the arrays are too small, so they need to be made bigger, and the new size used where the 5 is now
I agree, but if I set to 3 the last number don´t go to array, in somewhere I read that in this function you need a null caracter in the end of array, don´t know why.
Not to encourage the use of the String class, but it does have a toInt() method.
can you show me a example of this toInt() method? I don´t find it on references.
I agree, but if I set to 3 the last number don´t go to array, in somewhere I read that in this function you need a null caracter in the end of array, don´t know why.
You do need a NULL. The point is that 4 characters ('1', '0', '2', '3') and a NULL will NOT fit in a 3 element array. You MUST make the arrays large enough.
String crap = "14";
int crapAsInt = crap.toInt();
Serial.print(crapAsInt);