MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    1. Home
    2. autonomus
    A
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 7
    • Best 0
    • Controversial 0
    • Groups 0

    autonomus

    @autonomus

    0
    Reputation
    417
    Profile views
    7
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    autonomus Unfollow Follow

    Latest posts made by autonomus

    • RE: Multiline text output inside exec block is displayed as 1 line

      @sdetweil Thanks for the help!
      You made me realise that I need to return HTML syntax. This works as expected:
      line 1 text < br>
      line 2 text < br>
      …

      For reference, I was building a table for my data.
      Instead of multi lines with tabs, I switched to HTML tables.

      posted in Development
      A
      autonomus
    • Multiline text output inside exec block is displayed as 1 line

      Hello,

      I have a very simple module that executes a linux “cat” command on a file every N seconds.
      It works as expected except the line breaks in the file are ignored. All lines are displayed as 1 single line.

      This is how I call the cat command inside node_helper.js:
      var NodeHelper = require(‘node_helper’);
      const exec = require(‘child_process’).exec;

      module.exports = NodeHelper.create({

      readfile: function () {
      exec("cat /path/to/file/out.txt", (error, stdout, stderr) => {
      	if (error) {
      		console.error(`exec error: ${error}`);
      		return;
      	}
          	this.sendSocketNotification('UPDATE', stdout);
      });
      },
      
      socketNotificationReceived: function(notification, payload) {
      	if (notification === 'TICK') {
      	this.readfile();
      }
      },
      

      });

      Inside the module class, this is how I handle the update coming from socketNotificationReceived:

      	socketNotificationReceived: function(notification, payload) {
      	    if (notification === 'UPDATE') {
      	this.config.text = payload;
      	this.updateDom()
          }
      	},
      

      The reason I took this approach is I have absolutely no JS experience whatsoever, so I’m preparing the text file using a bash script and then use my MMM to display the result. (I moved the processing outside JS domain)

      Is it possible to use “cat” and display multiline?
      Or should I use a completely different approach e.g. reading the file inside JS line by line and displaying the result. If this is the correct approach then please point me to some examples.

      Thanks in advance

      posted in Development
      A
      autonomus
    • RE: run Linux command from a mm2 module

      @strawberry-3-141 , thanks for the info. I’m starting to understand how this would work, but I can’t get it to run yet. Can you please take a quick look at my code to point me to what I’m doing wrong.

      The missing piece is how to get the output from the Linux command and then pass it to the screen. How do I pass text to the Dom?

      Also is my schedule update the right way to make the module rerun the command and refresh the screen?

      //MMM-pichan.js
      Module.register(‘MMM-pichan’,{

      requiresVersion: "2.1.0",
      
      start: function() {
      Log.log('Starting module: ' + this.name);
      },
      

      });

      //node__helper.js
      var NodeHelper = require(‘node_helper’);
      const exec = require(‘child_process’).exec;

      module.exports = NodeHelper.create({

      start: function () {
      this.scheduleUpdate(0);
      },
      
      readfile: function () {
      //exec("cat /home/pi/Documents/PiChanServer/pichan_status.log", null);
      exec("cat /home/pi/Documents/PiChanServer/pichan_status.log", (error, stdout, stderr) => {
      	if (error) {
      		console.error(`exec error: ${error}`);
      		return;
      	}
      	console.log(`stdout: ${stdout}`);
      });
      },
      
      scheduleUpdate: function(delay, fn) {
      var nextLoad = 3000;
      if (typeof delay !== 'undefined' && delay >= 0) {
          nextLoad = delay;
      }
      
      var self = this
      setTimeout(function() {
          self.readfile();
      }, nextLoad);
      }
      

      });

      posted in Development
      A
      autonomus
    • run Linux command from a mm2 module

      Hello,

      My following question is very basic and that’s because I have no JS experience whatsoever.

      I’m trying to build a module that reads the content of a text file and display it on MM2.

      So I want the module to run the “cat” linux command and display its output. This will be refreshed on some interval as the text file will change.

      Is there’s a module that already does something similar?

      I looked at helloword default module but the text variable is a static string. I tried to add $USER to see if it’ll get the Linux env var value in there but it didn’t.

      I would be very thankful if anyone could provide me some pointers on how to go forward with this.

      posted in Development
      A
      autonomus
    • RE: Run module

      @strawberry-3.141 Thanks for the quick reply!

      posted in Requests
      A
      autonomus
    • RE: Run module

      Hi,

      Did you manage to solve this somehow? I’m trying to run a Linux command or script from inside a module.

      posted in Requests
      A
      autonomus