Read the statement by Michael Teeuw here.
Editing files outside of MM
-
@aareben problem is files in /sys, /etc, /opt
are all protected. so you would have to be in root user authority, which is not really possible inside mm.if your userid was in the sudoers group, you could exec sudo node scriptname.js, outside/under mm to run the script without requiring a prompt
-
@sdetweil that makes sense, my module is just a way to control the brightness of the official ras pi display. all the ones out there do it by sunrise and sunset and I want to be able to do it from on-screen buttons. I was planning on using this, https://github.com/tosti007/MMM-TouchNavigation for the buttons and just using notifications to control the module but this seems to be getting complicated. I just want to be able to edit the number within /sys/class/backlight/rpi_backlight/brightness. I was using the info in here https://www.raspberrypi.org/forums/viewtopic.php?t=214086 to figure it out. Do you have any suggestions for how to do it
-
@aareben try use sudo echo to push the number into the file.
so, to do the sudo echo is the same work as doing sudo node scriptname.
you would use the process.spawn library call
user has to be in the sudoers file or sudo group to have this work without prompt
-
@sdetweil how would i get sudo echo into my MMM-Brightness.js? this Is my module rn. Ik its probably very wrong but i don’t actually know javascript so…
Module.register("MMM-Brightness", { defaults: { startingBrightness: 130, jump: 10, path_to_backlight: '/sys/class/backlight/rpi_backlight/brightness', }, start: function () { self = this; var brightness = this.config.startingBrightness; }, notificationReceived: function() { if (notification === 'BRIGHTNESS_UP') { var brightness = brightness-this.config.jump;} if (notification === 'BRIGHTNESS_DOWN') { var brightness = brightness+this.config.jump;} }, loaded: function(callback) { this.finishLoading(); Log.log(this.name + ' is loaded!'); callback(); } })
-
@aareben again u can’t do it from the modulename.js as this runs inside the browser, you must use the node_helper to execute commands, call databases, access pins on pi board…
the browsers restrict all these things for security against hackers reading files, running programs to steal your info, etc
-
@aareben if u haven’t made any progress, see my sample module, which provides a node_helper and uses socket notifications for communications with the modulename.js