• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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 374 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 Jan 19, 2021, 2:20 AM

    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 Jan 19, 2021, 2:24 AM Reply Quote 0
    • S Away
      sdetweil @glorianneef
      last edited by sdetweil Jan 19, 2021, 2:27 AM Jan 19, 2021, 2:24 AM

      @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 Jan 19, 2021, 4:19 AM

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

        S 1 Reply Last reply Jan 19, 2021, 1:07 PM Reply Quote 0
        • S Away
          sdetweil @glorianneef
          last edited by Jan 19, 2021, 1:07 PM

          @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
          • 1 / 1
          1 / 1
          • First post
            1/4
            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