I'm trying to do a simple thing: Open and close a digital output on a Phidget board. The command is setState(state) and this is what the API says about it:
setState(state)
The State
will dictate whether the output is constantly high (TRUE) or low (FALSE).
- This will override any
DutyCycle
that may have been set on the channel. - Setting the
State
to TRUE is the same as settingDutyCycle
to 1.0, and setting theState
to FALSE is the same as setting aDutyCycle
of 0.0.
Parameters:
State(type: Boolean):The state value
Returns:
A Promise. Errors reject promise with a PhidgetError. Success resolves promise with the following:
No value is returned
Example:
// NOTE: This shows importing phidget22 in Node.JS. In-Browser JavaScript import is different
var phidget22 = require("phidget22");
var conn = new phidget22.Connection();
conn.connect().then(function() {
var ch = new phidget22.DigitalOutput();
ch.open(2500).then(function() {
ch.setState(true).catch(function (err) {
console.error("setState failed:", err);
});
}).catch(function (err) {
console.error("Error during open:", err);
});
}).catch(function (err) {
console.error("Error during connect:", err);
});
But I just can't get it to work, probably because I suck at programming. I can do simple Python and a bit more advanced LUA, but no JSON. I have tried to inject with this in a function node:
msg.topic = 'setState';
msg.payload = true;
return msg;
And I've tried to put setState as a string in the inject node and true as the JSON payload, but both of these gives me the same answer: "missing value" Can somebody please have a short look at this (I'm assuming it's easy for somebody who actually knows what they're doing!) and tell me what to do?
Here's the API: API Documentation - Phidgets
And here's a Readme for the node: node-red-contrib-phidget22 - npm