Webduino - webserver library [PORTED]


This is a port of webduino, an arduino webserver running on the ethernet shield. Of course, on the spark you don’t need an ethernet shield - it’s network enabled out of the box!

I ported this to the spark and fixed a few bugs. I will also write some documentation to augment what is available in the original repo.

I was expecting this to be a nightmare to port, since it had an entirely different network stack, but it was a breeze! It turns out the TCPClient and TCPServer in the spark firmware were completely API compatible with EthernetClient and EthernetServer classes that the library was expecting. All in all I was done in about 30 minutes, so hats off to the spark team for having the foresight to make the APIs compatible! :thumbsup:


Very cool, thanks for sharing! Much nicer than my tiny webserver :slight_smile:


@mdma, thanks for sharing, nice work!

One quick question, found declaration and implementation in the header file itself, any particular reason?

It’s like that simply because that’s the way the original library was. Although I often code my libraries like that also, since it’s quite convenient.

You only include it once (from your application.cpp) so it’s the same as if the implementation were separate. (If it’s ever included from multiple sources then you’ll get linker errors and that’s when there’s a difference.)

1 Like

Hi @mdma,

I just tried this code in the Spark Online IDE and it came up with the below error. What is it that I am doing wrong. Sure would like to test it.

Thanks ahead of time, Bobby

Error compiling:

In file included from ../inc/spark_wiring.h:30:0,
from ../inc/application.h:29,
from /webduino-webserver.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]  
# warning "Defaulting to Release Build"
/webduino-webserver.cpp:3:33: fatal error: WebServer/WebServer.h: No such file or directory
void setup();
compilation terminated.
make: *** [/webduino-webserver.o] Error 1

Error in WebServer.h file

// This #include statement was automatically added by the Spark IDE.
# include "WebServer.h"

In using the Spark Online IDE, I hit the “INCLUDE IN APP” button on the Libraries selection, which put the following include statement in my file:

#include "WebServer/WebServer.h"

The compiler was able to find the WebServer.h file - maybe that will help you, @spydrop?
However, after that the compiler hit some other errors:

In file included from /httpserver.cpp:1:0:
/WebServer/WebServer.h:181:1: error: expected class-name before '{' token
/WebServer/WebServer.h:203:41: error: 'uint16_t' has not been declared
WebServer(const char *urlPrefix = "", uint16_t port = 80);
/WebServer/WebServer.h:330:24: error: 'uint8_t' has not been declared
virtual size_t write(uint8_t);

Any thoughts on this, @mdma? I can provide the rest of the errors if necessary.

That include statement looks wrong - it should be

 #include "WebServer/WebServer.h"

I’d fixed these in the examples, but had forgotten to push (duh, again, that’s twice in a week for me!)
But the examples are now fixed, so if you browse the library, try the HelloWorld example again it should compile. (Alternatively, just change that #include to the one I give above.)

1 Like

this sounds like it could be a preprocessor problem - how much code is there in your httpserver.cpp file? If httpserver.cpp is not the main application file, then you’ll also need to include “application.h” before the webserver.h include.


I tried using “Webser/Webserver.h” but, SPark Core Online IDE can not find the file.

I started over with a new app name in the Online IDE and pasted your Hello World exmaple in a IDE App called webserver / Nothing is in WebServer.cpp / Placed your WebServer.h code in the WebServer.h file.

Save = OKay

Compiled = Fail

Change in WebServer.cpp

 #include "WebServer/WebServer" 


#include "WebServer"

Compile = OKAY

Core is assigned —> Opened in browser --> Times Out --> No Page Display.

I am not a coder so I won’t be able to figure this out.

Is it because WebServer.cpp is empty ?

Can you confirm you have added the webserver library to your app in the IDE?

The include is missing “.h” that’s very important.

EDIT; @spydrop - I re-read your post and you’re not adding the library. You don’t need to copy and paste files. See the docs for details on using libraries in the online IDE:


Once you’ve selected the webserver library, you can click on an example e.g. “Hello World” and have that compiled and flashed to the spark.



I finally got your WebServer to Compile in Spark IDE but, it took a few trys as the Include in App option does not work.

What Finanly worked was like you said, not to copy code. Their is a linked Video in the Docs that specifcally illustrates “Copy & Paste” code in to an existing app that really screwed me up :frowning:

In the Spark IDE the “INCLUDE IN APP” button does not work to copy example code to an existing App like it should. It only includes the link to WebServer.h . I found that even manually coping one of your Example Code in to an existing APP gives an error.

So th Process that Worked to Compile your Code / Ported Library is:

  1. Click Libraries Icon
  2. Select Webserver
  3. Click on Hello World
  4. Click Button = USE THIS EXAMPLE
  5. Change include path to
#include "WebServer/WebServer.h"

Thanks for the help as I really do appreciate it.


1 Like

Thanks for the help from both of you! Got it compiling both inside of the Spark editor using those steps and outside of the editor being sure I included the application.h.

Thanks for porting the Webduino library, mdma!


I have tried the library with the hello world example, it compiles and uploads to the spark fine. When I navigate to the spark’s IP address I get a page with “EPIC FAIL” in large bold uppercase letters. This seems to come from line 78 of WebServer.h. I could not find anywhere in the code to enter the IP or MAC address of the spark, I must be missing something obvious.
Any ideas?

The url should be




Other urls are not handled, and will generate that error message.

Hope that helps! :slight_smile:

That is exactly the url format that I have tried with. I have uploaded the code unaltered and still get the error message.

I recently wrote a personal message to @mdma regarding html code, in hindsight I should have posted here. Anyway, I wanted to post the question and response for others to see.

My Question:

Hi Matthew,

I’m curious if you might be able to help with something. I have been
able to load your webserver without issue, thank you for putting time
in to that. I’m working on this project, https://community.spark.io/t/spark-spark-relay-controlled-peristaltic-dosing-pumps/4888/56
and part of what I want is for the html control side to be part of the
spark core, hence your server. The piece of HTML is tiny, but for the
life of me I cannot figure out how to port standard html over to code
that your server can read. Is that something you can help me with?

I’m really hoping that the SD/Fram shield is released soon as I think
it would solve my problem. Provided that is they design it so the
spark core can read basic HTML from an SD card, as the arduino ethernet
shield does.

@mdma response:

For small pages, you embed them directly in the code, like this:

server.println("<html><body>Hello world</body></html>");

For a larger example, see my minibox demo.

According to this Stack Overflow question, you can now use raw string literals in C++99 which means you can pretty
much just copy and paste your HTML text into the source code.

const char* webpage = R"$\
<TITLE>Auto-generated html formated source</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#ffffff">
<P> </P>

Very Nice ! Files stored on the Spark Core - Job Well Done.

@mdma, @kennethlimcp can this pe used to get / post files to the Spark MicroSDcard ?


simply treat the uSD card as a memory. There’s a write up here on hosting the .htm/.html file + web server :wink:



I guess I spoke too soon, I the webserver loaded fine, and flashed fine, but nothing shows up when I go to my sparks ip. I’ve tried just as @mdma noted, and the browser just times out.

I see the included libraries, and if I click on the Web server library I get all of the web server files. I do see that webserver.cpp is empty, I’m not sure what the significance of that is though.

I’ve tried everything under the sun, I can’t get this to work. I can get the tiny web server working no problem. I last tried just doing the hello world, and even that doesn’t work. I added #include application.h as well, still no luck.