User rights for Phidget
Posted: Sun Feb 19, 2023 11:19 am
Hi!
I can't get my web page to connect to the Phidget. I'm guessing because of user rights somehow. What user rights does the web server have? Do I need to do something special to let it access Phidgets?
And that code in connectPhidgets, what does it do? Is it needed at all?
When I look at this web page, it shows that the onAttach is never called. I can see the Phidghet with phidget22admin, so it _is_ there and working!
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test DigitalOutput</title>
<script src="sha256.min.js"></script>
<script src="phidget22.min.js"></script>
</head>
<script>
const phidgetSerialNumber = 31404;
var Output0;
function connectPhidgets() {
var local = location.hostname; //get host location
var conn = new phidget22.Connection(8080, local);
conn.connect().then(runExample);
}
function onDigitalOutput_Attach(self) {
document.getElementById("mainLabel").innerHTML = "Phidgets - Attached";
};
function initDigitalOutput() {
Output0 = new phidget22.DigitalOutput();
Output0.setDeviceSerialNumber(phidgetSerialNumber);
Output0.setChannel(0);
Output0.onAttach = onDigitalOutput_Attach;
Output0.open(5000);
};
function runExample() {
initDigitalOutput(0);
Output0.setState(true);
document.getElementById("dataLabel").innerHTML = "Phidgets - Set " + Output0.getAttached();
};
</script>
<body onload="connectPhidgets()">
<div>
<h1 id="mainLabel">No Phidget attached</h1>
<h2 id="dataLabel">?</h2>
</div>
</body>
</html>
I can't get my web page to connect to the Phidget. I'm guessing because of user rights somehow. What user rights does the web server have? Do I need to do something special to let it access Phidgets?
And that code in connectPhidgets, what does it do? Is it needed at all?
When I look at this web page, it shows that the onAttach is never called. I can see the Phidghet with phidget22admin, so it _is_ there and working!
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test DigitalOutput</title>
<script src="sha256.min.js"></script>
<script src="phidget22.min.js"></script>
</head>
<script>
const phidgetSerialNumber = 31404;
var Output0;
function connectPhidgets() {
var local = location.hostname; //get host location
var conn = new phidget22.Connection(8080, local);
conn.connect().then(runExample);
}
function onDigitalOutput_Attach(self) {
document.getElementById("mainLabel").innerHTML = "Phidgets - Attached";
};
function initDigitalOutput() {
Output0 = new phidget22.DigitalOutput();
Output0.setDeviceSerialNumber(phidgetSerialNumber);
Output0.setChannel(0);
Output0.onAttach = onDigitalOutput_Attach;
Output0.open(5000);
};
function runExample() {
initDigitalOutput(0);
Output0.setState(true);
document.getElementById("dataLabel").innerHTML = "Phidgets - Set " + Output0.getAttached();
};
</script>
<body onload="connectPhidgets()">
<div>
<h1 id="mainLabel">No Phidget attached</h1>
<h2 id="dataLabel">?</h2>
</div>
</body>
</html>