Page 1 of 1

BCS API Help

Posted: Tue Feb 12, 2019 10:47 am
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 421 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

Re: BCS API Help

Posted: Sat Feb 16, 2019 5:49 am
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);
}

Re: BCS API Help

Posted: Sun Feb 17, 2019 2:43 am
by AndrewsBrewing
Thank you very much, bbrally. Worked like a charm

Eric

Re: BCS API Help

Posted: Mon Feb 18, 2019 4:21 am
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>

Re: BCS API Help

Posted: Mon Feb 18, 2019 8:28 am
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.

Re: BCS API Help

Posted: Mon Feb 18, 2019 8:44 am
by AndrewsBrewing
Brilliant! Works, thank you!!!