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.

    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...

    Scheduled Pinned Locked Moved Troubleshooting
    4 Posts 2 Posters 477 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.
    • G Offline
      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 Do not disturb
        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

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • G Offline
          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 Do not disturb
            sdetweil @glorianneef
            last edited by

            @glorianneef dont copy exactly from my posts

            i wouldnt start the spawn unstil start time

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 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