Author Topic: Data Feed API  (Read 2330 times)

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 669
    • ioBridge Support
Data Feed API
« on: December 24, 2008, 11:13:58 PM »
We are pleased to announce the ioBridge Data Feed API. Our developers have been putting together the API and documentation to allow you to extend ioBridge technology into your own desktop and web applications. Some of our users have been testing the API and have already created client-side applications with jQuery. For more information, documentation, and sample applications visit http://www.iobridge.com/technology. We are excited to see what you come up with. Let us know and we will feature the applications and projects on our blog.
ioBridge Support
Community Team

SouthForkWeb

  • Jr. Member
  • **
  • Posts: 50
  • Web Coding Master
    • South Fork Web Services
Re: Data Feed API
« Reply #1 on: December 24, 2008, 11:33:07 PM »
Thanks so much ioBridge dev team! I look forward to seeing what everyone comes up with as well. Cheers :D
http://SouthForkWeb.com - Professional Web Design and Hosting Services

jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 502
    • ioBridge.com
Re: Data Feed API
« Reply #2 on: December 26, 2008, 02:27:09 AM »
Here are two quick examples of the Data Feed API in action.

Both of these use Google Charts to dynamically create a visual representation of live data.  You'll need to let these pages stay open for a minute or so to see them doing their thing.

ioBridge Server Temperature Chart

ioBridge Server Temperature Gauge
 
« Last Edit: December 26, 2008, 02:29:18 AM by jason »
Jason Winters
ioBridge Developer

kevinsmith

  • Newbie
  • *
  • Posts: 11
Re: Data Feed API
« Reply #3 on: December 27, 2008, 05:49:16 PM »
Oh, this is fantastic. You guys are really making progress and in a very good direction.

I 'stole' your temperature charting code. I made a few changes to make it more easily customizable for other users. I'm including the altered code. Anyone who wants to chart their own temperatures it's really easy.

1) copy and past the code into a file on your computer named MyTempChart.html
  (if you Double click the file as is, you will see the ioBridge server's data.)

2) To point the chart at your own data: open the file with a text editor like textedit (or notepad for Windows users) and change 4 variables:

TempChannel : The channel the temperature probe is plugged into. This is zero based so if you plugged your temp sensor into channel 1 don't put 1, put 0.

MinTemp, MaxTemp: The minimum and maximum temp you want to be able to chart. If your temp is outside of these ranges the chart will just peg.
 
ioBridgeFeedURL: Login to ioBridge , go to your Modules, under actions there is a Feed link. Copy this link. Should be something like:
http://www.iobridge.com/interface/feed/FD_0BosKdymNbB3LyiFYUVI
I was able to copy the link by right clicking and choosing copy link location but if you don't use Firefox it will be slightly different.

Save the file and double click it. There you go.

Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<script type="text/javascript">


// THESE ARE CUTOMIZABLE
var ChartTitle = "IOBridge Temp Feed";
var ioBridgeFeedURL = "http://www.iobridge.com/interface/feed/FD_0BosKdymNbB3LyiFYUVI";
var MinTemp = 90;     
var MaxTemp = 115;
var TempChannel = 0; //The channel the temperature probe is plugged into. NOTE: zero based. This is 0-3, not 1-4.
var PollingPeriod = 10;  //seconds
</script>


<head>
<title>IOBridge Temperature Graph</span></title>
 
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load("jquery", "1");
    google.load("feeds", "1");
</script>
<script type="text/javascript">

var MaxDataLength = 1800;
var simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

function simpleEncode(valueArray) {

  var chartData = [];
  var encodingStart = valueArray.length - MaxDataLength;
  if (encodingStart < 0) {
     encodingStart = 0;
  }
  for (var i = encodingStart; i < valueArray.length ; i++) {
    var currentValue = valueArray[i];
    if (!isNaN(currentValue) && currentValue >= 0) {
       if (currentValue > MaxTemp )
          chartData.push('9');
       else if (currentValue < MinTemp )
          chartData.push('A');
       else
          chartData.push(simpleEncoding.charAt(Math.round((simpleEncoding.length-1) * (currentValue - MinTemp) / (MaxTemp - MinTemp) )));
    }
      else {
      chartData.push('_');
      }
  }
  return chartData.join('');
}
 
function my_state() { }
 
function storeTemp(temp) {
$("#my_mirror").text(temp);
my_state.values.push(temp);
}
 
function updateGraph(temp) {

var chart_url = "http://chart.apis.google.com/chart?"
var chart_type = "cht=lc";

var chartSec = my_state.values.length - 1;

chartSec = chartSec * 10;

    var chart_size = "&chs=400x400&chtt="+ChartTitle+"&chds=0,"+simpleEncoding.length+"&chxt=x,y,x,y&chxl=2:||Time (s)||3:|||Degrees (F)||&chxr=1,"+MinTemp+","+MaxTemp+"|0,0,"+chartSec;
if (my_state.values.length > 1)
var chart_data = "&chd=s:"+ simpleEncode(my_state.values);
else
var chart_data = "&chd=s:"+ simpleEncode(my_state.values) + simpleEncode(my_state.values);
var url = chart_url + chart_type + chart_size + chart_data;
 
var i = $("<img>").attr("src", url);
$("#data_graph").empty().append(i);

}
 
function checkTemp() {

$.getJSON(ioBridgeFeedURL + "&callback=?",
function (data) {
        storeTemp(data.module.channels[TempChannel].AnalogInput);
        updateGraph();
});

}
 
$(document).ready(function() {
my_state.values = [];

checkTemp();

$("#my_pollingperiod").text(PollingPeriod);
$("#my_charttitle").text(ChartTitle);
my_state.check_interval = setInterval("checkTemp()", PollingPeriod * 1000);

});

</script>
</head>
<body>

<div id="container">
<div id="data_graph"> </div> <p>
<div id="header" >
Current Temperature is <span id="my_mirror"></span>&deg;F<br><br>
This chart will automatically add another data point every <span id="my_pollingperiod"></span> seconds.   

</div>
</div>
 
</body>
</html>
« Last Edit: December 28, 2008, 01:37:27 AM by lynn »

jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 502
    • ioBridge.com
Re: Data Feed API
« Reply #4 on: December 28, 2008, 01:56:04 AM »
That is definitely an improvement over the charting script we put together.  Great work!

A few more posts like yours and we'll need to add a new "user created widgets" section to our website.   
Jason Winters
ioBridge Developer

kevinsmith

  • Newbie
  • *
  • Posts: 11
Re: Data Feed API
« Reply #5 on: December 29, 2008, 04:45:41 AM »
Here's a code snippit. This is particularly useful for getting your analog data into excel. This HTML will create a table with the 4 columns, one for each analog channel. The table will grow with new data appended to the end. You can simply copy and paste the data into excel.
(As is, this will show you the analog output of the iobridge server, the first column is temperature.)

Use it much like the previous code snippet I posted. I.E. save it to your computer then change the URL to your feed URL as described in the previous post. Enjoy.

Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>IOBridge Temperature Graph</title>
 
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load("jquery", "1");
    google.load("feeds", "1");
</script>
<script type="text/javascript">

// THESE ARE CUTOMIZABLE
var ioBridgeFeedURL = "http://www.iobridge.com/interface/feed/FD_0BosKdymNbB3LyiFYUVI";
var PollingPeriod = 10;  //seconds

var channel0Analog=new Array();
var channel1Analog=new Array();
var channel2Analog=new Array();
var channel3Analog=new Array();

function createTable() {
        // get the reference for the body
        var body = document.getElementsByTagName("body")[0];
       
    while ( body.childNodes.length >= 1 )
        body.removeChild( body.firstChild );       

        // creates a <table> element and a <tbody> element
        var tbl     = document.createElement("table");
        var tblBody = document.createElement("tbody");

        // creating all cells
        for (var j = 0; j < channel0Analog.length; j++) {
            // creates a table row
            var row = document.createElement("tr");

            for (var i = 0; i < 4; i++) {
                // Create a <td> element and a text node, make the text
                // node the contents of the <td>, and put the <td> at
                // the end of the table row
                var cell = document.createElement("td");
                var cellText;
                if ( i == 0 )
                cellText = document.createTextNode(channel0Analog[j]);
                else if ( i == 1 )
                cellText = document.createTextNode(channel1Analog[j]);
                else if ( i == 2 )
                cellText = document.createTextNode(channel2Analog[j]);
                else if ( i == 3 )
                cellText = document.createTextNode(channel3Analog[j]);

                cell.appendChild(cellText);
                row.appendChild(cell);
            }

            // add the row to the end of the table body
            tblBody.appendChild(row);
        }

        // put the <tbody> in the <table>
        tbl.appendChild(tblBody);
        // appends <table> into <body>
        body.appendChild(tbl);
        // sets the border attribute of tbl to 2;
        tbl.setAttribute("border", "2");
    }


function my_state() { }

function checkTemp() {

$.getJSON(ioBridgeFeedURL + "&callback=?",
function (data) {
        channel0Analog.push(data.module.channels[0].AnalogInput);
        channel1Analog.push(data.module.channels[1].AnalogInput);
        channel2Analog.push(data.module.channels[2].AnalogInput);
        channel3Analog.push(data.module.channels[3].AnalogInput);

        createTable();
});

}
 
$(document).ready(function() {
my_state.values = [];
checkTemp();
my_state.check_interval = setInterval("checkTemp()", PollingPeriod * 1000);

});

</script>
</head>
<body>

<div id="container">
<div id="data_table"> </div>
 
</body>
</html>

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 669
    • ioBridge Support
Re: Data Feed API
« Reply #6 on: December 29, 2008, 04:55:10 AM »
Wow, this is cool. Thanks for taking the time to put this together. I will get together some of these snippits and share them on the Projects blog. Thanks again.
ioBridge Support
Community Team

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 669
    • ioBridge Support
Re: Data Feed API
« Reply #7 on: January 31, 2009, 03:34:20 AM »
If you have a channel that is set to "Serial Mode", the data feed API will return two new keys:

LastSerialInput
LastSerialOutput

This will return the last data in the Serial Smart Board's incoming and outgoing buffer. You will only be able to request this data every 10 seconds, and for most apps 30 seconds to a minute would be adequate.
ioBridge Support
Community Team

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 669
    • ioBridge Support
Re: Data Feed API
« Reply #8 on: July 02, 2009, 11:10:59 PM »
Updated Data Feed API documentation on the Wiki. Now includes XML, Serial, and some sample applications.

http://www.iobridge.net/wiki/api/data-feed-api
ioBridge Support
Community Team