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.

    CORS policy

    Scheduled Pinned Locked Moved Solved Troubleshooting
    20 Posts 3 Posters 4.1k Views 3 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
      bicolorbore586 @sdetweil
      last edited by

      @sdetweil
      ok, have put it back to how it was… that was final “can I get this to work, before I ask for further help”
      this is my config.js

      code_text
      ``` {
      			module: "weather",
      			position: "top_right",
      			config: {
      				weatherProvider: "weatherbit",
      				type: "current",
      				lat: 5,
      				lon: -1,
      				apiKey: "ab4",
      				useCorsProxy: true
      					}
      		},
      		{
      			module: "weather",
      			position: "top_right",
      			header: "Weather Forecast",
      			config: {
      				weatherProvider: "weatherbit",
      				type: "forecast",
      				lat: 5,
      				lon: -1,
      				initialLoadDelay: 1,
      				apiKey: "ab4",
      				useCorsProxy: true
      					}
      		},
      S 1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @bicolorbore586
        last edited by sdetweil

        @bicolorbore586 ok, lousy provider error reporting…

        i want you to edit the provider weatherbit.js and

        using your config (with the bad apikey) I get the ‘0’ error too

        change this (starting on line 38)

        					if (!data || !data.data[0] || typeof data.data[0].temp === "undefined") {
        						// No usable data?
        						return;
        					}
        
        					const currentWeather = this.generateWeatherDayFromCurrentWeather(data);
        					this.setCurrentWeather(currentWeather);
        

        to this

        				if(!data || (data && data.error)){
        					Log.error("Could not load data ... ", data?data.error: "no data returned");
        				}
        				else {
        					if (!data || !data.data[0] || typeof data.data[0].temp === "undefined") {
        						// No usable data?
        						return;
        					}
        
        					const currentWeather = this.generateWeatherDayFromCurrentWeather(data);
        					this.setCurrentWeather(currentWeather);
        				}
        

        then save and
        restart mm, open the developers window
        ctrl-shift-i
        select the console tab
        and enter weath
        in the filter field

        there should be a red line of text , with the weatherbit.js name to the right

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        B 1 Reply Last reply Reply Quote 0
        • B Offline
          bicolorbore586 @sdetweil
          last edited by

          @sdetweil
          so I commented out the original text and added in the new:

          code_text
          ``` fetchCurrentWeather() {
          		this.fetchData(this.getUrl())
          			.then((data) => {
          				/*if (!data || !data.data[0] || typeof data.data[0].temp === "undefined") {
          					// No usable data?
          					return;
          				}
          
          				const currentWeather = this.generateWeatherDayFromCurrentWeather(data);
          				this.setCurrentWeather(currentWeather);*/
          				if(!data || (data && data.error)){
          					Log.error("Could not load data ... ", data?data.error: "no data returned");
          				}
          				else {
          					if (!data || !data.data[0] || typeof data.data[0].temp === "undefined") {
          						// No usable data?
          						return;
          					}
          
          					const currentWeather = this.generateWeatherDayFromCurrentWeather(data);
          					this.setCurrentWeather(currentWeather);
          				}
          			})
          			.catch(function (request) {
          				Log.error("Could not load data ... ", request);
          			})
          			.finally(() => this.updateAvailable());
          B 1 Reply Last reply Reply Quote 0
          • B Offline
            bicolorbore586 @bicolorbore586
            last edited by

            @bicolorbore586 from the line Could not load data … TypeError: Cannot read properties of undefined (reading ‘0’) at weatherbit.is

            S 2 Replies Last reply Reply Quote 0
            • S Offline
              sdetweil @bicolorbore586
              last edited by

              @bicolorbore586 can u email me your apikey

              same userid as on this post
              at gmail

              or send me a direct message

              the returned data is not coming back in the expected format

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              1 Reply Last reply Reply Quote 0
              • S Offline
                sdetweil @bicolorbore586
                last edited by

                @bicolorbore586 thanks for the key

                the error is

                Your request count (159) is over the allowed limit of 50 per day - Upgrade your key, or retry after 670.2 minutes
                

                and u have 2 modules configured, so each will fetch separately, so u have to change the update cycle to once/hour
                in both modules, (default 10 mins)

                updateInterval: 60 * 60 * 1000
                

                and every MM restart sends 2 requests, 1 for each module

                change the new code to look like this…

                				if(!data || (data && data.error) || data.status_message){
                					Log.error("Could not load data ... ", data?(data.error|| data.status_message): "no data returned");
                				}
                				else {
                					if (!data || !data.data[0] || typeof data.data[0].temp === "undefined") {
                						// No usable data?
                						return;
                					}
                
                					const currentWeather = this.generateWeatherDayFromCurrentWeather(data);
                					this.setCurrentWeather(currentWeather);
                				}
                

                crappy api implementation… should set error for all errors, not
                put error info in good data returns

                Sam

                How to add modules

                learning how to use browser developers window for css changes

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