Hi everybody,
I'm trying to copy a string from the flash memory to a char[] variable. But because of the __FlashStringHelper * type I don't know how to do it.
Any idea?
I'm working on a Web Server with a table which I have to construct on each iteration (see code below). But I don't want to send the string and numerical information separately because of the TCP overhead. So instead, I would like to store and concatenate the info in a fixed size buffer and when full, send it.
I already posted a thread about it (without flash memory)
http://arduino.cc/forum/index.php/topic,103110.0.html and I have good performance for a buffer of 60 bytes. But because I'm running out of memory I need to store the HTML code in the flash memory.
I'm having error because of the different types. I need a way to copy the flash values to RAM values.
Tnx!!
const int Buffer_length = 90;
char buffer[Buffer_length];
int TempTable[5][5];
void SecondTable(EthernetClient client)
{
for (int i = 1; i < 5; i++) {
int i=1;
printI(i,client);
printC(F("</td><td align='center'><input type='text' name='Block"),client);
printI(i,client);
printC(F("1' value='"),client);
printI(TempTable[i-1][0],client);
printC(F("' size='2' maxlength='2'/>: <input type='text' name='Block"),client);
printI(i,client);
printC(F("2' value='"),client);
printI(TempTable[i-1][1],client);
printC(F("' size='2' maxlength='2'/></td><td align='center'><input type='text' name='Block"),client);
printI(i,client);
printC(F("3' value='"),client);
printI(TempTable[i-1][2],client);
printC(F("' size='2' maxlength='2'/>: <input type='text' name='Block"),client);
printI(i,client);
printC(F("4' value='"),client);
printI(TempTable[i-1][3],client);
printC(F("' size='2' maxlength='2'/></td><td align='center'><input type='text' name='Block"),client);
printI(i,client);
printC(F("5' value='"),client);
printI(TempTable[i-1][4],client);
printC(F("' size='2' maxlength='2'/></td></tr>"),client);
}
void printI(int num, EthernetClient client){
if (strlen(buffer)<Buffer_length-6) //we add the int value only if we have enough space!
{
sprintf(buffer,"%s%d",buffer,num); //we add the int value to the buffer
}
else {
client.println(buffer); //we send the buffer though the net
buffer[0]='\0'; //we reset the buffer
sprintf(buffer,"%s%d",buffer,num);
}
}
void printC(const __FlashStringHelper * info, EthernetClient client){
int length_array1=strlen(buffer);
int length_array2=strlen(info);
if (Buffer_length-1>length_array1+length_array2)
{
strcat(buffer,info);
}
else {
client.println(buffer);
buffer[0]='\0';
strcat(buffer,info);
}
}