This will not work. G_addr[1] is a memory adress that the compiler knows about - the adress of that second element of your array. It''s ot a thing you can change.
What you probably want to so is to change the memory at that location.
Another issue is that I don't know if the strings in that array are nul-terminated. I'm guessing they aren't - you have to rely on knowing the size.
The simplest solution is to quit using String anywhere in your code. There is NOTHING that the String class can do that can not be done with string functions applied to NULL terminated arrays of chars.
I've try to change G_Addr from unsigned char to String but there were new problem
look this
String G_addr[10][8]; //store 10 index da 8 bytes (64bit)
byte G_Devices; // number of key in the bus
OneWire ow(1); // inizializza il bus onewire sulla porta n°8 (se avete collegato i sensori su un'altro pin dovete modificare qui)
but this is the problem
for (int i=0;i<G_Devices;i++) if(CheckAddress(G_addr[i],address)) {old=true;break;} // se trovo l'indirizzo imposto old a true ed esco dal for
this is the error
ibutton_v3.ino: In function 'void lookUpKeys()':
ibutton_v3:140: error: cannot convert 'String*' to 'unsigned char*' for argument '1' to 'bool CheckAddress(unsigned char*, unsigned char*)'
ibutton_v3:148: error: invalid conversion from 'byte' to 'const char*'
ibutton_v3:148: error: initializing argument 1 of 'String& String::operator=(const char*)'
ibutton_v3.ino: In function 'void applySetting(String, String, char)':
ibutton_v3:473: error: incompatible types in assignment of 'char' to 'String [8]'
ibutton_v3:476: error: incompatible types in assignment of 'String' to 'String [8]'
ibutton_v3:477: error: 'exBoolean' was not declared in this scope
ibutton_v3:480: error: incompatible types in assignment of 'String' to 'String [8]'
ibutton_v3:481: error: 'exLong' was not declared in this scope
ibutton_v3.ino: In function 'void applySetting(String, String, char)':
ibutton_v3:473: error: cannot convert 'String' to 'const void*' for argument '2' to 'void* memcpy(void*, const void*, size_t)'
ibutton_v3:474: error: incompatible types in assignment of 'char' to 'unsigned char [8]'
ibutton_v3:477: error: incompatible types in assignment of 'String' to 'unsigned char [8]'
ibutton_v3:478: error: 'exBoolean' was not declared in this scope
ibutton_v3:481: error: incompatible types in assignment of 'String' to 'unsigned char [8]'
ibutton_v3:482: error: 'exLong' was not declared in this scope
I've try to change G_Addr from unsigned char to String but there were new problem
That is NOT going in the right direction. Banish the stupid String class from your memory. Forget that it exists for the sole purpose of wasting memory.
so I'm looking to cicling store in temp [1] unsigned char the character reader
void readSDSettings(){
char character;
String settingName;
String settingValue;
unsigned char temp [1][8];
myFile = SD.open("settings.txt");
if (myFile) {
while (myFile.available()) {
character = myFile.read();
while((myFile.available()) && (character != '[')){
character = myFile.read();
}
character = myFile.read();
while((myFile.available()) && (character != '=')){
settingName = settingName + character;
character = myFile.read();
}
character = myFile.read();
while((myFile.available()) && (character != ']')){
for(int aa=0;aa<8;aa++) temp[1][aa]=character[aa]; // copia l'indirizzo
// settingValue = settingValue + character;
character = myFile.read();
}
so if I wanto so store inside temp the character i should cicle the reading
but this is the error
please help me before I become crazy
ibutton_v3.ino: In function 'void readSDSettings()':
ibutton_v3:434: error: invalid types 'char[int]' for array subscript
ibutton_v3.ino: In function 'void applySetting(String, String)':
ibutton_v3:477: error: incompatible types in assignment of 'String' to 'unsigned char [8]'
ibutton_v3:480: error: incompatible types in assignment of 'String' to 'unsigned char [8]'
ibutton_v3:481: error: 'exBoolean' was not declared in this scope
ibutton_v3:484: error: incompatible types in assignment of 'String' to 'unsigned char [8]'
ibutton_v3:485: error: 'exLong' was not declared in this scope
so if you see my sketch you can see that the first function was reading the key if never readed)
void lookUpKeys()
{
byte address[8]; // questo array conterrà l'indirizzo locale delle chiavi
while (ow.search(address)) // loop finchè trova nuovi dispositivi
{
if (address[0] == 0x01) // identificata chiave 1-wire
{
if(CheckSensor(address)==1) //se il crc ok la lettura è corretta
{
bool old=false;
for (int i=0;i<G_Devices;i++) if(CheckAddress(G_addr[i],address)) {old=true;break;} // se trovo l'indirizzo imposto old a true ed esco dal for
if(!old) // se la chiave non è ancora stata usata....
{
for(int aa=0;aa<8;aa++) G_addr[G_Devices][aa]=address[aa]; // copia l'indirizzo
G_Devices++; // incrementa il numero di devices memorizzati
lcd.setCursor(0, 0);
PrintAddress(address); // stampo l'indirizzo della chiave
}
PrintAddress(address); // stampo l'indirizzo della chiave
digitalWrite(17, HIGH); // accende il led sulla porta 13
delay(500); // aspetta un po'...
digitalWrite(17, LOW); //..e spegne di nuovo il led sulla porta 13
relayState = !relayState;
digitalWrite(9, relayState);
system = relayState;
}
}
so now I want to configure the kay by sd card so I think:
for(int aa=0;aa<8;aa++) G_addr[G_Devices][aa]=address[aa]; // copy address
G_Devices++; // incrementa il numero di devices memorizzati
this was the way that the original code use to store G-addr
I think so
read the value from SD card and copy inside G_addr
so G_addr is lenght 8
and max 10 G_addr
so I think that if I want to copy key1 inside the first G_addr I shoud use
fname.toCharArray(temp,8); // Convert the string to a character array
//G_addr[1][8] = temp;
for(int aa=0;aa<8;aa++) G_addr[G_Devices][aa]=temp[aa]; // copia l'indirizzo
now compile withour error but I don't know if this could works
PaulS please correct me I rewrite the function. I think now I'm nearest than before but you help me more !
void read_file_contents(String fname)
{
// This function opens the config.dat file on the SD card, reads the contents of the file and displays
// the contents on the serial terminal.
// Declare variables
lcd.clear();
char temp[100]; // Since the SD functions expect a character array and not a string we have to temporarily store the string in a character array.
fname.toCharArray(temp,100); // Convert the string to a character array
lcd.println("Reading config File");
delay (1200);
config_file = SD.open(temp); // Open the configuration file
if (config_file)
{
lcd.println("Reading command file");
while (config_file.available()) // While the file is available read the contents
{
number_of_key = config_file.readStringUntil('\n'); // Read the first line where stored number of key ( so the number of cycle for)
G_Devices = number_of_key;
for ( int cycle = 0; cycle<number_of_key ; cycle++)
for(int aa=0;aa<8;aa++)
address = config_file.readStringUntil('\n'); // Read the passphrase
G_addr[G_Devices][aa]=address[aa]; // store the reading inside G_addr
}
// Display the information that we read from the file
// Serial.print("SSID = ");
// Serial.println(ssid);
// Serial.print("Passphrase = ");
// Serial.println(passphrase);
}
config_file.close(); // Close the file.
}
the error is
ibutton.ino: In function 'void read_file_contents(String)':
ibutton:468: error: cannot convert 'String' to 'int' in assignment
ibutton:474: error: 'address' was not declared in this scope
ibutton:475: error: 'aa' was not declared in this scope
ibutton:475: error: 'address' was not declared in this scope
ibutton:481: error: 'ssid' was not declared in this scope
ibutton:483: error: 'passphrase' was not declared in this scope
Reading each line when I found the carriege return I must write the new key in G_addr[number_of_key+1] right ?
NO! That is nonsense.
You have a collection of boxes. There are 10 rows and 8 columns. Why is it so difficult to understand that a letter read from the file goes in one of the boxes? Why is it so difficult to understand that you need to keep track of which row the letter will end up on? Why is it so difficult to understand that you need to keep track of which column the letter will end up in?
Keeping track of the row and column) is dirt simple.
You have a global variable called row, initialized to 0.
You have a global variable called col, initialized to 0.
Every time you read a character from the file, test it.
If it is a carriage return, increment row and set col to 0.
Otherwise, store the character in the row'th row, in the col'th column and increment col.