I have successfully requested a timer value using C++ and an ESP8266 using the attached sketch
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
.BCS API Help
- AndrewsBrewing
- Posts: 35
- Joined: Sat Feb 14, 2015 10:06 am
- Bot?: No
- Contact:
Re: BCS API Help
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 proc/states: http://manipulator.from-ca.com/
Perform coeff. mods: http://calculator.from-ca.com/
HMI latest ver: http://bbrally.altervista.org/guibeta/i ... r=01042020
Perform coeff. mods: http://calculator.from-ca.com/
HMI latest ver: http://bbrally.altervista.org/guibeta/i ... r=01042020
- AndrewsBrewing
- Posts: 35
- Joined: Sat Feb 14, 2015 10:06 am
- Bot?: No
- Contact:
Re: BCS API Help
Thank you very much, bbrally. Worked like a charm
Eric
Eric
- AndrewsBrewing
- Posts: 35
- Joined: Sat Feb 14, 2015 10:06 am
- Bot?: No
- Contact:
Re: BCS API Help
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>
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
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:
Doing this would return the name of that timer:
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.
Try this:
Code: Select all
$('#timer0').html(value[0].value);
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 proc/states: http://manipulator.from-ca.com/
Perform coeff. mods: http://calculator.from-ca.com/
HMI latest ver: http://bbrally.altervista.org/guibeta/i ... r=01042020
Perform coeff. mods: http://calculator.from-ca.com/
HMI latest ver: http://bbrally.altervista.org/guibeta/i ... r=01042020
- AndrewsBrewing
- Posts: 35
- Joined: Sat Feb 14, 2015 10:06 am
- Bot?: No
- Contact:
Re: BCS API Help
Brilliant! Works, thank you!!!