• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

sendSocketNotification from node_helper to Module

Scheduled Pinned Locked Moved Development
5 Posts 2 Posters 2.6k Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    Leobaillard
    last edited by Jan 26, 2017, 10:48 AM

    Hi!

    I’m creating a new topic rather than dig up this old one:
    Re: Unable to sendSocketNotification from node_helper to Module

    I’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!

    M 1 Reply Last reply Jan 26, 2017, 5:02 PM Reply Quote 0
    • M Offline
      morozgrafix Moderator @Leobaillard
      last edited by Jan 26, 2017, 5:02 PM

      @Leobaillard sent you a DM for API key. Will try to troubleshoot it

      1 Reply Last reply Reply Quote 0
      • L Offline
        Leobaillard
        last edited by Jan 27, 2017, 7:58 AM

        Thanks! Key sent ;)

        M 1 Reply Last reply Jan 27, 2017, 10:38 AM Reply Quote 1
        • M Offline
          morozgrafix Moderator @Leobaillard
          last edited by morozgrafix Jan 27, 2017, 10:39 AM Jan 27, 2017, 10:38 AM

          @Leobaillard I think I got it.

          Lines 76-81 of MMM-JCD-Bikes.js is the culprit. I believe that once you were going into Object.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 and self.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 this cell.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.

          1 Reply Last reply Reply Quote 2
          • L Offline
            Leobaillard
            last edited by Jan 27, 2017, 12:33 PM

            Waow! I was completely off track! It now works perfectly. Thanks a lot!

            1 Reply Last reply Reply Quote 1
            • 1 / 1
            1 / 1
            • First post
              1/5
              Last post
            Enjoying MagicMirror? Please consider a donation!
            MagicMirror created by Michael Teeuw.
            Forum managed by Sam, technical setup by Karsten.
            This forum is using NodeBB as its core | Contributors
            Contact | Privacy Policy