MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Editing files outside of MM

    Scheduled Pinned Locked Moved Development
    10 Posts 2 Posters 1.2k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      aareben
      last edited by

      @sdetweil so I would probably be using fs. I’m trying to edit a file on the in the /sys/class. so with research, it would probably be:

      fs.writeFile(/sys/class/___.txt, '18', function (err) { 
                              if (err)
              console.log(err);
      });)
      

      this was taken from a website so I assume its right. I’ve been using vnc viewer to do everything from the pi but I will look into those other file managers. Thanks so much

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @aareben
        last edited by

        @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

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        A 1 Reply Last reply Reply Quote 0
        • A Offline
          aareben @sdetweil
          last edited by

          @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

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil @aareben
            last edited by

            @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

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            A 1 Reply Last reply Reply Quote 0
            • A Offline
              aareben @sdetweil
              last edited by

              @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();
              }
              })
              S 1 Reply Last reply Reply Quote 0
              • S Offline
                sdetweil @aareben
                last edited by sdetweil

                @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

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                S 1 Reply Last reply Reply Quote 0
                • S Offline
                  sdetweil @sdetweil
                  last edited by

                  @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

                  https://github.com/sdetweil/SampleModule

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Enjoying MagicMirror? Please consider a donation!
                  MagicMirror created by Michael Teeuw.
                  Forum managed by Sam, technical setup by Karsten.
                  This forum is using NodeBB as its core | Contributors
                  Contact | Privacy Policy