Read the statement by Michael Teeuw here.
sendSocketNotification from node_helper to Module
-
Hi!
I’m creating a new topic rather than dig up this old one:
Re: Unable to sendSocketNotification from node_helper to ModuleI’m experiencing the same symptoms. I created a module based on yo-less’s MMM-nextbike (https://github.com/yo-less/MMM-nextbike) to pull bike sharing station information from JCDecaux. I basically took his code and adapted the fetching functions.
The actual fetching works as can be seen in the logs when I dump the fetched object, so that doesn’t seem to be the issue. Once the stations are pulled, I send a socket notification to the module from the node_helper to notify that the data is ready to be displayed.
The problem is that this notification never reaches the module. The console.log call supposed to display an incoming notification is never fired.
I suspect that it might be a dumb error on my part, but I can’t figure it out… Here is my code:
- https://gitlab.leoserveur.org/leobaillard/MMM-JCD-Bikes/blob/master/MMM-JCD-Bikes.js
- https://gitlab.leoserveur.org/leobaillard/MMM-JCD-Bikes/blob/master/node_helper.js
Here is a sample configuration:
{ module: 'MMM-JCD-Bikes', position: 'top_left', config: { title: 'Stations Velo\'v', apiKey: '<>', contract: 'Lyon', stations: [3003,3087,3085,3099,6035,6036,6037,6041,6042,6043], } },
For the API key, you can generate one here: https://developer.jcdecaux.com/#/signup or I can PM you mine.
Thanks in advance!
-
@Leobaillard sent you a DM for API key. Will try to troubleshoot it
-
Thanks! Key sent ;)
-
@Leobaillard I think I got it.
Lines 76-81 of
MMM-JCD-Bikes.js
is the culprit. I believe that once you were going intoObject.keys
it was losing the scope. Try changing those lines to this:// List available bikes via a stations array var self = this; Object.keys(self.stationsData).forEach(function (key) { table.appendChild(self.createStationNameRow(self.stationsData[key].name)); table.appendChild(self.createAmountRow(self.stationsData[key])); });
note that I’ve added
var self = this;
and now calling these when appending children elements to the table:self.createStationNameRow
,self.stationsData[key].name
,self.createAmountRow
andself.stationsData[key]
Another spot that I’ve noticed is that
createStationNameRow
function didn’t appendHTML name of the station to the cell. I didn’t dig too much into it, but I think thiscell.innerHTML = name;
was missing from it:createStationNameRow: function(name) { var nameRow = document.createElement("tr"); var cell = document.createElement("td"); cell.className = "stationName"; cell.setAttribute("colSpan", 2); cell.innerHTML = name; nameRow.appendChild(cell); return nameRow; },
Hopefully it will get you going in the right direction.
-
Waow! I was completely off track! It now works perfectly. Thanks a lot!