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

Error on loading script (new module not working)

Scheduled Pinned Locked Moved Troubleshooting
3 Posts 2 Posters 203 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.
  • B Offline
    Bobae
    last edited by sdetweil Jun 2, 2020, 11:46 AM Jun 2, 2020, 10:47 AM

    Hi,
    I developed a new module. It seems okay,
    but if i try to load it, its aborted and not able to load

    [GET http://localhost:8080/modules/{mymodule} net::ERR_ABORTED 404 (Not Found)]
    [loader.js:187 Error on loading script: modules/{mymodule}]

    what could be the reason for this? Well probably my module has problems, so i attached it also.

    Thank you

    
    Module.register("mymodule",{
    	defaults: {
    		location: false,
    		locationID: false,
    		apiKey: "",
    		apiBase: "https://api.openweathermap.org/data/2.5/weather",
    		animationSpeed: 1000,
    		updateInterval: 10 * 60 * 1000, // every 10 minutes
    	},
    	// Define required scripts.
    	getScripts: function() {
    		return ["moment.js"];
    	},
    
    	// Define required scripts.
    	getStyles: function() {
    		return ["mymodule.css"];
    	},
    	
    	// No translations
    	getTranslations: function() {
    		return false;
    	},
    	
    	// Define start sequence.
    	  start: function() {
    	    Log.info("Starting module: " + this.name);
    	
    	    // Set locale.
    	    moment.locale(config.language);
    	
    	    this.type = null;
    		this.temperature = null;
    		this.loaded = false;
    		this.initialDelay = 0;
    		this.retryDelay = 2500;
    		this.scheduleUpdate(this.initialDelay);
    	  },
      
    	getDom: function(){
    		var wrapper = document.createElement("div");
    	    if (this.config.apikey === "") {
    	      wrapper.innerHTML = "Please set the valid APIKEY: " + this.name + ".";
    	      wrapper.className = "dimmed light small";
    	      return wrapper;
    	    }
    	
    	    if (!this.loaded) {
    	      wrapper.innerHTML = "LOADING";
    	      wrapper.className = "dimmed light small";
    	      return wrapper;
    	    }
    	    
    	    switch(this.type){
    			case "Rain":
    				wrapper.classList.add("rain");
    				break;
    			case "Drizzle": //이슬비
    				wrapper.classList.add("drizzle");
    				break;
    			case "Snow":
    				wrapper.classList.add("snow")
    				break;
    			case "Thunderstorm":
    				wrapper.classList.add("thunderstorm")
    				break;
    			case "default":
    				break;
    		}
    		
    		if(this.temperature > 27){
    			var hot = document.createElement("span");
    			hot.classList.add("hot");
    			wrapper.appendChild(hot);
    		}
    		return wrapper;
    	},
    	
    	updateWeather: function(){
    		if (this.config.apiKey === "") {
    			Log.error("RainAndSnow: Please set APIKEY");
    			return;
    		}
    		var url = this.config.apiBase + this.getParams();
    		var self = this;
    		var retry = true;
    
    		var request = new XMLHttpRequest();
    		request.open("GET", url, true);
    		request.onreadystatechange = function() {
    			if (this.readyState === 4) {
    				if (this.status === 200) {
    					self.processWeather(JSON.parse(this.response));
    				} else if (this.status === 401) {
    					self.updateDom(self.config.animationSpeed);
    
    					Log.error(self.name + ": Incorrect APIKEY.");
    					retry = true;
    				} else {
    					Log.error(self.name + ": Could not load weather.");
    				}
    
    				if (retry) {
    					self.scheduleUpdate((self.loaded) ? -1 : self.retryDelay);
    				}
    			}
    		};
    		request.send();
    	},
    	scheduleUpdate: function(delay){
    		var nextLoad = this.config.updateInterval;
    		if (typeof delay !== "undefined" && delay >= 0) {
    			nextLoad = delay;
    		}
    		var self = this;
    		setTimeout(function() {
    			self.updateWeather();
    		}, nextLoad);
    	},
    	processWeather: function(data){
    		if(!data) return;
    		
    		this.type = data.weather[0].main;
    		this.temperature = data.main.temp - 273.15;
    		this.loaded = true;
    		this.updateDom(this.config.animationSpeed);
    	},
    	getParams: function(){
    		var params = "?";
    		if(this.config.locationID){
    			params += "id="+this.config.locationID;
    		}
    		else if(this.config.location){
    			params += "q="+this.config.location;
    		}
    		params += "&appid="+this.config.apiKey;
    		return params;
    	},
    });
    
    S 1 Reply Last reply Jun 2, 2020, 11:51 AM Reply Quote 0
    • S Offline
      sdetweil @Bobae
      last edited by Jun 2, 2020, 11:51 AM

      @Bobae the name of the file you showed, we call it the modulename.js as the name MUST match the name of the module. which also must match the name of the folder the module is in

      and in config.js the name is the name of the folder

      { 
        module: 'name_of_module_folder',
        position: 'some screen position',
        config: {
        }
      }
      

      i hope this is edited for the forum

      http://localhost:8080/modules/{mymodule}
      

      it just says that the name of the module in config.js doesn’t match the name of the folder

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      B 1 Reply Last reply Jun 3, 2020, 10:47 AM Reply Quote 0
      • B Offline
        Bobae @sdetweil
        last edited by Jun 3, 2020, 10:47 AM

        @sdetweil Thank you! That one is edited for the forum actually, but anyway, you solved my problem ;)

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