If you don’t know what an ioBridge is I suggest you first read this page. It’s basically enables you to hookup all kinds of physical stuff (sensors, readers, led’s, lcd’s, servo’s, motors, etc) and control them true the web with great ease.
The people from ioBrigde have done a great job making it very easy to get your first project up and running. Just hook the ioBrigde up to any internet connection, browse to you personal ioBridge control panel and create some widgets to control the input and output channel. I got my first project running in under 10 minutes without any prior knowledge about the system!
There are different ways to talk to your ioBridge module. One of the are the widgets on the iobrigde.com site but there are also different API’s available. Unfortunately it was pretty hard to access your module using regular http calls. You best shot was to make use of the JavaScript Widget Control API but this isn’t a very flexible API as it forces html code onto your page and is useless if you want to make http calls from Java/PHP/Phyton/etc.
Another problem with the available ioBridge API’s is that they are slow. If you for instance want to make a background call to your ioBrigde when someone opens your website to blink a light you don’t want the visitor of your website to wait for 2 seconds before the ioBridge module returns a response. The event should be triggered without the user hardly noticing any delay. The way to make background calls on the web is of course by using Ajax. This brings another challenge along. As the ioBridge is located at iobridge.com every request goes to that domain. And as we all know you can’t make cross-domain Ajax calls.
So the ioBridge that has 3 issues
1. No easy API to control the module from anything else then a webpage
2. The module isn’t very fast and can become a bottleneck
3. Can’t make Ajax calls as the module is located at iobridge.com
The code that you’ll find below fixes all these things!
My solution to this was to create an ioBridge Proxy that resides on you local server, parses your requests and forwards them to your module. To this I added a new JavaScript API that utilizes this proxy and by default makes it’s call using Ajax.
How to use this?
Follow these very simple steps to use this new ioBridge API.
1. Download iobridge-proxy.php to your computer
2. Upload iobridge-proxy.php to your webserver (requires PHP >5)
3. Now create a widget using your iobridge.com portal. One that activates a lights or reads an analog value are probably the best to test.
4. Next up copy the widgetID (not the actionID!) and open the url in your browser, this should look something like http://yourdomain.com/iobridge-proxy.php?widgetID=xxxxxxxxxxxx.

5. If you just want to make http calls from lets say PHP then you’re done!
The next steps are useful if you want to use the Ajax API.
6. Download iobridge.js and example.html
7. Open iobridge.js and change the baseUrl variable so that it matches your domain and directory structure
8. Open example.html and change the widgetID’s.
* execute should be an Digital Output Pulse widget
* getValue should be an I/O Monitor widget
* setState(on) and setState(off) should be an Digital Output Control widget
* setValue should be an Serial Out or Send Serial Message widget
9. Upload iobridge.js and example.html to the same server as your iobridge-proxy.php
10. Open http://yourserver.com/example.html and test the functions
The current example uses JQuery to make the Ajax calls but of course you can change this to anything you like.
That’s it, with these 3 files you’ve freed your ioBridge from the constraints of the current API’s. It’s should now be a lot easier to use the ioBridge in any of your mashup projects!
update
See this article if you’re looking for an example that doesn’t use any javascript to control the module.
Download files
* iobridge-1.0.zip (all required files)








Comments (3)
Congrats on the iobridge projects! I’ve built a few python scripts for it which you can pull from my site:
http://blog.thecapacity.org/category/iobridge/
I found that there’s not too much of a delay with the HTTP calls (maybe 200-300 ms at most) and it was enough for me to get close to real time feedback and control.
On occasion I’ve had to build a queue system with a producer / consumer pair of threads but luckily python makes that pretty easy!
Oh, also you can make ajax calls using iobridge’s JS library, and sometimes I’ve taken advantage of jQuery too.
Both leverage JSONP so the “security” feature preventing you from calling offsite is bypassed.
@jay I’ve seen your projects, very cool!
Trackbacks/Pingbacks (3)
[...] MarcAThing.com “new and improved” < An easy API for the ioBrigde to use with Ajax/PHP/Java/Phyton/etc [...]
[...] chip. His project includes some JavaScript to control the LCD display via a web page which uses his PHP-based proxy and control API for the IO-204. ioBridge IO-204 Controlling Spark Fun [...]
[...] described earlier how you can use the ioBridge proxy as an easy API to control your ioBridge module with anything that can make a http call. The [...]