Phidget22 Node-RED Module Released

Supporting Browser-based Javascript and Node.js
User avatar
mparadis
Site Admin
Posts: 863
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Phidget22 Node-RED Module Released

Postby mparadis » Fri Jan 24, 2020 1:42 pm

We've just released a Node-RED module for Phidget22, node-red-contrib-phidget22, which you can find by searching for "phidget" in your Node-RED palette manager. You can view the readme to see how we've implemented the library.

All device types are supported in this module, although most "get" functions have not yet been implemented since most applications rely on events instead of polling. We plan on adding these in a later release for completeness' sake.

If you have any questions, comments, or recommendations for this module, please reply here or send an email to mparadis@phidgets.com.

Mastiff
Phidgetly
Posts: 21
Joined: Fri Sep 11, 2020 9:20 am
Contact:

Re: Phidget22 Node-RED Module Released

Postby Mastiff » Fri Dec 04, 2020 6:24 am

I have tried for weeks to get this to work, and I tried the forum too, but obvoiusly in the wronge place. Only now do I find this thread, I was doing my posting under Linux. :oops: So I have gotten as far as to connect to the server, but I can't do the simple task I want to do. I just want to open and close digital outputs from Node-RED. So first I created a connect node and hooked that up to a debug node. Here's what I have in my log when I start up:

Code: Select all

Attempting to Connect to Server (127.0.0.1:5661)
{"topic":"Disconnect","payload":{},"_msgid":"c60533fc.7b07e"}
Connect Success (127.0.0.1:5661)
{"topic":"Connect","payload":{},"_msgid":"43beec8b.978954"}
{"topic":"Attach","payload":{},"_msgid":"247fe19b.03ad5e"}


That sounds pretty promising. Then I created an inject node and a digital input node, trying to use the API for digital outputs, but I have obviously not understood that. Info in the inject node:

Code: Select all

Topic:setState(true)
Payload:0


And in the digital output node:

Code: Select all

LED Forward Voltage: volts_1_7
LED Current Limit: 0.02
Channel: 0 (I assume this is the port to open, but I'm not sure, so I set it to 0 like the port I'm trying to open)
Serial #: 15593
Using a VINT Port in DigitalOutput mode? (Tried both on and off)


But all I get is "Unsupported message topic: setState(true)" I have also tried with just "setState" as topic in the inject node and "true" as payload, but that gives me "missing value". I'm at my wit's end, I'm used to Node-RED nodes being a bit more self-explanatory. What is the correct way of opening and closing ports with Node-RED?

Edit: After I installed the Java Script excamples to have the webserver interface on, I suddenly get this in Node-RED:

Code: Select all

Open failed:PhidgetError: Open timed out


But the Phidget is connected to Phidgetserver, and it's all working because I can still use the Python example script and the web page to open and close the digital output.

User avatar
mparadis
Site Admin
Posts: 863
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Phidget22 Node-RED Module Released

Postby mparadis » Fri Dec 04, 2020 2:09 pm

(I'm assuming you're using the digital outputs on the 1032, based on the forward voltage you're trying to set. If you're using the HUB0000's ports, or a VINT device other than the LED1000, setting LED forward voltage or current limit won't do anything)

Here's some answers to your questions:

- Channel: This refers to which physical port on the board you're trying to control
- VINT Port in DigitalOutput mode: Only check this box if you're using a HUB0000, HUB5000 or SBC3003 and you're using the VINT port itself as a digital output (not an attached digitalOutput device plugged into that port)
- Unsupported message: You can't just set the payload to "0" or "true", the payload must be a JSON object with members whose names match the expected javascript parameters. You can find an example in the "Methods" section of the readme on npm linked in the original post above. (Why did we do it this way? Because some methods have multiple parameters and we wanted to be consistent even with single-parameter methods.)
- Open timed out: If open is suddenly timing out, it might be because the channel you're trying to open is currently open in another program or process (in this case the python example perhaps)

I hope this helps, sorry you've had a rough go with Phidgets in Node-RED. I wanted to make it more user-friendly (especially in the node configurations), but porting over from a library that didn't have flow-based programming in mind makes it a bit messy.

Mastiff
Phidgetly
Posts: 21
Joined: Fri Sep 11, 2020 9:20 am
Contact:

Re: Phidget22 Node-RED Module Released

Postby Mastiff » Fri Dec 04, 2020 3:12 pm

Thanks for answering! I'm using a 0/16/16, version 601. But I see. So I think I may have gotten it right by using "setstate" as a topic and then true as a JSON payload. Now I only get the timeout error on startup of Node-RED, and no errors in the syntax. I get "setState failed:PhidgetError: Device not Attached" on the firing of the command, but I guess that's related to the timeout. The reason for the "open timed out" can't be the script, I have tried to reboot and not run that script. I also tried to deactivate the www part of the server in case that was it, but nothing happened there eiher. I keep getting "Open failed:PhidgetError: Open timed out". Is there anything else I can try?

User avatar
mparadis
Site Admin
Posts: 863
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Phidget22 Node-RED Module Released

Postby mparadis » Fri Dec 04, 2020 3:37 pm

When you wire the output of the "connect" node to the console, does it say the connection was successful, or failed?

If connect succeeds but open fails, that channel is either open somewhere else, or the channel can't be found on that server based on the parameters you've supplied in the DigitalOutput node. I noticed your 1012 has a five-digit serial number- can you confirm that this is the serial number that shows when you open it in the Phidget Control Panel? Usually it's 6 digits but maybe if it's an older 1012 it would be 5. You can also leave the serial number field blank and the node will just try to match any channel 0 digital output regardless of serial number.

Mastiff
Phidgetly
Posts: 21
Joined: Fri Sep 11, 2020 9:20 am
Contact:

Re: Phidget22 Node-RED Module Released

Postby Mastiff » Fri Dec 04, 2020 5:00 pm

Found it! :mrgreen: During my messing around I had set HUB port wrong, to 2. But 0 worked, so "DigitalOutput Opened (SN:15593, Ch:1)"1 I am connected. But now it says "missing value" with the same settings as above. Any idea what value that may be?

Mastiff
Phidgetly
Posts: 21
Joined: Fri Sep 11, 2020 9:20 am
Contact:

Re: Phidget22 Node-RED Module Released

Postby Mastiff » Mon Dec 07, 2020 1:57 am

Fixed. 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... :mrgreen:

User avatar
mparadis
Site Admin
Posts: 863
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Phidget22 Node-RED Module Released

Postby mparadis » Tue Dec 08, 2020 9:12 am

Missing value usually means there's still an issue with the messages you're construction for the phidget nodes. Make sure the payload for each is a json object where the name of each parameter is the name listed for each parameter in our javascript API.

lingvo
Phidgetsian
Posts: 11
Joined: Fri Jul 16, 2021 8:43 am
Contact:

Re: Phidget22 Node-RED Module Released

Postby lingvo » Fri Jul 16, 2021 8:47 am

Hi Guys

Sorry, new here. I would like to automate measurement of ORP and PH in my pool using couple of ADP1000 and HUB5000. I wanted to have MQTT interface to connect to my Node-Red controller, but see that you have direct support for it.

So can you confirm that my config will work with Node-RED?

User avatar
mparadis
Site Admin
Posts: 863
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Phidget22 Node-RED Module Released

Postby mparadis » Fri Jul 16, 2021 9:24 am

The Phidgets node-red package is fully implemented, so it does support the HUB5000 and ADP1000.


Return to “Javascript”

Who is online

Users browsing this forum: No registered users and 1 guest