Skip to content

Replace node-libgpiod with gpiomon CLI – remove electron-rebuild#2

Merged
rkorell merged 1 commit intorkorell:mainfrom
KristjanESPERANTO:refactor
Mar 8, 2026
Merged

Replace node-libgpiod with gpiomon CLI – remove electron-rebuild#2
rkorell merged 1 commit intorkorell:mainfrom
KristjanESPERANTO:refactor

Conversation

@KristjanESPERANTO
Copy link
Contributor

Replaces the native node-libgpiod dependency with gpiomon (from the gpiod package) for PIR edge detection – the same approach used by MMM-Buttons.

Key benefits:

  • No more electron-rebuild after npm install
  • gpiomon is pre-installed on Raspberry Pi OS – no extra apt install needed for most users

Details:

  • pirLib.js: spawns gpiomon via child_process; auto-detects libgpiod version (1.x: gpiomon gpiochip0 4 / 2.x: gpiomon -c gpiochip0 -p 200ms 4); falls back to Python/gpiozero on failure
  • node_helper.js: added stop() cleanup; removed stale refs
  • package.json / package-lock.json: node-libgpiod and postinstall removed
  • README.md: updated accordingly

⚠️ Untested on real hardware – I don't currently have a PIR sensor available. node --check passes and the fallback chain is safe, but a hardware test would be advised before merging.

Let me know if anything isn't working 🙂

…n-rebuild

- Replace native node-libgpiod with gpiomon (gpiod CLI) for PIR edge detection
- Auto-detect libgpiod version (1.x vs 2.x) for correct gpiomon argument syntax
- Auto-fallback to Python/gpiozero if gpiomon is unavailable or crashes on startup
- Delete postinstall script (was: @electron/rebuild trigger)
- Remove node-libgpiod from optionalDependencies; package-lock regenerated (0 vulnerabilities)
- Add stop() cleanup method to node_helper
- Update README: installation, GPIO section, troubleshooting, changelog
@rkorell rkorell merged commit da98227 into rkorell:main Mar 8, 2026
rkorell added a commit that referenced this pull request Mar 8, 2026
Replace unconditional console.log calls with this.log() using
appropriate debug levels (simple/complex). Only errors remain
as console.error. With debug: "off" (default), pm2 logs are
now clean — no more updatePresence/updateScreen noise every
few seconds.

Discovered during PR #2 testing — thanks to KristjanESPERANTO.
@rkorell
Copy link
Owner

rkorell commented Mar 8, 2026

Dear Kristjan, @KristjanESPERANTO,

Thank you so much for this contribution! I've tested it on my Pi 5 (Debian Trixie, libgpiod 2.x)
and it works perfectly — gpiomon picks up the correct chip (gpiochip4), detects the libgpiod
version automatically, and both rising and falling edges are reported reliably.

This is a huge improvement over the previous approach. Eliminating node-libgpiod,
electron-rebuild, and the Python fallback in one clean refactoring makes the module so much easier
to install and maintain. The fact that gpiomon is pre-installed on every Pi is the key insight I
missed — sometimes fresh eyes see the obvious solution.

Your PR also helped me discover a pre-existing log spam issue: several console.log calls in
node_helper.js were firing unconditionally instead of going through the module's debug system.
Fixed that in 970a211 right after your merge. So thanks for that bonus find as well!

Warm regards,
Ralf

@KristjanESPERANTO
Copy link
Contributor Author

Hi Ralf 🙂 I'm glad it's working! I'm trying to get rid of electron-rebuild in the MagicMirror ecosystem, but I don't think that's possible for all modules, or at least it's very difficult.

@KristjanESPERANTO KristjanESPERANTO deleted the refactor branch March 9, 2026 07:40
@rkorell
Copy link
Owner

rkorell commented Mar 10, 2026

Dear Kristjan,
good initiative.
With 1.000nds of modules hard to reach.
Sorry from my side not to see this - will pay attention to this in future modules!
Thank you very much for your highly appreciated contribution!

BTW: I've tried to join the private group "module developers" but my ask is still "invitation pending" - are you aware who can approve this?

Thanks again!

Warmest regards,
Ralf

@KristjanESPERANTO
Copy link
Contributor Author

With 1.000nds of modules hard to reach.

The mass is not the problem at all. Of the more than 1000 modules, I know exactly which ones use electron-rebuild, and there are only a handful. But some packages cannot be replaced as “easily” as node-libgpiod. I have already successfully converted the simple cases. The rest may always have to remain with electron-rebuild.

are you aware who can approve this?

The core team. But there are no notifications about that. I just accepted your request to join 🙂

Thanks for your contributions! 😃


What I noticed in your module: you are using your own complex logger in node_helper. Is this an old legacy from the previous modules? You could use the logger from the core: const Log = require(‘logger’).

@rkorell
Copy link
Owner

rkorell commented Mar 10, 2026

this ist pretty COOL. Thank you SO much !

Regarding the core-logger: Good point, I looked into it — the core logger doesn't support file output (logFileName) or forwarding debug messages to the frontend, which we need.
But thanks for the hint, it's good to know it's there.

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

Successfully merging this pull request may close these issues.

2 participants