This is return of submit for the embedded server inside the board and the purpose is to same the new MAC inside the EEPROM
//****************************************MAC adress of this board *************************
char mystring[]="MC0=";
String macStr="";
String MAC;
for (int index = 48; index < 54; index++)// 48= ASCII du Zero en decimal
{
mystring[2]= char(index);// Increment the index (at position 2) value in the string
Serial.print(mystring); // print name of field with index
charsRead=finder.getString(mystring ,"&", filenameValue, 5);// seach for next indexed MCx value
if(charsRead>0) // got it !
{
filenameValue[charsRead]='\0';// read the value
Serial.println(filenameValue); //print the value
macStr = macStr + filenameValue; // concaten the result
Serial.println ("macStrc = "+macStr);
}
}
String myString = macStr ;
int myStringLength = macStr.length()+1;
char myChar[myStringLength]; // create array
char MACchar;
myString.toCharArray(myChar,myStringLength); // insert value in the array
for (int Index=0 ; Index<macStr.length();Index++)
{
if ((int(myChar[Index])>0) && (int(myChar[Index])<128))
{
Serial.println (int(myChar[Index]),HEX);
// MACchar = char(int(myChar[index]);
}
else
{
Serial.println (int(myChar[Index])+256,HEX);
// MACchar = char(int(myChar[index]+256);
}
MAC= MAC + String(MACchar);
}
Serial.println ("MAC= " +MAC);
//Update_String2EEPROM (MAC,9); // MAC is at position 9 in EEPROM
You REALLY need to decide if you are going to work with strings (preferred) or Strings. Do NOT try to mix and match and convert back and forth.
myString and mystring are not good names. There is a reason that you are collecting data in a string/String. Name the variable appropriately.
You need to post ALL of your code, so we can replicate the problem, and see the offending line highlighted. With just snippets, we have no idea which line is line 333.
What's with all the casting? myChar suggests that it is an array of characters. Casting characters to ints and back to chars to store in a char variable is a while lot of crap.
I Get string "A" in myChar[index]
Nonsense. You get the character 'A'. You do NOT need to convert that to 41 so you can convert it back to 'A'.
String MAC = String((char*)mac); // convert to char then string
Serial.println ("MAC= " +MAC); //Serial.print ("Length = "); //Serial.println(MAC.length());
MAC=MAC.substring(0,MAC.length()-1); // remove extra 0 form the string
Write_String2EEPROM (MAC,9); // MAC is at position 9 in EEPROM
What's with all the casting? myChar suggests that it is an array of characters. Casting characters to ints and back to chars to store in a char variable is a while lot of crap.
Nonsense. You get the character 'A'. You do NOT need to convert that to 41 so you can convert it back to 'A'.
Yes, I am not very good in this language and should improve for sure
What I want is to transform the "AA" received as string I.E. 4141 to 0xAA and store this in EEPROM
String MAC = String((char*)mac); // convert to char then string
That is NOT what that line does.
MAC=MAC.substring(0,MAC.length()-1); // remove extra 0 form the string
Why? Strings wrap strings that are NULL terminated. Not writing the NULL to EEPROM is one thing. Removing it from the String is another (stupid) thing.
if ((int(Mytable[Index])>0) && (int(Mytable[Index])<128))
The cast to int is completely unnecessary.
There was NO reason to convert the byte array to a String to store in EEPROM. It's 6 bytes. Just store them one at a time in EEPROM, to consecutive addresses. You are making the process FAR more difficult than it needs to be. Reading the 6 bytes back, and storing in a byte array will then be trivial, with no wasted memory and no useless casts.