Read the statement by Michael Teeuw here.
[Solved] Socket notification not working
-
@j.e.f.f Thanks but still not working.
-
@willfri Some things to check… sometimes I have problems like this. Is the module file named
helloworld.js
? Is it in themodules
under a subdirectory namedhelloworld
? Are there any other modules installed namedhelloworld
? there can only be one.If those are fine, what you can do is add
console.log()
at various places in your code to try and determine where it’s failing. Anyconsole.log
you add innode_helper.js
will appear in the terminal where you started MM withnpm start
, and anyconsole.log
entries that you make inhelloworld.js
will appear in electron’s console (usenpm start dev
) to start electron with the dev console open.so for example, in helloworld.js, maybe add this :
start: function() { this.sendSocketNotification('CONFIG', this.config); console.log("notification sent to node_helper"); },
and in
node_helper.js
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"); } }
back in helloworld.js:
socketNotificationReceived: function(notification, payload) { if (notification === 'STARTED') { console.log("STARTED notification received from node_helper"); this.config.text = 'Started'; this.updateDom(); } }
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.
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.
-
@j.e.f.f Thank you for your help.
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.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.
It’s strange that all console.logs() in socketNotificationReceived() are missing but now everything works.
Is it a feature?! ;D -
@willfri you need to look in several places for the console.log output. Anything from
node_helper.js
will be displayed in the terminal window (I.e. Where you rannpm install
from) or in pm2’s log file (pm2 logs mm
) if you’re running it on auto start.The console.log statements in
helloworld.js
will be output in electron’s console (enable it withnpm start dev
). -
@j.e.f.f I tried
npm start dev
but I don’t got the output fromconsole.log()
inhelloworld.js