Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node-red crashed after connect Arduino and using this module #920

Closed
5 tasks
ghost opened this issue May 30, 2022 · 14 comments
Closed
5 tasks

Node-red crashed after connect Arduino and using this module #920

ghost opened this issue May 30, 2022 · 14 comments

Comments

@ghost
Copy link

ghost commented May 30, 2022

Which node are you reporting an issue on?

node-red-node-arduino

What are the steps to reproduce?

  1. Use Arduino Input
  2. Connect Arduino

What happens?

Node-red crashed with error: TypeError: cannot set properties of undefined (setting 'pinMode') at Firmata.pinMode (/root/.node-red/node_modules/firmata-io/lib/firmata.js:947:27)

What do you expect to happen?

Successful read from pin

Please tell us about your environment:

  • Node-RED version: 2.2.2
  • node.js version: v16.14.2
  • npm version: 8.1.3
  • Platform/OS: armv7/ Alpine Linux
  • Browser: Yandex Browser (on other PC with Windows)
@PizzaProgram
Copy link

I can confirm this bug.

To reproduce:

  • Set an invalid pin number and mode to: Analog

Node-red will crash.

Solution:

  1. The code should first check, if pin number is valid, before applying MODE
  2. Put a try..catch around pinMode change. (If setting the mode fails. Because it does sometimes!)

Probably other modes + invalid pin numbers should be checked too.

@dceejay
Copy link
Member

dceejay commented Feb 8, 2025

Much improved error handling now in v1.1.0
Reports invalid pin, and also port not found.

@dceejay dceejay closed this as completed Feb 8, 2025
@PizzaProgram
Copy link

@dceejay Great to hear!
Currently on npm only 1.0.0 is available. ( The one from 1 year, 3 months ago )

@PizzaProgram
Copy link

@dceejay Is there any way the new 1.1.0 version is getting uploaded to NPM?

@dceejay
Copy link
Member

dceejay commented Feb 23, 2025

It was uploaded 2 weeks ago

Image

@PizzaProgram
Copy link

You are right! Had to re-open NR window. Now it's visible.

Image

Will test it in the next few weeks.

@PizzaProgram
Copy link

Problem 1 :

at 35-arduino.js line 176 :

if (node.pin && !isNaN(node.pin) && node.pin >=0 && node.pin <= 20) {
...

20 is wrong! It should be a number queried from queryCapabilities() function, called by firmata-io.js once !
For example: RPi Pico with customFirmata has: TOTAL_PINS = 30 but not all digital.
See here: firmata/ConfigurableFirmata#115 (comment)

The Result is:

I can not use all the ports, including built-in LED pin=25, since I've upgraded to v1.1.

@PizzaProgram
Copy link

IMHO the whole naming of the module is wrong.
Instead of "Arduino" we should start a new, universal node, called:

node-red-node-firmata

@dceejay
Copy link
Member

dceejay commented Feb 24, 2025

Quick workaround is to patch that line for yourself...
But a Pull Request along the lines you suggest would be gratefully accepted.
(apologies I'm travelling for a bit so unable to access hardware to try/test anything for a while.)
PS - no this node won't be renamed. We could of course create a new one - subject to latest naming conventions of course

@PizzaProgram
Copy link

We could of course create a new one - subject to latest naming conventions of course

I agree ! We should. This should be the universal communication protocol that should be on the main menu of NR's website, compatible with all boards supporting firmata. (not limited to arduino, supporting extended capabilities, etc.)

But a Pull Request along the lines you suggest would be gratefully accepted.

I'm still trying to figure out, how to get values of the pins, previously set by the queryCapabilities() function.
So far I've found these:

  1. A way checking, if an analogue pin is valid: if (board.pins[board.analogPins[pin]]) { ... }
  2. Maybe this should be ok, for normal pins:
    if (node.pin && !isNaN(node.pin) && node.pin >=0 && node.pin <= node.board.pins.length) {

(PS: I "just" have to test it, but always getting confused about npm link and rebuild ... )

@dceejay
Copy link
Member

dceejay commented Feb 25, 2025

You shouldn't need either link or rebuild. If you have the code in a directory then from your .node-red user directory just npm install {path to directory} will install it. You only need to do that once. It will create the necessary links for you.

@PizzaProgram
Copy link

PizzaProgram commented Mar 10, 2025

Things that are fixed / added: v1.2

  1. max pin problem solved
  2. analogue pin checking! (NR crashed before)
  3. help added to html
  4. msg.payload = reset >> resets board (not yet working 👎 )
  5. added many else and constants to speed up execution
  6. renamed variables to be unique. Like: node -> brdNode, nodeIn, nodeOut
  7. added error handling for unhandled errors
  8. changed var to let everywhere

(Worked ca 30-40 hours so far on it.)
Please reopen this Issue, so others can see the progress too.
... too tired to create a Commit now. Here are the changed files:

node-red-node-arduino.zip

Needs to be solved (in v1.3)

  1. startup() function is running min. 2x !
    (sometimes continuously every 5000ms .. especially if there is min 1 node with wrong pin)
  2. Dual startup of wrong pin overrides the "wrong pin" status msg. "Connecting..." appears.
  3. There are 3 different startup() loops. Probably conflicting each other. Needs more investigation.
  4. [Flow Restart] kills communication. Board does not reset on close
  5. [Partial deploy] does not work.

subject to latest naming conventions of course

What are those? Any link to it?

@dceejay
Copy link
Member

dceejay commented Mar 10, 2025

No need for renaming unless you plan to release a new node. Great if we can fix this one with v1.2 (or 1.3 etc)

@PizzaProgram
Copy link

PizzaProgram commented Mar 10, 2025

No need for renaming

The goal would be to have a universal name that refers to all boards running Firmata, not just "Arduino".

There are many board types available:

So, the name "Arduino" is misleading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants