MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.24.0 is available! For more information about this release, check out this topic.

    I am a Node.js noob and I created a module for interfacing with a keypad connected to my arduino. The Arduino communicates to my RPi via serial USB. My application keeps crashing...

    Troubleshooting
    2
    4
    155
    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.
    • G
      glorianneef last edited by

      I have checked for configuration errors and this is all fine. Everything seems to go smoothly until I add my node_helper.js. I will upload my config file, main module file, and my helper. Any help would be appreciated. Can’t seem to find the reason for breaking my Magic mirror. =
      MMM-Timer.js

      Module.register("MMM-Timer", {
      // Default module config.
         defaults: {
         	text: "Hello World!"
         },
      
         // Override dom generator.
         getDom: function() {
         	var wrapper = document.createElement("div");
         	wrapper.innerHTML = this.config.text;
         	return wrapper;
         },
         start: function() {
         	this.mySpecialProperty = "So much wow!";
         	Log.log(this.name + ' is started!');
         	var self = this;
         	setInterval(function() {
         	self.updateDom(); // no speed defined, so it updates instantly.
         		}, 1000); //perform every 1000 milliseconds.
         },
         notificationReceived: function(notification, payload, sender) {
         	if (sender) {
         		Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
         	} else {
         		Log.log(this.name + " received a system notification: " + notification);
         	}
         },
         socketNotificationReceived: function(notification, payload) {
         	Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
         }
      });
      

      node_helper.js

      var NodeHelper = require("node_helper");
      const { spawn } = require('child_process');
      const child = spawn('~/serial_communication.py');
      
      module.exports = NodeHelper.create({
      	start: function() {
      		this.mySpecialProperty = "So much wow!";
      		Log.log(this.name + ' is started!');
      	},
      	stop: function() {
      		console.log("Shutting down MyModule");
      		console.log('kill');
          		child.kill();
      		this.connection.close();
      	},
      	// Override socketNotificationReceived method.
      
      	socketNotificationReceived: function(notification, payload) {
      		Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
      	},
      
      	// Test another function
      	aFunction: function() {
      		child.stdout.on('data', (data) => {
        			console.log(`child stdout:\n${data}`);
      		});
      		
      		child.stderr.on('data', (data) => {
        			console.error(`stderr: ${data}`);
      		});
      		child.on('close', (code) => {
        			console.log(`child process exited with code ${code}`);
      		});
      		//want to return the python subprocess
      		this.sendSocketNotification('MY_TIMER_DATA', data);
      	}
      });
      
      S 1 Reply Last reply Reply Quote 0
      • S
        sdetweil @glorianneef last edited by sdetweil

        @glorianneef move sendsocketnotification in the data.on handler
        child.stdout.on('data… ()=>{
        sendsocketnotification(notice, data)
        }

        on phone, best i can do

        Sam

        Create a working config
        How to add modules

        1 Reply Last reply Reply Quote 0
        • G
          glorianneef last edited by

          Thank you for the reply!
          However, I sadly am still shown a black screen of doom… not too sure.

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

            @glorianneef dont copy exactly from my posts

            i wouldnt start the spawn unstil start time

            Sam

            Create a working config
            How to add modules

            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 Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
            This forum is using NodeBB as its core | Contributors
            Contact | Privacy Policy