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

Calendar Module: How to declare local calendar

Scheduled Pinned Locked Moved Troubleshooting
13 Posts 5 Posters 9.3k Views 5 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.
  • D Offline
    DazDavid
    last edited by Oct 17, 2016, 8:22 PM

    Hi all,

    maybe a stupid question but I cannot figure it out. I host my own Calendar file using Radicale Server on same Raspberry pi as the Mirror is but I have no idea how to access the local .ics file within the Mirror. I´ve tried both, local path ala /home/pi/…/MyCalendar.ics and also via https://IP-Address:5232/user/MyCalendar.ics but nothin works. Could anyone please guide me on how to set up the calendar properly? Thanks in Advance

    1 Reply Last reply Reply Quote 0
    • D Offline
      DazDavid
      last edited by Oct 19, 2016, 5:15 PM

      Did nobody every used a local file instead of Icloud or whatever? Am I the first? Even SMB or NFS would be fine but non of them is working…

      1 Reply Last reply Reply Quote 0
      • B Offline
        bhepler Module Developer
        last edited by Oct 19, 2016, 10:29 PM

        I’m currently trying to do the same as a modification to the compliments module. As part of the gift, my wife is writing up about 100 compliments for the recipients. That’s a bit much to throw into the config.js file, so I am attempting to get it to load the JSON for the compliments array in a separate file.

        I’ve had some success. I managed to get the file loaded into a variable. I can log out the contents of the array. What I can’t seem to do it get that variable into the existing compliments code. Hopefully you’ll have more success. Loading JSON file code taken from Codepen.

        complimentFile: function(callback) {
        	var xobj = new XMLHttpRequest();
        	xobj.overrideMimeType("application/json");
        	xobj.open('GET', this.file([***file name***]), true); 
        	xobj.onreadystatechange = function () {
        		if (xobj.readyState == 4 && xobj.status == "200") {
        			callback(xobj.responseText);
        		}
        	};
        	xobj.send(null);
        },
        

        And the call:

        randomCompliment: function() {
        	var compliments = this.complimentArray();
        		var complimentFile = this.complimentFile(function (response) {
        		     var json = JSON.parse(response);
        		     console.log(json.compliments.morning[0])
        	});
        		var index = this.randomIndex(compliments);
        		return compliments[index];
        },
        

        With this code, I can get the console to show the contents of the JSON file. In the log, I can see the first of the morning compliments I set up in my external file. But for the life of me, I can’t seem to get that json object out of the function. Javascript is obviously not my thing.

        D S 2 Replies Last reply Oct 20, 2016, 5:01 AM Reply Quote 0
        • C Offline
          cowboysdude Module Developer
          last edited by cowboysdude Oct 20, 2016, 3:08 AM Oct 20, 2016, 3:08 AM

          console.log(json.compliments.morning[0])

          I’m not programmer either but doesn’t this line just call the first object in the json file?

          function readTextFile(file, callback) {
          var rawFile = new XMLHttpRequest();
          rawFile.overrideMimeType(“application/json”);
          rawFile.open(“GET”, file, true);
          rawFile.onreadystatechange = function() {
          if (rawFile.readyState === 4 && rawFile.status == “200”) {
          callback(rawFile.responseText);
          }
          }
          rawFile.send(null);
          }

          //usage:
          readTextFile(“/Users/Documents/workspace/test.json”, function(text){
          var data = JSON.parse(text);
          console.log(data);
          });

          B 1 Reply Last reply Oct 20, 2016, 11:15 AM Reply Quote 0
          • D Offline
            DazDavid @bhepler
            last edited by Oct 20, 2016, 5:01 AM

            @bhepler thanks for the input but unfortunately your Problem is different to mine. The Calendar Module is already looking for an external ics File, all I need to know is the correct syntax for a local File instead of somewhere on a Webserver.

            1 Reply Last reply Reply Quote 0
            • Y Offline
              yawns Moderator
              last edited by Oct 20, 2016, 7:35 AM

              A quick search for “local ics” would return this: https://forum.magicmirror.builders/topic/467/calendar-ics-file-from-local-path/6 :)

              D 3 Replies Last reply Oct 20, 2016, 7:43 AM Reply Quote 1
              • D Offline
                DazDavid @yawns
                last edited by Oct 20, 2016, 7:43 AM

                @yawns hm Im pretty sure I searched for these two words before I opened the thread but didnt found it… I tried already something like this but without webcal prefix. I will try when I have a connection and give feedback. Thanks for the Link.

                1 Reply Last reply Reply Quote 0
                • D Offline
                  DazDavid @yawns
                  last edited by Oct 20, 2016, 8:03 AM

                  @yawns now I remember… i tried it that way and now the calendar tells me “no upcoming events”, whats not true.

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    DazDavid @yawns
                    last edited by Oct 20, 2016, 8:20 AM

                    @yawns Ok, the link finally solved my problem. I tried first to place the ics file under /MagicMirror directly but that doesnt work. As mentioned in the link I also created a new folder under /MagicMirror/modules and it works now. Thanks for your help.

                    Y 1 Reply Last reply Oct 20, 2016, 10:30 AM Reply Quote 1
                    • S Offline
                      strawberry 3.141 Project Sponsor Module Developer @bhepler
                      last edited by Oct 20, 2016, 8:35 AM

                      @bhepler something like this should do the job:

                      move the call of complimentFile into the start method, you want to load that file only once not every 30 secs
                      then override the the config compliments object with your data, that should be it

                      start: function() {
                          Log.info("Starting module: " + this.name);
                      
                          this.lastComplimentIndex = -1;
                      		
                          this.complimentFile((response) => {
                              this.config.compliments = JSON.parse(response);
                          });
                      
                          // Schedule update timer.
                          var self = this;
                          setInterval(function() {
                              self.updateDom(self.config.fadeSpeed);
                          }, this.config.updateInterval);
                      },
                      

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

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