On Webduino, a Web Server Library for the Arduino Platform, and on favicon.ico

As reported earlier I had been given an Arduino Uno. I subsequently received my Ethernet Shield to hook the board up to the network. I’m clearly heading towards the Internet of things… Although I am still not 100% certain about what I’m going to do with the board (or how many additional ones I am going to have to buy) one things is pretty clear: It will have to be controllable and/or configurable over a web interface.

I found the Webserver example that ships with the Arduino IDE to be rather dull and unflexible. It wasn’t long before I stumbled upon Webduino, a very flexible generic Web Server library originally written by Ben Combee. The Webduino project homepage on Google Project Hosting points to this GitHub page. I downloaded the version adapted to Arduino 1.0 and started hacking away. Let me say this now: Webduino does meet my expectations.

However after a short while I ran into problems. None of them were to blame on the library, but rather on myself, but that’s actually not the point of this post… When I ran Wireshark to look at the data going over the network I noticed that for every page loaded Firefox also tries to download favicon.ico from the web server. Since Webduino sends a 400 error back on any requests for resources that have not been defined Firefox just keeps retrying forever.

At around the same time I discovered that, to avoid excess traffic from robots, there is a default robots.txt built into Webduino. So I decided to add a default favicon.ico, based on the icon used in the “Web_Image” example that ships with Webduino. Now when the first page is requested, Firefox loads the icon file, which actually eats more resources than one 400 error, but it pays off down the road when Firefox caches the icon and does not request it again, saving the Arduino from having to generate many 400 errors…

Webduino "Hello World!" page with favicon.ico

Webduino "Hello World!" page with favicon.ico; this is the default favicon.ico in my version of Webduino

And since I see projects hosted on GitHub as an open invitation to fork I ended up with my own Webduino project on GitHub. Feel free to look at the code, to fork, clone, whatever (MIT license), and to let me know what you think! (Oh, and I gave the readme some TLC and also added a keywords.txt file for syntax highlighting.)

Update: I started to write a “beautiful” API documentation

Tags: , , ,

  1. Cool, thanks for posting this.

    It’s too bad you can’t just send a 410 GONE answer and expect a browser to properly remember it really doesn’t exist. But googling suggests browsers including firefox keep requesting favicon.ico even if it is told it is GONE.

    That said, if you want to cut down on data a bit, an empty 200 OK for favicon.ico is handled acceptably by browsers (they just show no icon), and stops subsequent requests.

    But as long as you’re sending an answer anyway, why not have a nice icon?

  2. Alternatively, you can return a zero length file, rather than a full icon….

  3. Hi Nick and Karl,

    Thank you for your comments. Your idea of sending a zero file never occurred to me. I was so focused on other things I missed that option.

    I have just committed a change to GitHub allowing you to put

    #define WEBDUINO_FAVICON_DATA ""

    in your sketch, before #include "WebServer.h", which will cause Webduino to send no icon data at all. It also allows you to change the icon if you need to.

    In addition to that I found another issue with Firefox (didn’t check other browsers) where favicon.ico was still requested twice per session if you had a bookmark for your Arduino. By adding a Cache-Control header this is now really down to one request.

Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>