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.

    Unable to display weather description

    Scheduled Pinned Locked Moved Requests
    9 Posts 2 Posters 3.1k 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.
    • mochmanM Offline
      mochman Module Developer
      last edited by

      Did you want to get the first day’s weather information only? Did you declare the variable this.desc in the start function first? If not, that may be your problem.

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        Leone510es @mochman
        last edited by Leone510es

        @mochman Yes, only for the first day, and yes I did declared the variable in the start function like this:

        this.desc = null;
        

        I just dont know what to do in a different way. Maybe the DIV element creation part is wrong? I think the API is ok like this

        data.weather[0].description;
        

        or maybe not?

        Nobody ever made like this before?

        1 Reply Last reply Reply Quote 0
        • mochmanM Offline
          mochman Module Developer
          last edited by

          Yeah, it does look like the module gets back an array of weather data for each day. Have you tried putting some console.log() statements in your code to try and troubleshoot where the problem is. Like

          this.desc = data.weather[0].description;
          console.log("Description Var - " + this.desc); //See if anything is output
          

          At least then you’d know if the variable is correct and your div statement isn’t working, or the variable isn’t getting set correctly.

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            Leone510es @mochman
            last edited by

            @mochman Thanks for the great tip! Now I can see in the console whats happening in the background, and it’s really interesting.

            I’ve put console.log in 3 places in the code:

            1. in the start: function()
            console.log("Description 1 - " + this.desc); //See if anything is output
            
            1. in the getDom: function()
            var description = document.createElement("div");
            description .innerHTML = this.desc;
            large.appendChild(description);
            console.log("Description 2 - " + this.desc); //See if anything is output
            
            1. and in the processWeather: function(data)
            this.desc = data.weather[0].description;
            console.log("Description 3 - " + this.desc); //See if anything is output
            

            I also put a test line in the getDom function to see if it’s working:

            var test = document.createElement("div");
            test.innerHTML = "Lorem ipsum.." + this.desc + "..END";
            large.appendChild(test);
            

            And here you can see the results:
            0_1521365546142_mmirror.jpg

            As you can see, only the third console.log has the value, and the first two has only “null”. The “null” is also in the test line Lorem ipsum…

            Any idea whats wrong? I think I’m really close to the solution, but I just need some more help :)

            1 Reply Last reply Reply Quote 0
            • L Offline
              Leone510es
              last edited by

              @mochman Something happened :) After I submitted the post 2 minutes ago, I went back to the MagicMirror and…look :)
              0_1521366334598_mmirror2.jpg

              So I think after a few minutes, the processWeather: function() updated itself, and could display the correct value.
              But still, do you think we can make it work so it will display the correct value at first run?

              1 Reply Last reply Reply Quote 0
              • mochmanM Offline
                mochman Module Developer
                last edited by

                Well I’m glad it started mostly working. Sorry about the array of weather I was talking about earlier. I though you were using the weatherforecast module to get this info, not currentweather. The way you’re describing the issue, it sounds like the updateDOM() function is getting called before that value is set. Where in the processWeather() function did you put this.desc = data.weather[0].description;? is it before this section?

                this.show(this.config.animationSpeed, {lockString:this.identifier});
                this.loaded = true;
                this.updateDom(this.config.animationSpeed);
                this.sendNotification("CURRENTWEATHER_DATA", {data: data});
                
                L 1 Reply Last reply Reply Quote 0
                • L Offline
                  Leone510es @mochman
                  last edited by

                  @mochman Ohhh you are sooo right!! I messed up the code, the declaration was after the updateDom function. I moved it before the function, and now it’s wooorkiiing!!! :)
                  Thank You Soooo much! I’m very happy now that it’s working like a charm :)

                  1 Reply Last reply Reply Quote 0
                  • mochmanM Offline
                    mochman Module Developer
                    last edited by

                    Glad to hear it.

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