As part of a “grand plan”, I’m thinking about how to implement a feature rich Arduino web application, without getting myself tied up in knots worrying about blowing the capabilities of the ATmega in terms of program size, memory size or processor speed. Without an SD card to store all the files on, the simple logical answer is to hand off as much work as possible to “someone else”, so the content (i.e. all the big files) lives on my static host and the grunt of the runtime execution is performed by the user’s browser. The only thing the Arduino needs to do is serve the initial landing page and respond to (tiny) data requests. I know I’m not the first to approach the problem from this angle, but a bit of Googling hasn’t turned up any concrete examples upon which I could base my efforts.

  • Arduino returns a home page that;
  • references jquery.js from a CDN
  • references webapp.js from my static host
  • references webapp.css from my static host
  • doesn’t really contain anything else other than a bare HTML structure
  • Webapp waits for document.ready() and then;
    • generates UI content
    • makes AJAX request(s) to RESTful web services on the Arduino
    • references any images, or other required content, from my static host
  • Arduino handles incoming REST requests and returns JSON data

    Serving the webapp.js and webapp.css from my own static host means that;

    • code changes to the webapp can be deployed instantly with no need to change anything on the Arduino or upload a new sketch
    • the Arduino does not have to concern itself with storing/returning the large code files associated with the JavaScript for the webapp
    • because the HTML page is served from the same domain as the JSON responses, same-origin policy is satisfied for AJAX, without having to mess about with JSONP or proxies
    • if I keep the JSON structures simple, there’s no need to go hunting for a library implementation as it’s just a bit of string concatenation here and there

    When that elusive hour of “spare time” turns up, I’ll document the process and throw the code up on GitHub, but for the moment you’ll just have to say “wooh” and use your imagination!