Author Topic: Serial API and Javascript  (Read 988 times)

webbr

  • Newbie
  • *
  • Posts: 6
Serial API and Javascript
« on: August 11, 2009, 04:36:18 PM »
Hello Everyone,

I was wondering if I could get some help with parsing data coming in from the Serial API. I have the data coming in and it is over the form: DATA #+#+#+#+#, but I am a little confused as to how to parse the data.    
Basically how do I store the input as a Javascript variable so I can use the split function? If someone could provide an example of how to do this using the Serial API example: http://www.iobridge.net/wiki/api/serial-api that would be really helpful.

Thanks!

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 668
    • ioBridge Support
Re: Serial API and Javascript
« Reply #1 on: August 13, 2009, 11:47:20 PM »
Hi Webbr:

Try this code below. I have tried to comment in the example to explain what is going on. My hope is that the solution is straightforward.

You will need a Serial API key and place it into the script for this to work properly.

Good luck!

Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ioBridge Serial Buffer Stream</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">
 
function checkSerial(returnedStreamID) {
 
if (returnedStreamID) {}
else {returnedStreamID = "new";}
 
$.getJSON("http://www.iobridge.com/api/serial/buffer/key=FD_XXXXXXXXXXXXXXXXXXXX&streamID="+returnedStreamID+"&callback=?", function (data) {   
 
        // SerialData is the parsed variable that contains the serial string
        var SerialData = data.serialObject.SerialData;
 
  //Act on the serial string if it exists, otherwise go back and ask the API for the string
if (SerialData) {

// Update webpage (only purpose is a visual echo
document.getElementById('updateID').innerHTML = SerialData;

//Split Serial String into an array
var responseParts = new Array();
responseParts = SerialData.split("+");

//responseParts is an Array with the data

var firstPart = responseParts[0];
var secondPart = responseParts[1];

//etc.

//Perform actions

//Repeat

}
 
var streamID = data.serialObject.streamID;
        checkSerial(streamID);
});
}
 
$(document).ready(function() {
 
checkSerial();
 
});
 
</script>
</head>
<body>
 
<div id="updateID">Listening...</div>
 
</body>
</html>
ioBridge Support
Community Team

webbr

  • Newbie
  • *
  • Posts: 6
Re: Serial API and Javascript
« Reply #2 on: August 14, 2009, 11:31:52 AM »
Thanks!


noelportugal

  • Newbie
  • *
  • Posts: 35
    • http://blogs.oracle.com/noelportugal/
Re: Serial API and Javascript
« Reply #3 on: October 26, 2009, 08:49:03 PM »
I'm testing the Serial API and I'm a bit confused about the key. Do I need to request one or should I use the one listed under my module as "Data Feed API Key"?

-Noel

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 668
    • ioBridge Support
Re: Serial API and Javascript
« Reply #4 on: October 26, 2009, 09:07:47 PM »
Send an email to support@iobridge.com and we will fix you up with a key. The Serial API uses a buffer on the server that is separate than the module feed.
ioBridge Support
Community Team