http://www.iobridge.com/api/module/feed.json?key=zTFNFDol7706vSZnuxel
==== JSON Object ====
{
"module": {
"serial": "24000XXX",
"label": "ioServer Monitor",
"lat": "",
"long": "",
"location": "Gainesville, FL",
"datetime": "Dec-24-2008 00:35:22 AM",
"status": "Online",
"channels": [
{"channel": "1", "label": "Channel 1", "AnalogInput": "384", "AnalogInputRaw": "384", "AnalogInputScale": "Raw", "DigitalInput": "Off", "DigitalInputState": "0", "DigitalOutput": "On", "DigitalOutputState": "1"},
{"channel": "2", "label": "Channel 2", "AnalogInput": "308", "AnalogInputRaw": "308", "AnalogInputScale": "Raw", "DigitalInput": "Off", "DigitalInputState": "0", "DigitalOutput": "Off", "DigitalOutputState": "0"},
{"channel": "3", "label": "Channel 3", "AnalogInput": "0", "AnalogInputRaw": "0", "AnalogInputScale": "Raw", "DigitalInput": "0", "DigitalInputState": "0", "DigitalOutput": "0", "DigitalOutputState": "0"},
{"channel": "4", "label": "Channel 4", "AnalogInput": "2.737", "AnalogInputRaw": "560", "AnalogInputScale": "Voltage", "DigitalInput": "Off", "DigitalInputState": "0", "DigitalOutput": "Down", "DigitalOutputState": "0"}
]
}
}
===== Server-side XML =====
By adding the format parameter to the Data Feed URL, you can alternatively format the results in XML.
==== XML Feed URL Example ====
http://www.iobridge.com/api/module/feed.xml?key=zTFNFDol7706vSZnuxel
==== XML Object ====
2400XXXX
Gainesville, FL
2009-07-03 02:20:36
Online
2.737
14
Voltage
On
1
Off
0
310
310
Raw
On
1
Off
0
256
256
Raw
On
1
Off
0
279
279
Raw
On
1
Off
0
===== Client-side JSON =====
If you are using jQuery or other client-scripting libraries to parse JSON, you have the ability to use JSONP (JSON with Padding) to get JSON from two different domains using Callback.
==== JSONP Callback Data Feed URL ====
http://www.iobridge.com/api/module/feed.json?key=zTFNFDol7706vSZnuxel&callback=?
When callback is used, the Feed URL returns a JSONP object.
==== JSONP Object ====
jsonp1230097032945({
"module": {
"serial": "24000XXX",
"label": "ioServer Monitor",
"lat": "",
"long": "",
"location": "Gainesville, FL",
"datetime": "Dec-24-2008 00:36:40 AM",
"status": "Online",
"channels": [
{"channel": "1", "label": "Temperature", "AnalogInput": "103.6", "AnalogInputRaw": "665"
, "AnalogInputScale": "Temp F", "DigitalInput": "On", "DigitalInputState": "1", "DigitalOutput": "Off", "DigitalOutputState": "0"},
{"channel": "2", "label": "Channel Tester", "AnalogInput": "337", "AnalogInputRaw": "337", "AnalogInputScale": "Raw", "DigitalInput": "Hi", "DigitalInputState": "1", "DigitalOutput": "Off", "DigitalOutputState": "0"},
{"channel": "3", "label": "Servo", "AnalogInput": "269", "AnalogInputRaw": "269", "AnalogInputScale": "Raw", "DigitalInput": "On", "DigitalInputState": "1", "DigitalOutput": "On", "DigitalOutputState": "1"},
{"channel": "4", "label": "IR", "AnalogInput": "0", "AnalogInputRaw": "0", "AnalogInputScale": "Raw", "DigitalInput": "0", "DigitalInputState": "0", "DigitalOutput": "0", "DigitalOutputState": "0"}
]
}
})
===== Parsing JSON =====
You can get access to any of the data in the JSON Object by parsing out the desired keys.
For example here is a jQuery request and data selection from feed:
function checkTemp() {
$.getJSON("http://www.iobridge.com/api/module/feed.json?key=zTFNFDol7706vSZnuxel&callback=?",
function (data) {
storeTemp(data.module.channels[0].AnalogInput); updateGraph();
});
}
"data.module.channels[0].AnalogInput" references the scaled analog input value on channel 1 of the IO-204 Module.
If you would want the modules serial number, the reference would be “data.module.serial” using the serial key under module.
===== Client-side Application Step-by-Step =====
From soup to nuts, we wanted to show you a complete application extension of the Data Feed API and the steps involved. Share your projects at www.iobridge.com/projects.
The following projects takes your Feed URL extracts the Scaled Analog Input from Channel 1 and feeds Google Charts to return a Google-o-Meter indicating the current temperature using jQuery.
**Step 1:** Create a new HTML file called //ServerTempNeedle.html//
**Step 2:** Create the HTML frame work – head and body
ioBridge Server Temperature
**Step 3:** Load jQuery from Google JSAPI to the document header
**Step 4:** Add a ready function when the HTML fully loads to check the temperature from the feed and set a timer that will check the temperature every 10 seconds
$(function() {
checkTemp(); // Gets initial temperature
setInterval("checkTemp()", 10000); // Sets a 10 Second timer
});
**Step 5:** Add function that checks the temperature and updates the graph when the data is returned (use your feed URL to get your data or use our public feed to get our server temperature)
function checkTemp() {
$.getJSON("http://www.iobridge.com/api/module/feed.json?key=zTFNFDol7706vSZnuxel&callback=?",
function (data) {
// Channel 1 is the first element in the array
updateGraph(data.module.channels[0].AnalogInput);
});
}
**Step 6:** Add function to get the Google chart and display it in the “data_graph” division in the document body
function updateGraph(temp) {
var newTemp = temp-50;
newTemp = 100 - newTemp;
var chart_url = "http://chart.apis.google.com/chart?"
var chart_type = "cht=gom";
var chart_size = "&chs=300x200";
var chart_title = "&chtt=ioBridge Server Temperature";
var chart_data = "&chd=t:" + newTemp + "&chl=" + temp + " F";
var url = chart_url + chart_type + chart_size + chart_title + chart_data;
var i = $("
").attr("src", url);
$("#data_graph").empty().append(i);
}
**Step 7:** Save file and open in web browser such as Safari, Chrome, Firefox, Opera, or Internet Explorer
===== Live Examples =====
* [[http://www.iobridge.com/ServerTempNeedle.html|ioBridge Server Temperature Needle]]
* [[http://www.iobridge.com/ServerTempChart.html|ioBridge Server Temperature Chart]]
===== Google Chart - Temperature Meter Source Code =====
ioBridge Server Temperature
===== Google Chart - Temperature Chart Source Code =====
ioBridge Server Temperature
Current Temperature is °F
This chart will automatically add another data point every 10 seconds.
===== Additional Resources =====
* [[http://www.iobridge.com/ServerTempNeedle.html|ioBridge Server Temperature Needle]]
* [[http://www.iobridge.com/ServerTempChart.html|ioBridge Server Temperature Chart]]
* [[http://www.iobridge.com/technology|ioBridge Technology Page]]