-
Dec 7th, 2011, 04:27 PM
#1
Thread Starter
New Member
Help with a problem pls
I am wanting to display 3 separate data feeds on my mobile website from Pachube like this and have modified some code (which was designed just to display 1 feed). As you will see the code has been extended (all added code is in red) but does not display (at all!) on a iPhone, whilst the original code did. I have been told that it may be because there is no interval between each variable actualization. Could you give any advice how to rectify this pls. (My knowledge of javascript is pretty low!)
Code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script type="text/javascript" language="javascript">
function writePage( divname, text){
document.getElementById(divname).innerHTML=text;
}
function PachubeAPI(options) {
// Magic Incantation to enforce instantiation
if (! (this instanceof arguments.callee)) {
return new arguments.callee(arguments);
}
var self = this;
self.settings = {};
if (options != undefined) {
self.settings = {
api_key: options.api_key
};
}
self.settings.api_url = 'http://api.pachube.com/v2/';
}
PachubeAPI.prototype.datastreamGet = function(options) {
var self = this;
var url = {
base: self.settings.api_url
, resource: options.resource
, format: ''
, key: '?key=' + (options.api_key || self.settings.api_key)
, interval: ''
, start: ''
, end: ''
, per_page: '3'
};
if (options.interval != undefined) { url.interval = '&interval=' + options.interval }
if (options.start != undefined) { url.start = '&start=' + options.start.toISOString() }
if (options.end != undefined) { url.end = '&end=' + options.end.toISOString() }
if (options.per_page != undefined) { url.per_page = '&per_page=' + options.per_page }
$.ajax({
url: url.base + url.resource + url.format + url.key + url.interval + url.start + url.end + url.per_page
, success: options.callback
, dataType: 'jsonp'
});
};
</script><script type="text/javascript" language="javascript">
var pachubeAPI = new PachubeAPI({api_key:"KxiTYU9tWdwjUWuQErzozv_Uyvkdhv1bwj1SebtiWII"});
var interval = 20000;
var counter = interval;
var update = 1000;
var options = new Array();
var options2 = new Array();
var options3 = new Array();
options.resource = 'feeds/34843/datastreams/sd1';
options2.resource = 'feeds/34843/datastreams/sd2';
options3.resource = 'feeds/34843/datastreams/sd8';
options.callback = function done(data){
writePage("content_x","Solar: " + data.current_value + " W");
}
options2.callback = function done(data){
writePage("content_y", "Home: " + data.current_value + " W");
}
options3.callback = function done(data){
writePage("content_z", "Temp: " + data.current_value + " °C");
counter = interval;
}
function time_counter(){
var w = 200.0 * parseFloat(counter) / parseFloat(interval)
writePage("time_div_x", "<br />next update: " + counter/1000 + " seconds" + " <br /><img src='http://community.pachube.com/files/bar_0.png' width='"+w+"' height='10' />");
counter -= update;
if (counter == -50) counter = 0;
}
pachubeAPI.datastreamGet(options)
setInterval ( function() { pachubeAPI.datastreamGet(options) }, interval );
pachubeAPI.datastreamGet(options2)
setInterval ( function() { pachubeAPI.datastreamGet(options2) }, interval );
pachubeAPI.datastreamGet(options3)
setInterval ( function() { pachubeAPI.datastreamGet(options3) }, interval );
time_counter();
setInterval ( time_counter, update);
</script>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|