• 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.

Trying to fix my module

Scheduled Pinned Locked Moved Troubleshooting
9 Posts 2 Posters 2.9k 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.
  • S Offline
    strawberry 3.141 Project Sponsor Module Developer @skoz
    last edited by strawberry 3.141 Dec 25, 2016, 9:18 PM Dec 25, 2016, 9:16 PM

    @skoz the link is above

    to give you an idea i wrote something little quick to give you an idea how it can be

    set an interval in start()

    setInterval(() => {
      this.getData();
      this.updateDom();
    }, 30*60*1000); //calls getData every 30 mins
    

    getData()

    this.dataDirSM = loadJSON("https://api-ratp.pierre-grimaud.fr/v2/rers/B/stations/les+baconnets?destination=robinson+saint+remy+les+chevreuse&endingstation=les+baconnets");
    this.data = loadJSON("https://api-ratp.pierre-grimaud.fr/v2/rers/B/stations/les+baconnets?destination=charles+de+gaulle+mitry+claye&endingstation=les+baconnets");
    

    getDom()

    var wrapper = document.createElement("div")
    if(this.dataDirSM && this.data){
    
                    var realtable = document.createElement('table');
    
                    realtable.appendChild(this.createUpperRow());
    
    for(var i = 0; i < Math.min(this.data.response.schedules.length, this.dataDirSM.response.schedules.length); i++){
                    var row = document.createElement('tr')
                    row.appendChild(this.boxHeader(this.data.response.schedules[i].message))
                    row.appendChild(this.boxHeader(this.data.response.schedules[i].id))
                    row.appendChild(this.boxHeader(this.dataDirSM.response.schedules[i].id))
                    row.appendChild(this.boxHeader(this.dataDirSM.response.schedules[i].message))
                    realtable.appendChild(row)
    }
                    wrapper.appendChild(realtable)
    } else {
    wrapper.innerHTML = "NO DATA";
    }
                    return wrapper
    

    Please create a github issue if you need help, so I can keep track

    1 Reply Last reply Reply Quote 0
    • S Offline
      skoz
      last edited by Dec 25, 2016, 9:26 PM

      oh, i’m blind xD I had never seen this module, thanks for pointing it out !
      You fixed the for loop, i had trouble with this one, I refused to work and i still don’t know why so i decided to bypass it. Thanks alot for fixing my code, if I understand right, the getDom function will check if data has arrived and if True, it will display the table, if False, it will display the"NO DATA" ? and each reload, the program will reload the data and display it ?
      I’ll just have to shorten the time between each refresh because train pass by a bit more regularly so it wont be up to date if i wait 30 minutes each time.

      Thank you alot, I will try this new code now :)

      S 1 Reply Last reply Dec 25, 2016, 9:34 PM Reply Quote 0
      • S Offline
        strawberry 3.141 Project Sponsor Module Developer @skoz
        last edited by Dec 25, 2016, 9:34 PM

        @skoz yes, but it’s not tested i just wrote it down to give you an idea. if you get in trouble feel free to wite me a pn or check out the other module

        Please create a github issue if you need help, so I can keep track

        1 Reply Last reply Reply Quote 0
        • S Offline
          skoz
          last edited by Dec 25, 2016, 9:49 PM

          Well at least, this time, something happened, the mirror boot up but where the table should be, its written :

          schedules
          module_5_schedules

          Module.register(“schedules”, {

                  defaults: {
                      updateInterval: 20000
                      fadeSpeed: 4000
                  },
          
                  getScripts: function() {
                      return ["moment.js"]
                  },
          
                  getStyles: function() {
                      return ["font-awesome.css", "schedules.css"]
          
                  },
          
                  start: function() {
                      Log.info("Starting module: " + this.name);
          
          
                      setInterval(() => {
                          this.getData();
                          this.updateDom();
                      }, 20 * 1000); //calls getData every 20 second
                  },
          
                  getDom: function() {
          
          
                      var wrapper = document.createElement("div")
                      if (this.dataDirSM && this.data) {
          
                          var realtable = document.createElement('table');
          
                          realtable.appendChild(this.createUpperRow());
          
                          for (var i = 0; i < Math.min(this.data.response.schedules.length, this.dataDirSM.response.schedules.length); i++) {
                              var row = document.createElement('tr')
                              row.appendChild(this.boxHeader(this.data.response.schedules[i].message))
                              row.appendChild(this.boxHeader(this.data.response.schedules[i].id))
                              row.appendChild(this.boxHeader(this.dataDirSM.response.schedules[i].id))
                              row.appendChild(this.boxHeader(this.dataDirSM.response.schedules[i].message))
                              realtable.appendChild(row)
                          }
                          wrapper.appendChild(realtable)
                      } else {
                          wrapper.innerHTML = "NO DATA";
          
                      },
          
          
                      getData: function() {
          
                              this.dataDirSM = loadJSON("https://api-ratp.pierre-grimaud.fr/v2/rers/B/stations/les+baconnets?destination=robinson+saint+remy+les+chevreuse&endingstation=les+baconnets");
                              this.data = loadJSON("https://api-ratp.pierre-grimaud.fr/v2/rers/B/stations/les+baconnets?destination=charles+de+gaulle+mitry+claye&endingstation=les+baconnets");
          
                          },
          
                          createUpperRow: function() {
          
                              function createUpperRow() {
          
                                  var firstTableRow = document.createElement('tr');
          
                                  var tableh1 = document.createElement('th');
                                  tableh1.classList.add('align-left');
                                  var tx1 = document.createTextNode('Time');
          
                                  tableh1.appendChild(tx1);
                                  firstTableRow.appendChild(tableh1);
          
                                  var tableh2 = document.createElement('th');
                                  tableh2.classList.add('align-left');
                                  var tx2 = document.createTextNode('Paris');
          
                                  tableh2.appendChild(tx2);
                                  firstTableRow.appendChild(tableh2);
          
                                  // deuxième moitier
          
                                  var tableh3 = document.createElement('th');
                                  tableh3.classList.add('align-right');
                                  var tx3 = document.createTextNode('Sud');
          
                                  tableh3.appendChild(tx3);
                                  firstTableRow.appendChild(tableh3);
          
                                  var tableh4 = document.createElement('th');
                                  tableh4.classList.add('align-right');
                                  var tx4 = document.createTextNode('Time');
          
                                  tableh4.appendChild(tx4);
                                  firstTableRow.appendChild(tableh4);
          
                                  return firstTableRow;
          
                              },
          
                              boxHeader: function(inside) {
          
                                  if (inside == 'Train à l\'approche' || inside == 'Train à quai') {
          
                                      inside = 'no way'
                                  } else if (inside == 'Train retardé') {
          
                                      inside = 'retard'
                                  }
          
          
          
                                  var fillNode = document.createTextNode(inside);
                                  var realBox = document.createElement('td')
                                  realBox.appendChild(fillNode);
                                  return realBox;
                              }
          
          
                          })
          

          and here is what I got from your advices

          S 1 Reply Last reply Dec 25, 2016, 9:51 PM Reply Quote 0
          • S Offline
            strawberry 3.141 Project Sponsor Module Developer @skoz
            last edited by strawberry 3.141 Dec 25, 2016, 9:53 PM Dec 25, 2016, 9:51 PM

            @skoz you forgot to return wrapper at the end of getDom and remove function createUpperRow() { in vreateUpperRow

            Please create a github issue if you need help, so I can keep track

            1 Reply Last reply Reply Quote 0
            • S Offline
              skoz
              last edited by Dec 25, 2016, 9:59 PM

              Oh you are right, I also forget a curly brace after the ‘else’, I changed all that but it still doesn’t work
              I paste the code again if you want to see it clear

              Module.register(“schedules”, {

              defaults: {
                  updateInterval: 20000
                  fadeSpeed: 4000
              },
              
              getScripts: function() {
                  return ["moment.js"]
              },
              
              getStyles: function() {
                  return ["font-awesome.css", "schedules.css"]
              
              },
              
              start: function() {
                  Log.info("Starting module: " + this.name);
              
              
                  setInterval(() => {
                      this.getData();
                      this.updateDom();
                  }, 20 * 1000); //calls getData every 20 seconds
              },
              
              getDom: function() {
              
              
                  var wrapper = document.createElement("div")
                  if (this.dataDirSM && this.data) {
              
                      var realtable = document.createElement('table');
              
                      realtable.appendChild(this.createUpperRow());
              
                      for (var i = 0; i < Math.min(this.data.response.schedules.length, this.dataDirSM.response.schedules.length); i++) {
                          var row = document.createElement('tr')
                          row.appendChild(this.boxHeader(this.data.response.schedules[i].message))
                          row.appendChild(this.boxHeader(this.data.response.schedules[i].id))
                          row.appendChild(this.boxHeader(this.dataDirSM.response.schedules[i].id))
                          row.appendChild(this.boxHeader(this.dataDirSM.response.schedules[i].message))
                          realtable.appendChild(row)
                      }
                      wrapper.appendChild(realtable)
                  } else {
                      wrapper.innerHTML = "NO DATA";
                  };
                  return wrapper
              
              },
              
              
              getData: function() {
              
                  this.dataDirSM = loadJSON("https://api-ratp.pierre-grimaud.fr/v2/rers/B/stations/les+baconnets?destination=robinson+saint+remy+les+chevreuse&endingstation=les+baconnets");
                  this.data = loadJSON("https://api-ratp.pierre-grimaud.fr/v2/rers/B/stations/les+baconnets?destination=charles+de+gaulle+mitry+claye&endingstation=les+baconnets");
              
              },
              
              createUpperRow: function() {
              
              
                  var firstTableRow = document.createElement('tr');
              
                  var tableh1 = document.createElement('th');
                  tableh1.classList.add('align-left');
                  var tx1 = document.createTextNode('Time');
              
                  tableh1.appendChild(tx1);
                  firstTableRow.appendChild(tableh1);
              
                  var tableh2 = document.createElement('th');
                  tableh2.classList.add('align-left');
                  var tx2 = document.createTextNode('Paris');
              
                  tableh2.appendChild(tx2);
                  firstTableRow.appendChild(tableh2);
              
                  // deuxième moitier
              
                  var tableh3 = document.createElement('th');
                  tableh3.classList.add('align-right');
                  var tx3 = document.createTextNode('Sud');
              
                  tableh3.appendChild(tx3);
                  firstTableRow.appendChild(tableh3);
              
                  var tableh4 = document.createElement('th');
                  tableh4.classList.add('align-right');
                  var tx4 = document.createTextNode('Time');
              
                  tableh4.appendChild(tx4);
                  firstTableRow.appendChild(tableh4);
              
                  return firstTableRow;
              
              },
              
              boxHeader: function(inside) {
              
                  if (inside == 'Train à l\'approche' || inside == 'Train à quai') {
              
                      inside = 'no way'
                  } else if (inside == 'Train retardé') {
              
                      inside = 'retard'
                  }
              
              
              
                  var fillNode = document.createTextNode(inside);
                  var realBox = document.createElement('td')
                  realBox.appendChild(fillNode);
                  return realBox;
              }
              

              })

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                8/9
                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