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

How to load a <script> src = " " </script> into my mirror?

Scheduled Pinned Locked Moved Development
35 Posts 4 Posters 24.1k 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.
  • M Offline
    morozgrafix Moderator
    last edited by morozgrafix Jan 24, 2017, 8:53 AM Jan 24, 2017, 5:27 AM

    Sorry I’m on mobile right now and it’s not easy to write code samples on the phone.

    You will not be able to access your local file via URL like that. You would need to read it from the file system. In default compliments module there is a piece of code that you can modify to achieve that.

    EDIT: If you place your JANUARY22TEST.csv file in the directory of your module named datafeed it should be available at this URL: http://localhost:8080/modules/datafeed/JANUARY22TEST.csv

    Here is a snippet, but I would recommend looking through the whole module to get a better idea how it works:

    	/* complimentFile(callback)
    	 * Retrieve a file from the local filesystem
    	 */
    	complimentFile: function(callback) {
    		var xobj = new XMLHttpRequest();
    		xobj.overrideMimeType("application/json");
    		xobj.open("GET", this.file(this.config.remoteFile), true);
    		xobj.onreadystatechange = function () {
    			if (xobj.readyState == 4 && xobj.status == "200") {
    				callback(xobj.responseText);
    			}
    		};
    		xobj.send(null);
    	},
    

    In this case it’s reading JSON file, but you would need to read plain text CSV. There are a few examples that are similar on Stack Overflow and in tutorials online. I will try to dig up an example when I’m back in front of my computer, but I’m sure you can easily search for them.

    N 1 Reply Last reply Jan 24, 2017, 5:16 PM Reply Quote 0
    • N Offline
      nbrenn @morozgrafix
      last edited by Jan 24, 2017, 5:16 PM

      @morozgrafix Thanks for the response and the support!

      This looks very promising solution and I’ll give it a go once I solve one nagging problem. I am receiving the connection refused error when I am connecting to the localhost: 8080:

      pi@raspberrypi:~ $ wget --verbose localhost:8080
      --2017-01-24 12:11:12--  http://localhost:8080/
      Resolving localhost (localhost)... ::1, 127.0.0.1
      Connecting to localhost (localhost)|::1|:8080... failed: Connection refused.
      Connecting to localhost (localhost)|127.0.0.1|:8080... failed: Connection refused.
      pi@raspberrypi:~ $
      
      M 1 Reply Last reply Jan 24, 2017, 6:02 PM Reply Quote 0
      • M Offline
        morozgrafix Moderator @nbrenn
        last edited by Jan 24, 2017, 6:02 PM

        @nbrenn is your mirror up and running with npm start or node serveronly? If webserver isn’t running on port 8080 you will get connection refused error when attempting to access it over HTTP.

        N 1 Reply Last reply Jan 24, 2017, 6:04 PM Reply Quote 0
        • N Offline
          nbrenn @morozgrafix
          last edited by Jan 24, 2017, 6:04 PM

          @morozgrafix I start my mirror with npm start. And my Mirror config.js, I am using Port 8080.

          M 1 Reply Last reply Jan 24, 2017, 6:07 PM Reply Quote 0
          • M Offline
            morozgrafix Moderator @nbrenn
            last edited by Jan 24, 2017, 6:07 PM

            @nbrenn when your electron MM app shows up on the screen and while it is running, you should be able to do wget http://localhost:8080 without getting connection refused.

            N 1 Reply Last reply Jan 24, 2017, 6:19 PM Reply Quote 0
            • N Offline
              nbrenn @morozgrafix
              last edited by nbrenn Jan 24, 2017, 6:24 PM Jan 24, 2017, 6:19 PM

              @morozgrafix Yep, when the mirror was running, and running the wget http://localhost:8080 command, I connected successfully.

              So then when I open up a command terminal while the mirror is running, and run:

              wget http://localhost:8080/home/pi/MagicMirror/modules/datafeed/JANUARY22TEST.csv
              

              it says connected to 8080, but returns 404 Not Found.

              M 1 Reply Last reply Jan 24, 2017, 6:29 PM Reply Quote 0
              • M Offline
                morozgrafix Moderator @nbrenn
                last edited by Jan 24, 2017, 6:29 PM

                @nbrenn that path is incorrect. Try

                wget http://localhost:8080/modules/datafeed/JANUARY22TEST.csv
                
                N 1 Reply Last reply Jan 24, 2017, 6:41 PM Reply Quote 0
                • N Offline
                  nbrenn @morozgrafix
                  last edited by Jan 24, 2017, 6:41 PM

                  @morozgrafix You got it! The path was the issue. Do you know why I can’t use the path the way I specified?

                  Now, I’ll go back and try your solution and see if I have any other problems!

                  Thanks again for your help. It’s much appreciated.

                  M 1 Reply Last reply Jan 24, 2017, 7:07 PM Reply Quote 0
                  • M Offline
                    morozgrafix Moderator @nbrenn
                    last edited by morozgrafix Jan 24, 2017, 7:07 PM Jan 24, 2017, 7:07 PM

                    @nbrenn glad you are getting closer to solving this.

                    Root directory that is served by webserver that is running on localhost:8080/ is mapped to MagicMirror directory. In most cases and in your case the full path of that is /home/pi/MagicMirror.
                    By default it is configured to serve you index.html.

                    So mapping looks kind of like this:

                    http://localhost:8080					---->	/home/pi/MagicMirror/
                    http://localhost:8080/index.html			---->	/home/pi/MagicMirror/index.html
                    http://localhost:8080/modules/module_name		---->	/home/pi/MagicMirror/modules/module_name/
                    http://localhost:8080/modules/module_name/foo.html	---->	/home/pi/MagicMirror/modules/module_name/foo.html
                    

                    as you can see from above when you asking for

                    http://localhost:8080/home/pi/MagicMirror/modules/datafeed/JANUARY22TEST.csv
                    

                    webserver will attempt to serve you something from

                    /home/pi/MagicMirror/home/pi/MagicMirror/modules/datafeed/JANUARY22TEST.csv
                    

                    which doesn’t really exist and that’s the reason why you can’t use absolute file path in the URL. Which also brings up another point: because root directory that is served by webserver is mapped to /home/pi/MagicMirror, webserver can’t serve anything above the /home/pi/MagicMirror directory. (for example you won’t be able to access /home/pi/foo.html).

                    This is just a small portion of how it works and there are other rules that play role, but hopefully this info shines some light and gives you enough explanation on why your path didn’t work.

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      morozgrafix Moderator
                      last edited by Jan 24, 2017, 7:44 PM

                      I’ve moved this thread into Development category, since conversation is now mostly related to your module development.

                      Thanks.

                      N 1 Reply Last reply Jan 24, 2017, 10:24 PM Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 1 / 4
                      1 / 4
                      • First post
                        10/35
                        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