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...
-
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.jsModule.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); } }); -
@glorianneef move sendsocketnotification in the data.on handler
child.stdout.on('data… ()=>{
sendsocketnotification(notice, data)
}on phone, best i can do
-
Thank you for the reply!
However, I sadly am still shown a black screen of doom… not too sure. -
@glorianneef dont copy exactly from my posts
i wouldnt start the spawn unstil start time
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