BCS API Help

Suggestions, Problems, Availability, etc. Everything is up for discussion.
Post Reply
User avatar
AndrewsBrewing
Posts: 35
Joined: Sat Feb 14, 2015 10:06 am
Bot?: No
Contact:

BCS API Help

Post by AndrewsBrewing »

I have successfully requested a timer value using C++ and an ESP8266 using the attached sketch
ESP8266_HTTP_GET_Test.zip
(829 Bytes) Downloaded 291 times
.

However I am not sure how to make that GET call from a web page using JScript or JQuery. What I want to do is have a page setup on a Windows machine on the same network that displays, at first, the timer value as it counts down without refreshing the page.

Does anyone have a working copy of what I'm trying to do?

Eric
User avatar
bbrally
Posts: 210
Joined: Sat Mar 27, 2010 3:59 am
Bot?: No
Location: Vancouver, BC
Contact:

Re: BCS API Help

Post by bbrally »

Here's some code I wrote long ago to help someone else out who needed to get temps. There are lots of ways to do this, this only one:

Code: Select all

// run our javascript once the page has loaded
$(document).ready(function () {
	getBCSTempWithJqueryGet('http://192.168.1.218/');
});

function getBCSTempWithJqueryGet(bcsAddress) {
	//create a timer that will fire every 1000ms until the browser window closes.
	setInterval(function () {
		//use the Jquery "get" method to get temp values, then when temps have been acquired, update each temp
		$.get(bcsAddress + '/api/temp', function (temp) {
			$('#temp0').html(temp[0]/10);
			$('#temp1').html(temp[1]/10);
			$('#temp2').html(temp[2]/10);
			$('#temp3').html(temp[3]/10);
			$('#temp4').html(temp[4]/10);
			$('#temp5').html(temp[5]/10);
			$('#temp6').html(temp[6]/10);
			$('#temp7').html(temp[7]/10);
		}).fail(function () {
			console.log('fail');
		});
	}, 1000);
}
User avatar
AndrewsBrewing
Posts: 35
Joined: Sat Feb 14, 2015 10:06 am
Bot?: No
Contact:

Re: BCS API Help

Post by AndrewsBrewing »

Thank you very much, bbrally. Worked like a charm

Eric
User avatar
AndrewsBrewing
Posts: 35
Joined: Sat Feb 14, 2015 10:06 am
Bot?: No
Contact:

Re: BCS API Help

Post by AndrewsBrewing »

bbrally, you don't happen to have jscript that gets timer0 on process4 do you?

I have this but I'm seeing that it is more complicated than the temp get.

<script>
// run our javascript once the page has loaded
$(document).ready(function () {
getBCSTimerWithJqueryGet('http://192.168.1.234');
});

function getBCSTimerWithJqueryGet(bcsAddress) {
//create a timer that will fire every 1000ms until the browser window closes.
setInterval(function () {
//use the Jquery "get" method to get temp values, then when temps have been acquired, update each temp
$.get(bcsAddress + '/api/process/4/timer', function (value) {
$('#timer0').html(value[0]);
}).fail(function () {
console.log('fail');
});
}, 1000);
}
</script>
User avatar
bbrally
Posts: 210
Joined: Sat Mar 27, 2010 3:59 am
Bot?: No
Location: Vancouver, BC
Contact:

Re: BCS API Help

Post by bbrally »

Try entering "http://192.168.1.234/api/process/4/timer" into your browser, this will allow you to see what the BCS is giving you for values. When I do this it returns an array of objects, not just the timer values.

Try this:

Code: Select all

$('#timer0').html(value[0].value);
Doing this would return the name of that timer:

Code: Select all

$('#timer0').html(value[0].name);

The API documentation can be found here : http://embeddedcc.github.io/api-docs/
But it isn't always correct as can be seen for getting the timer values.
User avatar
AndrewsBrewing
Posts: 35
Joined: Sat Feb 14, 2015 10:06 am
Bot?: No
Contact:

Re: BCS API Help

Post by AndrewsBrewing »

Brilliant! Works, thank you!!!
Post Reply