Read the statement by Michael Teeuw here.
when to use init , start, loaded of node helper
-
@kayakbabe I agree w @MMRIZE , probably never user init or loaded.
think of start() as where u might do one time things before real work begins… like initialize hardware, or some such
-
@sdetweil if start is for one time things, where would I do work that must be repeated endlessly like a sensor or button that needs to be constantly checked.
If I have to init a node package that my module uses, I do that in start? so setting up in module variables is done in start?
-
@kayakbabe in start you would create a timed cycle using setInterval, or a timer using setTimeout.
basically, node help gets called once by mm
and then is dependent on notifications for it’s work process. it’s JOB is to help it’s module, by doing things the module can’t do directly
access hardware, read files, call libraries that might do those things (accessed via require())
-
yes you could init a library in start. but, you might not have the info you need, that would/should have been placed in config on the module in config.js
that info was passed to the modulename.js.
you will see that modules that use a node helper send a notification early on to pass the config object to the helper. this happens effectively light years after start is called (maybe seconds)
so generally start isn’t used much, as the helper is dependent on the config info usually stuff like
gpio pins, file names, urls, usernames and passwords… cycle time limits… -
@kayakbabe think of the helper as a web service provider
gets a request (notification)
process
send response(notification) -
@sdetweil your explanations helped a lot. I debugged using a timer in the node_helper to fake detecting different types of button press and my module will send magic mirror notifications. (So, if I can detect the actual physical events I’m pretty sure my script will work.
I think it’s the node package I’m trying to use that is the problem.
I even got so far as to figure out that a dependency of the package I want to used wasn’t compiled for Node version 16. which i what I’ve got running on my Mirror pi. I figured out it is c++ and even figured out how to recompile it with node-gyp and make. so now I do not get any errors in the pm2 error log. but now instead of a black screen electron, I don’t get electron opening a window at all. I check the PM2 logs. There are no errors in the mm-error log. It is blank.
However, the pm2 mm-out log is being added to over and over, so electron and MagicMirror are running. and the error keeps being repeated in the mm-out log.The error which i’ve googled and gotten no working result for is:
ERROR Error: Cannot find module 'bindings'.
Yet there is a bindings folder in the node_helper folder.
Is there a way to find out what path is being used to try to find “bindings”.Or maybe the package I’m trying to use just is too much of a mess to keep screwing with. It sure seems like it would be super useful. I wanted to add a few physcial intermittant buttons and be able to assign multiple uses to them. Funny thing is… it works great when I run the test script in the command line using node.
https://github.com/bnielsen1965/rpi-gpio-buttons
By the way, this learning nodejs and module development is not all that easy.
-
@kayakbabe DRAT! I just crushed my microSD with my wheelchair. It is definitely time for bed.