Author Topic: Java Math  (Read 1455 times)

k-maub

  • Newbie
  • *
  • Posts: 24
Java Math
« on: December 22, 2009, 02:06:17 AM »
I'm a JavaScript noob, so forgive me if this is really easy to do, but I'm trying to make an iGoogle gadget so I can check on my ioBridge from that page.  It's easy enough to dump the embed code sample in a gadget and call it a day.

My main motivation, however, is to do some unique manipulation of the raw data to come up with a meaningful number for that sensor.  For instance, I made my own temperature sensor that is not calibrated to yours, so raw values translate to temperatures in a distinct way which I've figured out.  How do I retrieve the raw value from ioBridge so that I can manipulate it and then display the temperature on my iGoogle gadget?

Basically, I need a way to isolate the raw value from the ioBridge widget; for now, the embed code is just a javascript, and I can't seem to strip away the features and get at the number.

Thanks for any help you may be able to offer.
ryan

zero*gx

  • Full Member
  • ***
  • Posts: 116
    • zero*gx
Re: Java Math
« Reply #1 on: December 22, 2009, 02:21:12 AM »
i would poll the device using the iobridge api. its on the wiki.

parse the return call to get at the data you need, then perform math.

this solution is best scaled for single users or developers. probably isnt the best answer for distributing the gadget.

i dont code javascript, but i do enough programming to understand the flow of what you are doing.
zero*gx | imagineering solutions

k-maub

  • Newbie
  • *
  • Posts: 24
Re: Java Math
« Reply #2 on: December 22, 2009, 12:07:04 PM »
Ok, great; thanks!  I think you're right.  I had already done some work with Perl accessing the API and parsing a JSON return message.  I should have figured JavaScript would be able to handle JSON as well.  I'll bet it would even deal with XML as well.

I'll give it a shot, and update if anyone is interested in doing something similar.

zero*gx

  • Full Member
  • ***
  • Posts: 116
    • zero*gx
Re: Java Math
« Reply #3 on: December 22, 2009, 01:15:14 PM »
no problem!

id like to see what you do with it.
zero*gx | imagineering solutions

anestho

  • Newbie
  • *
  • Posts: 16
Re: Java Math
« Reply #4 on: February 11, 2011, 01:24:40 PM »
Has any progress been made on this?  I need to do some scale math too for a gadget. 

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 668
    • ioBridge Support
Re: Java Math
« Reply #5 on: February 16, 2011, 01:56:17 PM »
Are you putting the widget on a webpage or using it directly on the ioBridge interface? You can scale the widget using JavaScript if you embed on a page.
ioBridge Support
Community Team

anestho

  • Newbie
  • *
  • Posts: 16
Re: Java Math
« Reply #6 on: February 24, 2011, 02:43:35 PM »
I want to embed it into a google gadget in my igoogle personal page.  I tried adding the code to the helloworld.xml but it doesnt work.

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 668
    • ioBridge Support
Re: Java Math
« Reply #7 on: March 04, 2011, 12:25:53 PM »
ioBridge Support
Community Team

k-maub

  • Newbie
  • *
  • Posts: 24
Re: Java Math
« Reply #8 on: March 22, 2011, 02:38:04 PM »
Just FYI, here's my code that works for me when I make a "Google Gadget".  Curiously, it only works on a FireFox browser.  If anyone can see stuff I'm doing wrong, I'd appreciate some pointers....

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs title="ioBridge Checker" />
  <Content type="html">
    <![CDATA[
      Hello, world!<br>
Temperature (Raw):<br>
<script type="text/javascript">
document.write(unescape("%3Cscript src='" + "http://www.iobridge.com/widgets/io.js?YOURWIDGETID' type='text/javascript'%3E%3C/script%3E"),'<br>');
</script>
<script type="text/javascript">
function get_tempC() {
var numval = widgetGetValue('YOURWIDGETID');
var res = 10000*numval/(1023-numval);
var beta = 3907;
var r25 = 10000;
var temp = (beta*25-273.15*298.15*Math.log(res/r25))/(beta+298.15*Math.log(res/r25));
  return temp;
}

function update_temp(){
  var newtC = document.getElementById("tempCel");
  var newtF = document.getElementById("tempFahr");
  var newt = get_tempC();
  newtC.firstChild.nodeValue=newt.toFixed(1);
  var temptempF = newt*9/5+32;
  newtF.firstChild.nodeValue=temptempF.toFixed(1);
  }

var temp_out = get_tempC();
document.write('<span id="tempCel">',temp_out.toFixed(1),'</span> &#176C<br>');
var temp_outF = temp_out*9/5+32;
document.write('<span id="tempFahr">',temp_outF.toFixed(1),'</span> &#176F');
setInterval('update_temp()',60000);
</script>

    ]]>
  </Content>
</Module>