Variable into char array

Hi,
I want to make a char array with some analog Read, but i've a problem with "operand +".

I have this:

PROGMEM prog_char content_page1[] = "<hr /><TABLE BORDER='1'><TR><TH>" + analogChan0 + "</TH><TH>" + valeurAnalog0 + "</TH><TH>Volts</TH></TR><TR><TH>" + analogChan1 + "</TH><TH>" + valeurAnalog1 + "</TH><TH>Amp&egrave;res</TH></TR><TR><TH>" + analogChan2 + "</TH><TH>" + valeurAnalog2 + "</TH><TH>Watts</TH></TR><TABLE>";

And my error code is:

multipage:62: error: invalid operands of types 'const char*' and 'const char [10]' to binary 'operator+'

Do you want to help me ?

A double quote will close the string.

So this: "Hello" world" is a string "Hello" with world" just hanging around.
To get the double quote into a string, use the escape character: "

char message[] = "A text with double quotes: \"Hello world\". ";

You can not get a variable in a PROGMEM (programmed along the sketch code in flash) area.
You have to do that runtime in a sketch.
For example you could use $1 or %A in the html code in PROGMEM, and replace that with the variables in the sketch.

i must edit the progmem.h an include my variable for read it in my html page ?

When i do this ? Or Where is located the progmem.h ?

Sorry i'm a little noob :stuck_out_tongue:

If you don't know what you doing, you shouldn't be looking to edit "progmem.h".
Maybe have a look at "sprintf_P".

Yes, i've an other idea with sprintf but, it's not working with PROGMEM

I've this:

#include <stdio.h>
EDIT: And if i put it here => char content_page1[200];
//PROGMEM prog_char content_page1[] = "<hr /><TABLE BORDER='1'><TR><TH>\"analogChan0\"</TH><TH>\"valeurAnalog0\"</TH><TH>Volts</TH></TR><TR><TH>\"analogChan1\"</TH><TH>\"valeurAnalog1\"</TH><TH>Amp&egrave;res</TH></TR><TR><TH>\"analogChan2\"</TH><TH>\"valeurAnalog2\"</TH><TH>Watts</TH></TR><TABLE>";
sprintf(content_page1, "<hr /><TABLE BORDER='1'><TR><TH>%d</TH><TH>%d</TH><TH>Volts</TH></TR><TR><TH>%d</TH><TH>%d</TH><TH>Amp&egrave;res</TH></TR><TR><TH>%d</TH><TH>%d</TH><TH>Watts</TH></TR><TABLE>", valeurAnalog0, analogChan1, valeurAnalog1, analogChan2, valeurAnalog2 );

With it, the program show error message:

multipage:66: error: expected constructor, destructor, or type conversion before '(' token
multipage:81: error: 'content_page1' was not declared in this scope

EDIT: OH WAIT...

No, it's not working.
Maybe that multi-page program not working with dynamic display on website...

No, it's not working.

Sorry to hear that.

Have another read of reply #3

You cannot just add literal string constants together like that. Arduino C++ is not Java.

Yes, how the function sprintf_P works ? I didn't see it :stuck_out_tongue:

Ma teacher told me to sprintf( char*, myChar, variable);

Like this (post #4):

sprintf(content_page1, "<hr /><TABLE BORDER='1'><TR><TH>%d</TH><TH>%d</TH><TH>Volts</TH></TR><TR><TH>%d</TH><TH>%d</TH><TH>Amp&egrave;res</TH></TR><TR><TH>%d</TH><TH>%d</TH><TH>Watts</TH></TR><TABLE>", valeurAnalog0, analogChan1, valeurAnalog1, analogChan2, valeurAnalog2 );

But, with this syntax, i've an error code (post #4 too). And the line with the "progmem prog_char content_page1[]=...", what that i make ? x)

Or, my syntax is wrong...

I didn't see it

Here

Don't troll me please, i already see this website :stuck_out_tongue:
But, sprintf_P is the same function that sprintf_P

So, what is the difference ? :slight_smile:

Now i've:

char chaine[200];
sprintf_P(chaine, PSTR("<hr /><TABLE BORDER='1'><TR><TH>%d[............]</TH><TH>Watts</TH></TR><TABLE>"), analogChan0, valeurAnalog0, analogChan1, valeurAnalog1, analogChan2, valeurAnalog2);

That correct ? :slight_smile:

sprintf_P(chaine, PSTR("<hr /><TABLE BORDER='1'><TR><TH>%d[............]</TH><TH>Watts</TH></TR><TABLE>"), analogChan0, valeurAnalog0, analogChan1, valeurAnalog1, analogChan2, valeurAnalog2);

You've only got one "%d" format specifier in there.

no, in the program i've six "%d".

Resume the beginning

I take this program Arduino Playground - WebServer

But, apparently, "PROGMEM prog_char content_page1[] = " HTML code";" didn't work with my variable like "valeurAnalog".

I WANT... No I MUST, display my dynamic variable into my website...

if I do not understand, say me...

Now, with this function:

sprintf_P(chaine,"<hr /><TABLE BORDER='1'><TR><TH>%d</TH><TH>%d</TH><TH>Volts</TH></TR><TR><TH>%d</TH><TH>%d</TH><TH>Amp&egrave;res</TH></TR><TR><TH>%d</TH><TH>%d</TH><TH>Watts</TH></TR><TABLE>", analogChan0, valeurAnalog0, analogChan1, valeurAnalog1, analogChan2, valeurAnalog2);

That can it works in this program ?

That can it works in this program ?

I have no idea, but in the time it took you to type that post, you could have tried it.

What do you intend to do with chaine when you get it populated?

I WANT... No I MUST, display my dynamic variable into my website...

If by dynamic variable you are referring to analogChan0, then the below code might be of interest. The link below may also have useful info.

// zoomkat's meta refresh data frame test page 5/25/13
// use http://192.168.1.102:84 in your brouser for main page
// http://192.168.1.102:84/data static data page
// http://192.168.1.102:84/datastart meta refresh data page
// for use with W5100 based ethernet shields
// set the refresh rate to 0 for fastest update
// use STOP for single data updates

#include <SPI.h>
#include <Ethernet.h>

const int analogInPin0 = A0;
const int analogInPin1 = A1;
const int analogInPin2 = A2;
const int analogInPin3 = A3;
const int analogInPin4 = A4;
const int analogInPin5 = A5;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
unsigned long int x=0; //set refresh counter to 0
String readString; 

//////////////////////

void setup(){
  Serial.begin(9600);
    // disable SD SPI if memory card in the uSD slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();
  Serial.println("meta refresh data frame test 5/25/13"); // so I can keep track of what is loaded
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
         if (readString.length() < 100) {
          readString += c; 
         } 
        //check if HTTP request has ended
        if (c == '\n') {

          //check get atring received
          Serial.println(readString);

          //output HTML data header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          //generate data page
          if(readString.indexOf("data") >0) {  //checks for "data" page
            x=x+1; //page upload counter
            client.print("<HTML><HEAD>");
            //meta-refresh page every 1 seconds if "datastart" page
            if(readString.indexOf("datastart") >0) client.print("<meta http-equiv='refresh' content='1'>"); 
            //meta-refresh 0 for fast data
            if(readString.indexOf("datafast") >0) client.print("<meta http-equiv='refresh' content='0'>"); 
            client.print("<title>Zoomkat's meta-refresh test</title></head><BODY>
");
            client.print("page refresh number: ");
            client.print(x); //current refresh count
            client.print("

");
            
              //output the value of each analog input pin
            client.print("analog input0 is: ");
            client.print(analogRead(analogInPin0));
            
            client.print("
analog input1 is: ");
            client.print(analogRead(analogInPin1));
                        
            client.print("
analog input2 is: ");
            client.print(analogRead(analogInPin2));
            
            client.print("
analog input3 is: ");
            client.print(analogRead(analogInPin3));
                                    
            client.print("
analog input4 is: ");
            client.print(analogRead(analogInPin4));
            
            client.print("
analog input5 is: ");
            client.print(analogRead(analogInPin5));
            client.println("
</BODY></HTML>");
           }
          //generate main page with iframe
          else
          {
            client.print("<HTML><HEAD><TITLE>Zoomkat's frame refresh test</TITLE></HEAD>");
            client.print("Zoomkat's Arduino frame meta refresh test 5/25/13");
            client.print("

Arduino analog input data frame:
");
            client.print("&nbsp;&nbsp;<a href='http://192.168.1.102:84/datastart' target='DataBox' title=''yy''>META-REFRESH</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://192.168.1.102:84/data' target='DataBox' title=''xx''>SINGLE-STOP</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://192.168.1.102:84/datafast' target='DataBox' title=''zz''>FAST-DATA</a>
");
            client.print("<iframe src='http://192.168.1.102:84/data' width='350' height='250' name='DataBox'>");
            client.print("</iframe>
</HTML>");
          }
          delay(1);
          //stopping client
          client.stop();
          //clearing string for next read
          readString="";
        }
      }
    }
  }
}

Hello :slight_smile:

zoomkat, i already see this tutorial and i make a first page for get back this variable with analogInput...

But, my project want too make many page ( first with AnalogInput Data, second config page, third for process the second page data)
So, i fund this tuto (Arduino Playground - WebServer), but apparently, PROGMEM Dosen't work with many variable, or char array dont want work with my analog Input :confused:

I've almost finished my project, but i want that many pages :slight_smile:

Thanks a lot :slight_smile:

EDIT: It's possible to define divers url like( myIP/index, myIP/setup, myIP/process) without PROGMEM ??