Hi,
I’m very new to MM (2 days in…).
I have successfully got a module I’ve written working. It scrapes a local transit website for real-time train departure info and displays in the mirror.
My second module, however, is having problems. The node_helper is getting socket notifications from the module, but when it calls sendSocketNotification(), nothing is received at the module. I tried used the original (working) module as a template, making it almost an exact copy of the working module, but that didn’t help.
I’ve stipped it back to almost nothing, and still no luck. Here’s the node_helper and module file in question:
node_helper.js:
const NodeHelper = require('node_helper');
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node helper: " + this.name);
},
socketNotificationReceived: function(notification, payload) {
var self = this;
console.log("Notification: " + notification + " Payload: " + JSON.stringify(payload));
if (notification === "GET_DATA") {
self.sendSocketNotification("GOT_DATA", "1234566789");
}
}
});
and MMM-MYTEST.js:
Module.register("MMM-MYTEST", {
// Default configs
defaults: {
intervalSecs: 10,
},
start: function () {
Log.info(this.config);
Log.log('Starting module: ' + this.name);
self = this;
self.getData();
setInterval(function() {
self.getData();
}, self.config.intervalSecs * 1000);
},
getData: function () {
Log.info(this.name + ': Getting data');
this.sendSocketNotification("GET_DATA", {
config: this.config,
});
},
getStyles: function () {
return [
this.file('styles.css'),
];
},
socketNotificationReceived: function(notification, payload) {
if (notification === "GOT_DATA") {
Log.info('socketNotificationReceived: GOT_DATA');
this.updateDom();
}
},
// Override the DOM generator
getDom: function () {
let wrapper = document.createElement('div');
return wrapper;
},
});
And snipped log output while running (I added some debug outout to NodeHelper.socketNotificationReceived() to make sure it was being called):
[27.02.2023 14:10.56.820] [LOG] Notification: GET_DATA Payload: {"config":{"intervalSecs":10}}
[27.02.2023 14:10.56.821] [INFO] in MMM-MYTEST sendSocketNotification GOT_DATA
[27.02.2023 14:11.06.819] [LOG] Notification: GET_DATA Payload: {"config":{"intervalSecs":10}}
[27.02.2023 14:11.06.820] [INFO] in MMM-MYTEST sendSocketNotification GOT_DATA
[27.02.2023 14:11.16.827] [LOG] Notification: GET_DATA Payload: {"config":{"intervalSecs":10}}
[27.02.2023 14:11.16.829] [INFO] in MMM-MYTEST sendSocketNotification GOT_DATA
So I can see that NodeHelp.socketNotificationRecieved() is being called, but my module never gets the notification. I’ve run out of debug ideas. Any assistance would be greatly appreciated.
m