Embedded web server is all about clever formatting


Take a look around here and you’ll find all kinds of embedded web servers. This one doesn’t look all that interesting, especially because it’s just a NIC plugged into a development board. But for us the interesting part is in how [Andrew Rossignol] chose to format the webpage assets to best utilize the under-powered server.

The project was spawned as part of a class in Internet Embedded Systems which [Andrew] is taking. The board has an ATmega16 microcontroller and he’s using the ever popular ENC28J60 on that Ethernet adapter board. The TuxGraphics TCP/IP Stack takes care of communications with the network.

One constraint which [Andrew] imposed upon himself was to use just a single response which the available RAM limits to about  700 bytes. Any decent webpage needs to have at least some graphics but that’s tough with the size limit. He managed to display an AVR logo by optimizing an SVG in Inkscape then stripped the rest of the cruft using VIM (explained in the demo after the break). With that piece of Linux-fu in his pocket he set to work streamlining the CSS file. The webpage isn’t just static either. He displays the server up-time and even allows the relays and LEDs on the Olimex board to be controlled.

Despite the limitations of the ATmega family they still seem to do some amazing Internet-connected stuff. Here’s one used as a Minecraft server.

18 thoughts on “Embedded web server is all about clever formatting

      1. The original article says: “One severe limitation of this hardware is the 1kB of RAM. This limits the response size to approximately 700 bytes.”

        He doesn’t talk about directly sending a single response from flash, so it’s possible he didn’t think of that option.

        1. I did consider this option, but decided not to go this route. At some point, program memory is going to become a concern as well so I might as well minimize as much as possible. The image is already about 11kB out of the total 16kB.

          It was more “because I can” when limiting myself to the small buffer size.

          1. I don’t think that’d be an issue anyway: the data has to come from somewhere before it goes into RAM, so it could just as well be streamed from that location without putting a RAM-buffer in between. I respect your ‘because I can’, by the way, it’s always good to practice, just saying this probably isn’t the most optimal way to get low RAM usage.

          2. ATMEGA324 or ATMEGA644 will drop in where a 16 goes, if you ever need more ROM. I think they have more RAM as well, but don’t remember off hand.

  1. Did you (Andrew) look into doing some compression to get a bit more space. RLE takes basically no memory for decode/encode and can be just about as fast as direct memcpy.

    1. I had thought about using runs, but gzipping done at compile time and provides better compression ratios. I don’t think run length encoding gzipped content would be a good idea.

      I basically have a web folder full of my js, css and html files that are gzipped and converted into h file includes. This system has no notion of a file system.

      1. I disagree, a good university Engineering education concentrates on the underlying mathematics and physics that make all these wonderful technologies possible. You don’t want to spend much of your precious university time banging on software and hardware that will be obsolete in a few years. Yes, some lab work is necessary in school to bring theory to life, but that’s not the focus. After you get a job – that’s when your education continues at the nuts & bolts level you desire.

  2. As for limited storage, Why not just put an SD flash card on the thing and use a couple of pins to get stuff in and out. I think there are at least a few pre-built SD card FS library options for AVR out there.

  3. While the old the5k.org entries wouldn’t have had a prayer on this device, perhaps the current js1k.com competitors could squeeze their code just a *bit* tighter.

  4. hey andrew,
    Can you please share your code.. I am trying to implement the same thing with Mega16 running on 8 MHz and ENC28j60 breakout module..i am not able to taste the sucess..please help…I am using AVRSTUDIO 5.0 on XP

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.