<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Solved] Socket notification not working]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">yesterday I’ve created my first module with some socket notifications and everything worked.<br />
Today I started to creating my second module but now I got a problem with the socket notifications. I tried very much but it’s still not working correctly. After this I created a very simple module based on the helloworld module.</p>
<p dir="auto">The first notification receive at node_helper.js but when I now try to answer with a new notification nothing happend. The module still shows “Hello World!” insteand of “Started”. Also console.log() inside of socketNotificationReceived in main file are ignored when node_helper.js sends one.</p>
<p dir="auto">Here you can see my code.</p>
<p dir="auto">helloworld.js</p>
<pre><code>Module.register("helloworld",{
	defaults: {
		text: "Hello World!"
	},

	getDom: function() {
		var wrapper = document.createElement("div");
		wrapper.innerHTML = this.config.text;
		return wrapper;
	},

	start: function() {
		this.sendSocketNotification('CONFIG', this.config);
	},

	socketNotificationReceived: function(notification, payload) {
		if (notification === 'STARTED') {
			this.config.text = 'Started';
			this.updateDom();
		}
	}
});
</code></pre>
<p dir="auto">node_helper.js</p>
<pre><code>var NodeHelper = require("node_helper");

module.exports = NodeHelper.create({
	start: function () {
		this.config = {}
	},

	socketNotificationReceived: function (notification, payload) {
		if (notification === 'CONFIG') {
			this.config = payload;
			this.sendSocketNotification('STARTED');
		}
	}
});
</code></pre>
<p dir="auto">Can anyone help me?</p>
<p dir="auto">Thanks<br />
Willy</p>
]]></description><link>https://forum.magicmirror.builders/topic/4667/solved-socket-notification-not-working</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 01:59:47 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/4667.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Aug 2017 18:12:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Solved] Socket notification not working on Thu, 17 Aug 2017 22:24:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/j.e.f.f" aria-label="Profile: j.e.f.f">@<bdi>j.e.f.f</bdi></a> I tried <code>npm start dev</code> but I don’t got the output from <code>console.log()</code> in <code>helloworld.js</code></p>
]]></description><link>https://forum.magicmirror.builders/post/26675</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/26675</guid><dc:creator><![CDATA[willfri]]></dc:creator><pubDate>Thu, 17 Aug 2017 22:24:27 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Socket notification not working on Thu, 17 Aug 2017 22:12:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/willfri" aria-label="Profile: willfri">@<bdi>willfri</bdi></a> you need to look in several places for the console.log output. Anything from <code>node_helper.js</code> will be displayed in the terminal window (I.e. Where you ran <code>npm install</code> from) or in pm2’s log file (<code>pm2 logs mm</code>) if you’re running it on auto start.</p>
<p dir="auto">The console.log statements in <code>helloworld.js</code> will be output in electron’s console (enable it with <code>npm start dev</code>).</p>
]]></description><link>https://forum.magicmirror.builders/post/26673</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/26673</guid><dc:creator><![CDATA[j.e.f.f]]></dc:creator><pubDate>Thu, 17 Aug 2017 22:12:43 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Socket notification not working on Thu, 17 Aug 2017 22:00:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/j.e.f.f" aria-label="Profile: j.e.f.f">@<bdi>j.e.f.f</bdi></a> Thank you for your help.<br />
Now it works but I can’t tell exactly why. In meantime I installed a new image with Raspbian and MM and tested my code above. Then I recognized that there is also the module “helloworld” in “defaults” folder. After renaming the module it worked. Then I flashed my old installation again and tried the above code under a new name again and it worked. Finally I tried my second module, for which I do all this testing, with minimal changes and, surprise, it works.</p>
<p dir="auto">I think my problem was to rely too much on the output of the console. I never saw the output from console.log() in the socketNotificationReceived() (in main file) so I suspected a mistake with the socket notifications.</p>
<p dir="auto">It’s strange that all console.logs() in socketNotificationReceived() are missing but now everything works.<br />
Is it a feature?! ;D</p>
]]></description><link>https://forum.magicmirror.builders/post/26672</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/26672</guid><dc:creator><![CDATA[willfri]]></dc:creator><pubDate>Thu, 17 Aug 2017 22:00:04 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Socket notification not working on Thu, 17 Aug 2017 19:48:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/willfri" aria-label="Profile: willfri">@<bdi>willfri</bdi></a> Some things to check… sometimes I have problems like this.  Is the module file named <code>helloworld.js</code>?  Is it in the <code>modules</code> under a subdirectory named <code>helloworld</code>?  Are there any other modules installed named <code>helloworld</code>? there can only be one.</p>
<p dir="auto">If those are fine, what you can do is add <code>console.log()</code> at various places in your code to try and determine where it’s failing.  Any <code>console.log</code> you add in <code>node_helper.js</code> will appear in the terminal where you started MM with <code>npm start</code>, and any <code>console.log</code> entries that you make in <code>helloworld.js</code> will appear in electron’s console (use <code>npm start dev</code>) to start electron with the dev console open.</p>
<p dir="auto">so for example, in helloworld.js, maybe add this :</p>
<pre><code>	start: function() {
		this.sendSocketNotification('CONFIG', this.config);
                console.log("notification sent to node_helper");
	},
</code></pre>
<p dir="auto">and in <code>node_helper.js</code></p>
<pre><code>	socketNotificationReceived: function (notification, payload) {
		if (notification === 'CONFIG') {
                        console.log("CONFIG notification received");
			this.config = payload;
			this.sendSocketNotification('STARTED');
                        console.log("STARTED notification sent back to front end");
		}
	}
</code></pre>
<p dir="auto">back in helloworld.js:</p>
<pre><code>	socketNotificationReceived: function(notification, payload) {
		if (notification === 'STARTED') {
                        console.log("STARTED notification received from node_helper");
			this.config.text = 'Started';
			this.updateDom();
		}
	}
</code></pre>
<p dir="auto">If you see all four of those messages, then the notifications are working and you need to look elsewhere.  Otherwise, when one of the messages doesn’t show up when you expect it to, then you’ve now zeroed closer into the problem.</p>
<p dir="auto">If you haven’t done so already, install MM locally on your laptop or workstation.  It’s way easier to develop modules that way that directly on the Pi.</p>
]]></description><link>https://forum.magicmirror.builders/post/26670</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/26670</guid><dc:creator><![CDATA[j.e.f.f]]></dc:creator><pubDate>Thu, 17 Aug 2017 19:48:23 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Socket notification not working on Thu, 17 Aug 2017 19:35:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/j.e.f.f" aria-label="Profile: j.e.f.f">@<bdi>j.e.f.f</bdi></a> Thanks but still not working.</p>
]]></description><link>https://forum.magicmirror.builders/post/26669</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/26669</guid><dc:creator><![CDATA[willfri]]></dc:creator><pubDate>Thu, 17 Aug 2017 19:35:33 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Socket notification not working on Thu, 17 Aug 2017 19:34:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/willfri" aria-label="Profile: willfri">@<bdi>willfri</bdi></a> I’m not positive that this is the problem, but in your node_helper.js file, you’re sending the socket notification back to the main module without a payload, but the front end expects a payload.</p>
<p dir="auto">Try changing this:</p>
<pre><code>this.sendSocketNotification('STARTED');
</code></pre>
<p dir="auto">to this:</p>
<pre><code>this.sendSocketNotification('STARTED', 'something');
</code></pre>
<p dir="auto">See if that fixes it.</p>
]]></description><link>https://forum.magicmirror.builders/post/26667</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/26667</guid><dc:creator><![CDATA[j.e.f.f]]></dc:creator><pubDate>Thu, 17 Aug 2017 19:34:20 GMT</pubDate></item></channel></rss>