onoff icon indicating copy to clipboard operation
onoff copied to clipboard

fs error

Open sk337 opened this issue 1 year ago • 9 comments

node:internal/fs/utils:347
    throw err;
    ^

Error: EINVAL: invalid argument, write
    at Object.writeSync (node:fs:920:3)
    at Object.writeFileSync (node:fs:2208:26)
    at exportGpio (/home/pi/rpiapp/node_modules/onoff/onoff.js:18:8)
    at new Gpio (/home/pi/rpiapp/node_modules/onoff/onoff.js:172:36)
    at new s (/home/pi/rpiapp/dist/index.cjs:1:1479)
    at Object.<anonymous> (/home/pi/rpiapp/dist/index.cjs:1:2592)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12) {
  errno: -22,
  syscall: 'write',
  code: 'EINVAL'
}
pi@raspberrypi:~/rpiapp $ node -v
v16.20.2

i am using a Pi 2 model B

sk337 avatar Apr 30 '24 18:04 sk337

Same here with RPi5 Node v18.19.0

michaelpeterlee avatar Apr 30 '24 20:04 michaelpeterlee

Workaround: https://github.com/fivdi/onoff/issues/199

michaelpeterlee avatar Apr 30 '24 20:04 michaelpeterlee

It seems that Raspberry OS kernel addresses GPIO pins yet by another numbering scheme.

cat /sys/kernel/debug/gpio gpio-512 (ID_SDA ) gpio-513 (ID_SCL ) gpio-514 (GPIO2 ) gpio-515 (GPIO3 ) gpio-516 (GPIO4 ) gpio-517 (GPIO5 ) gpio-518 (GPIO6 ) gpio-519 (GPIO7 ) gpio-520 (GPIO8 ) gpio-521 (GPIO9 ) gpio-522 (GPIO10 ) gpio-523 (GPIO11 ) gpio-524 (GPIO12 ) gpio-525 (GPIO13 ) gpio-526 (GPIO14 ) gpio-527 (GPIO15 ) gpio-528 (GPIO16 ) gpio-529 (GPIO17 ) gpio-530 (GPIO18 ) gpio-531 (GPIO19 ) gpio-532 (GPIO20 ) gpio-533 (GPIO21 ) gpio-534 (GPIO22 ) gpio-535 (GPIO23 ) gpio-536 (GPIO24 ) gpio-537 (GPIO25 ) gpio-538 (GPIO26 ) gpio-539 (GPIO27 )

You must use the number after gpio-[number]

alex-reach avatar May 01 '24 16:05 alex-reach

It seems that Raspberry OS kernel addresses GPIO pins yet by another numbering scheme.

cat /sys/kernel/debug/gpio gpio-512 (ID_SDA ) gpio-513 (ID_SCL ) gpio-514 (GPIO2 ) gpio-515 (GPIO3 ) gpio-516 (GPIO4 ) gpio-517 (GPIO5 ) gpio-518 (GPIO6 ) gpio-519 (GPIO7 ) gpio-520 (GPIO8 ) gpio-521 (GPIO9 ) gpio-522 (GPIO10 ) gpio-523 (GPIO11 ) gpio-524 (GPIO12 ) gpio-525 (GPIO13 ) gpio-526 (GPIO14 ) gpio-527 (GPIO15 ) gpio-528 (GPIO16 ) gpio-529 (GPIO17 ) gpio-530 (GPIO18 ) gpio-531 (GPIO19 ) gpio-532 (GPIO20 ) gpio-533 (GPIO21 ) gpio-534 (GPIO22 ) gpio-535 (GPIO23 ) gpio-536 (GPIO24 ) gpio-537 (GPIO25 ) gpio-538 (GPIO26 ) gpio-539 (GPIO27 )

You must use the number after gpio-[number]

ok looks just to be offset by 512

sk337 avatar May 01 '24 18:05 sk337

Looks like every GPIO library when run on new kernel will have this issue. At the same time seems like the whole community is perplexed what actually happened. Did you manage to find any official explanation how to prepare for this change and why it was introduced?

szwacz avatar May 14 '24 23:05 szwacz

On Raspbian Bullseye it works, on Raspbian Bookworm it's broken.

SamDecrock avatar May 24 '24 09:05 SamDecrock

The library needs to look for the gpiochip* file and add the * value to every pin. on mine its gpiochip512 so for pin 2 i believe it would be 514

nwpray avatar Jun 27 '24 01:06 nwpray

I opened a PR to lookup the base address and add that automatically to the address you pass https://github.com/fivdi/onoff/pull/204

nwpray avatar Jun 27 '24 02:06 nwpray