Can somebody please put me out of my misery on a JSON command?

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 setting DutyCycle to 1.0, and setting the State to FALSE is the same as setting a DutyCycle 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

Forewarning: I have no idea what this phidgets thing is.

Have you installed that set of nodes?

there is a Digital Output node (and a whold bunch of other nodes too) - have you tried firing a value into this node?

That's exactlyt what I'm trying to do. And I have done all that. The input node is for reading relays and switches, btw. The output node sends 12V- to the selected output. And the connection is working. But the output node needs the correct messages sent into it to do it's work. I'm missing a part of the correct syntax for the command itself.

unfortunately, the built in help is pretty terrible and there is no link to the repository (so cannot look at the source to help you out)

You might get some luck contacting the author

If you have any questions, bug reports, or recommendations for this module, please send them to mparadis@phidgets.com.

Believe me, I have tried. Either they don't understand what I need, or they are of the opinion that if I want to use this I should know how to... I have spent weeks on getting this to work!

Try use an inject node to a change node. Select json and click the little button to the right of the input box. In the window that opens up copy this in and try.

Topic: setState
Payload: {
    "state": true
}

On mobile so can't try it out.

@kevins No, I'm afraid not. But I have found a workaround that works very well, I got help to make a Phyton script that's called from Node-RED and opens the nodes. OK, somebody made it for me, I didn't do much myself... :smiley:

That isn't valid JSON.

In the change node, on the row for payload set it to JSON then paste in

{
    "state": true
}

As for topic, leave that as string& your in what you need.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.