Read from SD to ethernet, convert into letters.

I am making an controller, which holds the webpage(s) on the SD card.

When I use "client.print((char)c);" (line 172) it shows the webpage when I go to the arduino's ip.

But my problem is that the webpage will have some dynamic numbers in, which will be read and stored in the eeprom on the controller. So the webpage can have something like %e1%, which then should be replaced with what is read from eeprom address 1. To do so I figured I had to read one line at a time, process the line and replace if something needs replacing, then send the text to the client.

The problem is now that after I made it read one line at a time, and send it, it sends numbers instead. I then tried to use itoa (line 163) to convert the numbers back, but so far without any luck.

Anyone got an idea to what I can do, or what I am doing wrong?

Full source: //SD card stuff#include <SD.h>File myFile;//Ethernet stuff#include <SP - Pastebin.com

      while ((c = myFile.read()) > 0)
      {
        itoa(c, (char*)temp, 10);
        output += temp;

This makes no sense. You read a character from the file, treated it as a number, and converted the numeric value to it's string representation, and sent that.

So the webpage can have something like %e1%, which then should be replaced with what is read from eeprom address 1. To do so I figured I had to read one line at a time, process the line and replace if something needs replacing, then send the text to the client.

Sounds reasonable. You must start with reading a full record from the SD card, not just one character. Then, you need to determine if the record contains any pairs of %s. If so, you need to parse the value in between, and read from EEPROM.

You are not doing any of that, yet.

Start with reading a complete record from the SD card, and sending the complete record to the client, regardless of content.

When that works, determine whether the content needs to be altered, but do nothing about that,

Then, work on determining what the new content should be, again without actually getting the new content. Then, add in code to get the new content, but do nothing with it.

Next, change the code to send to the client to send the part before the first % to the client, then send the new content, then send the stuff after the second %.

Finally, deal with the situation where a record might contain more than one pair of %s.

PaulS:

      while ((c = myFile.read()) > 0)

{
       itoa(c, (char*)temp, 10);
       output += temp;



This makes no sense. You read a character from the file, treated it as a number, and converted the numeric value to it's string representation, and sent that.

So what can I do instead?

PaulS:

So the webpage can have something like %e1%, which then should be replaced with what is read from eeprom address 1. To do so I figured I had to read one line at a time, process the line and replace if something needs replacing, then send the text to the client.

Sounds reasonable. You must start with reading a full record from the SD card, not just one character. Then, you need to determine if the record contains any pairs of %s. If so, you need to parse the value in between, and read from EEPROM.

You are not doing any of that, yet.

It is reading until it sees a line change, and then sends it. (as far as I know, and what I have been figuring out by looking at some serial debug I added)
That part seems to be working.

And no, I am not doing anything that replaces the parts I want yet, because it would not make any sense to add that, before it actually can read and store the content properly.

PaulS:
Start with reading a complete record from the SD card, and sending the complete record to the client, regardless of content.

When that works, determine whether the content needs to be altered, but do nothing about that,

Then, work on determining what the new content should be, again without actually getting the new content. Then, add in code to get the new content, but do nothing with it.

Next, change the code to send to the client to send the part before the first % to the client, then send the new content, then send the stuff after the second %.

Finally, deal with the situation where a record might contain more than one pair of %s.

As I said, it can read the entire thing, and send it. But when I make it store one line at a time, and sending it. I am getting numbers instead of letters.

What that other character could I use instead? I know I am using % for something else too, but as it is a webpage, almost all characters can occur. That is why it is %something% chances of that being there is very low.

I know how to replace what I want to replace, but the problem is to get it stored so it can look at it and determine what to do with it.

It is reading until it sees a line change, and then sends it. (as far as I know, and what I have been figuring out by looking at some serial debug I added)
That part seems to be working.

This code:

      while ((c = myFile.read()) > 0)
      {

reads ONE character from the file. What you were doing with the character prior to the change to add the itoa code is a mystery. If all you were doing was appending the character to output, then, after the if() test, you would add code to test if output contains any % characters. That is where you then need to decide what to do.

PaulS:

It is reading until it sees a line change, and then sends it. (as far as I know, and what I have been figuring out by looking at some serial debug I added)
That part seems to be working.

This code:

      while ((c = myFile.read()) > 0)

{



reads ONE character from the file. What you were doing with the character prior to the change to add the itoa code is a mystery. If all you were doing was appending the character to output, then, after the if() test, you would add code to test if output contains any % characters. That is where you then need to decide what to do.

I am not sure what is wrong. Do you think I just add the itoa because I thought the code was too short? There is a reason I started experimenting with it. And that is because when I add c to the output, I ALSO get a number.

When I print it out to the client directly, I am getting what I expect. Like I also started by saying.

But when I start looking at what c is... I get a number and only numbers are then printed to the client.

What you tell me to do, is EXACTLY what I am trying to do. But so far, the question I started asking, so I could get to that part. Is still the problem. I know what I want it to do. But the problem is that the only thing I get from it, is numbers, not the characters I need.

client.print((char)c);
will give me and so on printed to the client...

while ((c = myFile.read()) > 0)
{
output += c;
}

I then get stuff like 342032912312495723

      int16_t c;

Data is stored on SD cards as bytes, not ints. If you want to read a character from the SD card, and send a character to the client, then c should BE a char variable. Then, there would be no reason to cast the value to a char.