BCS API Help

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

BCS API Help

Post by AndrewsBrewing » Tue Feb 12, 2019 10:47 am

I have successfully requested a timer value using C++ and an ESP8266 using the attached sketch
ESP8266_HTTP_GET_Test.zip
(829 Bytes) Downloaded 2 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: 202
Joined: Sat Mar 27, 2010 3:59 am
Bot?: No
Location: Vancouver, BC or NST, Thailand
Contact:

Re: BCS API Help

Post by bbrally » Sat Feb 16, 2019 5:49 am

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);
}
Move, copy, clear processes/states: http://manipulator.from-ca.com/
Perform coefficient mods: http://calculator.from-ca.com/
HMI Builder: http://bbrally.altervista.org/GUI/index.html
HMI Builder latest ver: http://bbrally.altervista.org/guibeta/index.html

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

Re: BCS API Help

Post by AndrewsBrewing » Sun Feb 17, 2019 2:43 am

Thank you very much, bbrally. Worked like a charm

Eric

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

Re: BCS API Help

Post by AndrewsBrewing » Mon Feb 18, 2019 4:21 am

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: 202
Joined: Sat Mar 27, 2010 3:59 am
Bot?: No
Location: Vancouver, BC or NST, Thailand
Contact:

Re: BCS API Help

Post by bbrally » Mon Feb 18, 2019 8:28 am

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.
Move, copy, clear processes/states: http://manipulator.from-ca.com/
Perform coefficient mods: http://calculator.from-ca.com/
HMI Builder: http://bbrally.altervista.org/GUI/index.html
HMI Builder latest ver: http://bbrally.altervista.org/guibeta/index.html

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

Re: BCS API Help

Post by AndrewsBrewing » Mon Feb 18, 2019 8:44 am

Brilliant! Works, thank you!!!

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests