cosm library test
Cosm has its own library, going to try again using it.
by spuder
HTML
<script src="http://d23cj0cdvyoxg0.cloudfront.net/cosmjs-1.0.0.min.js"></script>
<body>
<div class="datastream-value"></div>
</body>
JavaScript
$(document).ready(function () {
cosm.setKey("-Ux_JTwgP-8pje981acMa5811-mSAKxpR3VRUHRFQ3RBUT0g");
//cosm.feed.get( "504", function( data ) {
// console.log( data.title ); // Logs the feed title
//});
cosm.datastream.subscribe( "120687", "sensor_reading", function( event, data ) {
console.log( data.current_value ); // Logs value changes in realtime
$('.datastream-value').replaceWith(data.current_value);
});
//cosm.feed.get( "120687", function( data ) {
//console.log( data.sensor_reading ); // Logs the feed title
//$('.datastream-value').cosm('live', {
// feed: 120687,
// datastream: 'sensor_reading'
//});
// });
// getJson();
});
//hurl.it is able to use the headers no problem
// http://www.hurl.it/hurls/75502ac851ebc7e195aa26c62718f58fecc4a341/47ad3b36639001c3a663e716ccdf3840352645f1
function getJson() {
$.ajax({
type: 'GET',
url: 'https://api.cosm.com/v2/feeds/120687/datastreams/sensor_reading',
headers: {
"X-ApiKey": "-Ux_JTwgP-8pje981acMa5811-mSAKxpR3VRUHRFQ3RBUT0g"
},
//headers:{"Accept": "*/*",
// "X-ApiKey": "-Ux_JTwgP-8pje981acMa5811-mSAKxpR3VRUHRFQ3RBUT0g"},
//headers:{"-Ux_JTwgP-8pje981acMa5811-mSAKxpR3VRUHRFQ3RBUT0g"},
success: function (feed) {
var currentSensorValue = feed.current_value;
console.log(currentSensorValue);
},
dataType: 'jsonp'
});
}