DrTomAllen.com
tom@jugglethis.net
  • Dr Tom
  • Now
  • Consulting
    • Testimonials
  • Robotics
    • Publications & Videos
  • Startups
    • Cubescape
    • Triple Point Robotics
  • Game Design
    • Bounces
    • Dodgy Wiring
    • Half the Battle
    • Road to Nowhere
    • Summon the Swarm
    • Evil Robots
    • Spelled
  • Blog

electric imp HttpIn using AJAX from a static HTML page without PHP, jQuery, or access to the electric imp Agents beta test. Phew!

17/9/2013

 
I spent a while refreshing my HTML front end skills while trying to get a basic electric imp prototype going. Since the EI forums have a paucity of information on this topic, here's a basic guide and some sample code. The point of this code compared to others you might find is that this one doesn't require access to the electric imp Agents beta test, doesn't require the use of jQuery, doesn't need you to have a PHP-capable webserver, and is really really simple.

This demo code is a basic webpage with five buttons corresponding to servo motor positions. You could use a slider instead, or toggles, or drive LEDs - whatever. The point is that clicking the buttons uses asynchronous javascript to POST to the EI API without loading the API response as a new webpage. So you don't see the "OK" and have to hit your back button. Simply dump the index.html file on your webserver with your HttpIn node's API endpoint, and your impee's UID in the obvious spots. Yes, this is a security risk, but for a basic prototype I and you probably don't care. Later on, when everyone is using Agents anyway, this won't be a problem. For now - enjoy!

Update 18/09/2013 - Added code for doing the same thing if you do have access to the Agents beta test. The HTML code stays the same - other than pointing the httpRequest to agent.electricimp.com/... instead of the older api.electricimp.com/v1/... - but you can remove your HttpIn node from the blueprint, and then use the attached Agent and Device scripts similarly to the original.

Comments are closed.
    This blog is very seldom updated. Having kids will do that.
    ​

    Archives

    October 2022
    August 2021
    October 2019
    June 2019
    February 2016
    July 2015
    July 2014
    June 2014
    February 2014
    October 2013
    September 2013
    May 2013
    April 2013
    March 2013
    November 2012
    September 2012
    August 2012
    June 2012
    May 2012

    Categories

    All
    Coffee
    Hacking
    Programming
    Projects
    Rants
    Robots
    Startups
    Thoughts

    RSS Feed