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.

    Module Developer Challenge - I surrender!

    Scheduled Pinned Locked Moved Solved Development
    33 Posts 6 Posters 19.9k 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.
    • Mykle1M Offline
      Mykle1 Project Sponsor Module Developer
      last edited by

      Module Developer Challenge - Or anyone else

      I have been working on adding a url to an existing module of mine, namely,
      MMM-SunRiseSet. The url is to an image
      of a cylindrical projection of day and night across the Earth. If you open
      this url in a browser and refresh the page every so often, say 5 minutes, you
      can see the updated image, as day and night move across the map. Try it. This is what
      I have been trying to add to my module. It’s the perfect compliment to the data
      being presented.

      So what’s the problem, Mykle?

      The module loads. The data and the image from the url display as expected.
      I cannot get the url to refresh/update in the module. The initial load of the
      image from the url works fine but I’m stuck with that. Reloading MM gets the updated
      image but again, it doesn’t update after that. I guess I should mention that the url
      to the image is separate from the data. I don’t know if that matters.

      You’re not a real programmer, Mykle!

      That is so true. I am the first to admit it but I do enjoy making modules with the
      little bit of knowledge that I’ve learned in 10 months. 11 months ago I didn’t know
      what Linux or a Raspberry Pi was. I only started learning to impress my son. You
      guys are the real geniuses.

      I am humble

      It is with the utmost humility that I ask for your assistance. I do not ask for help
      lightly. I have tried for the better part of 4 days to figure this out but I am defeated.
      I’ll get over my embarrassment, eventually. I’m sure one of you will point out a simple
      mistake I’ve made or something I forgot to include.

      Peace

      Create a working config
      How to add modules

      ? 1 Reply Last reply Reply Quote 0
      • ? Offline
        A Former User @Mykle1
        last edited by A Former User

        @Mykle1
        This is not the result of deep-thought, but… In many cases, it might be related to the cache. So I suggest you try the traditional solution about this kind of problem.
        Add some random value to the url for refreshing cache when you try to load the new image like this.
        http://api.usno.navy.mil/imagery/earth.png?date=today&seed=[SomeRandomValue]

        However this might be not the solution, but I think it has worthy to try.

        strawberry 3.141S Mykle1M 2 Replies Last reply Reply Quote 3
        • strawberry 3.141S Offline
          strawberry 3.141 Project Sponsor Module Developer @Guest
          last edited by

          @Sean actually the problem starts even before the cache. the way magicmirror is designed in the update module function is, that it will only rerender if there was something changed in the dom. But your solution should still fix the problem.

          Another similar way would be to put a “seed” to the dom element itself insetad of the url, as i suggested in the iframe reload module, which fixed the reload problem there.

          after line 147

          img.setAttribute("timestamp", new Date().getTime());
          

          which will create an dom element like:

          < img class="photo" timestamp="1508693514656" src="http://api.usno.navy.mil/imagery/earth.png?date=today" />
          

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

          Mykle1M 1 Reply Last reply Reply Quote 2
          • Mykle1M Offline
            Mykle1 Project Sponsor Module Developer
            last edited by

            @Sean
            @strawberry 3.141

            Oh hey, thanks to you both. I just got in from my daughter’s. I was playing with my grandchildren. I will give those a try right now. You guys are awesome!

            I’ll post back with my results.

            Create a working config
            How to add modules

            1 Reply Last reply Reply Quote 0
            • Mykle1M Offline
              Mykle1 Project Sponsor Module Developer @Guest
              last edited by Mykle1

              @Sean said in Module Developer Challenge - I surrender!:

              http://api.usno.navy.mil/imagery/earth.png?date=today&seed=[SomeRandomValue]

              Hi Sean,

              I tried your suggestion first as yours was the first suggestion.

              I added a var for random number between 1 and 99

              var randomNumber = Math.floor(Math.random() * 99);
              

              And inserted that into the url

              img.src = "http://api.usno.navy.mil/imagery/earth.png?date=today&seed=" + randomNumber;
              

              Console log reporting that the random number is being generated

              http://api.usno.navy.mil/imagery/earth.png?date=today&seed=16
              MMM-SunRiseSet.js:157 http://api.usno.navy.mil/imagery/earth.png?date=today&seed=5
              MMM-SunRiseSet.js:157 http://api.usno.navy.mil/imagery/earth.png?date=today&seed=75
              MMM-SunRiseSet.js:157 http://api.usno.navy.mil/imagery/earth.png?date=today&seed=31
              MMM-SunRiseSet.js:157 http://api.usno.navy.mil/imagery/earth.png?date=today&seed=12
              MMM-SunRiseSet.js:157 http://api.usno.navy.mil/imagery/earth.png?date=today&seed=16
              

              Many thanks to you, Sean. The module IS updating now!

              Now, on to try @strawberry’s suggestion!

              EDIT
              I set the above to run on my MacBuntu laptop running MM so I could monitor it. It was updating nicely for a while but then something odd happened. An update resulted in an earlier image being loaded. I think this is because random numbers between 1 - 99 will at some point choose the same number.

              I’ll continue to work on it. I have an idea!

              Create a working config
              How to add modules

              ? 1 Reply Last reply Reply Quote 0
              • ? Offline
                A Former User @Mykle1
                last edited by

                @Mykle1 I think 99 is somehow too small. Use bigger values or timestamp for preventing duplicated.

                Mykle1M 1 Reply Last reply Reply Quote 1
                • Mykle1M Offline
                  Mykle1 Project Sponsor Module Developer @Guest
                  last edited by

                  @Sean said in Module Developer Challenge - I surrender!:

                  I think 99 is somehow too small. Use bigger values or timestamp for preventing duplicated.

                  Yes, see the edit to my post. I was writing that as you posted.

                  I’ll report back

                  Create a working config
                  How to add modules

                  1 Reply Last reply Reply Quote 0
                  • Mykle1M Offline
                    Mykle1 Project Sponsor Module Developer @strawberry 3.141
                    last edited by

                    @strawberry-3.141

                    So, after having tried Sean’s suggestion I realized my mistake in using a random number instead of timestamp. As I was about to try your suggestion I realized that I could use a part of Sean’s suggestion and a part of your suggestion.

                    I had already set up a var for random numbers, so I changed that to var getTimeStamp = new Date().getTime(); which was your idea added to Sean’s idea of a random value. A quick check in the console showed me it was working.

                    http://api.usno.navy.mil/imagery/earth.png?date=today&seed=1508717386975
                    MMM-SunRiseSet.js:166 http://api.usno.navy.mil/imagery/earth.png?date=today&seed=1508717686862
                    MMM-SunRiseSet.js:166 http://api.usno.navy.mil/imagery/earth.png?date=today&seed=1508717686866
                    MMM-SunRiseSet.js:166 http://api.usno.navy.mil/imagery/earth.png?date=today&seed=1508717987939
                    MMM-SunRiseSet.js:166 http://api.usno.navy.mil/imagery/earth.png?date=today&seed=1508717987944
                    MMM-SunRiseSet.js:166 http://api.usno.navy.mil/imagery/earth.png?date=today&seed=1508718287819
                    MMM-SunRiseSet.js:166 http://api.usno.navy.mil/imagery/earth.png?date=today&seed=1508718287823
                    

                    Then a simple edit to the url which was kinda, sorta, like the ideas you both had.

                    img.src = "http://api.usno.navy.mil/imagery/earth.png?date=today&seed=" + getTimeStamp;
                    

                    And BOOM! Success! I’ll leave it running all night and check it in the morning but I don’t foresee any problems

                    So, thank you Strawberry and thank you Sean. You guys are truly amazing!!!

                    Commence embarrassment recovery

                    Create a working config
                    How to add modules

                    1 Reply Last reply Reply Quote 0
                    • Mykle1M Offline
                      Mykle1 Project Sponsor Module Developer
                      last edited by

                      So far, so good. I have it running on my MacBuntu laptop. Here is a 2 frame animation so you get the idea. Obviously, there are quite a few updates absent from the gif and the shadow will move much more slowly and not jump across the planet. hehe
                      0_1508726003023_1.gif

                      Create a working config
                      How to add modules

                      1 Reply Last reply Reply Quote 0
                      • Mykle1M Offline
                        Mykle1 Project Sponsor Module Developer
                        last edited by

                        I am happy to report that the module ran for the last 11 hours without a hitch. The visual image shows day and night exactly where it should.

                        Create a working config
                        How to add modules

                        1 Reply Last reply Reply Quote 3
                        • Mykle1M Offline
                          Mykle1 Project Sponsor Module Developer
                          last edited by

                          I find myself in a similar situation, again. :-)

                          This is my cry for help. I only do this when I’ve tried all the things I know
                          and googled the things I don’t know. I’ve even tried free form improvising but coding
                          seems to reject that sort of thing, at least in my case.

                          About 2 weeks ago I wrote a module that gets system stats from a PC board running
                          ubuntu and MM. There is just one more thing that I want to include. I want to get the system
                          temperature (CPU?) and/or the temps of any other system components.

                          So, it is with the utmost humility that I ask for your help, suggestions or directions. I won’t
                          object to any modifications that anyone cares to make, if that is the case. If it can’t be done,
                          I can live with that, too. Even if you look at the module and never make any comments regarding
                          my request, I still thank you for your time and interest.

                          https://github.com/mykle1/MMM-PC-Stats

                          Peace

                          Create a working config
                          How to add modules

                          N 1 Reply Last reply Reply Quote 0
                          • N Offline
                            ninjabreadman @Mykle1
                            last edited by ninjabreadman

                            @Mykle1 It doesn’t seem that pc-stats has all the info you require. You might consider switching to the systeminformation package.

                            You can then use si.cpu() for your CPU stats and si.cpuTemperature() to retrieve an object that (if I read the docs right) looks like { main: 0, max: 0, cores: [0, 0] } with your core temps. You can then combine the two responses (or you may be able to have it return all within one request) and return those in a single sendNotification() call.

                            Problem with config or JavaScript? Copy/paste it into JSHint.
                            Check out the detailed walkthroughs on install, config, modules, etc.

                            Mykle1M 1 Reply Last reply Reply Quote 1
                            • Mykle1M Offline
                              Mykle1 Project Sponsor Module Developer @ninjabreadman
                              last edited by

                              @ninjabreadman

                              You know, I started out with that package but had some trouble with it. Likely, the problem was me, but I moved to the pc-stats package and had no problems. However, as you saw, that package doesn’t offer the cpu temps. I then tried unsuccessfully to use other packages along with pc-stats to get the temps but my knowledge and abilities are woefully inadequate. For whatever reason, I was able to get a return from pc-stats. That’s no small miracle where I’m concerned. I do like the data that the return gives me, especially the multicore support.

                              Anyway, I did give it more than a few days and more than a few attempts but I will look at systeminformation again in the hopes that I can stumble across some success. Really, I am not qualified to be doing any of this. I just find it so fascinating that I keep trying until I get something right. And then there are the few special people that have taken pity on me and taught me what I needed to know at any given moment. They have my deepest gratitude and respect.

                              Thanks for pointing me back to where I should have been all along. :-)

                              Create a working config
                              How to add modules

                              N 1 Reply Last reply Reply Quote 0
                              • N Offline
                                ninjabreadman @Mykle1
                                last edited by

                                @Mykle1 Depending on the style/implementation you’re using, you may want to read up on Promises in JS.

                                Also, see this note here about the lm-sensors package.

                                Alternatively, have a look at MMM-SystemStats which uses vcgencmd on the CLI to retrieve the system temp, which would be far easier to integrate into your current module.

                                Problem with config or JavaScript? Copy/paste it into JSHint.
                                Check out the detailed walkthroughs on install, config, modules, etc.

                                Mykle1M 1 Reply Last reply Reply Quote 1
                                • Mykle1M Offline
                                  Mykle1 Project Sponsor Module Developer @ninjabreadman
                                  last edited by

                                  @ninjabreadman said in Module Developer Challenge - I surrender!:

                                  Alternatively, have a look at MMM-SystemStats which uses vcgencmd on the CLI to retrieve the system temp, which would be far easier to integrate into your current module.

                                  Thanks ninja. I will give this a shot first. In fact, I’m going to look at that right now.

                                  Create a working config
                                  How to add modules

                                  N 1 Reply Last reply Reply Quote 1
                                  • N Offline
                                    ninjabreadman @Mykle1
                                    last edited by ninjabreadman

                                    @Mykle1 Hmm, it may be that vcgencmd is specific to the RPi. You can try these; acpi seems like a contender, as does lm-sensors.

                                    Problem with config or JavaScript? Copy/paste it into JSHint.
                                    Check out the detailed walkthroughs on install, config, modules, etc.

                                    Mykle1M 2 Replies Last reply Reply Quote 0
                                    • Mykle1M Offline
                                      Mykle1 Project Sponsor Module Developer @ninjabreadman
                                      last edited by

                                      @ninjabreadman said in Module Developer Challenge - I surrender!:

                                      Hmm, it may be that vcgencmd is specific to the RPi.

                                      Ha! I see. Ok, on to the others. :-)

                                      Create a working config
                                      How to add modules

                                      N 1 Reply Last reply Reply Quote 0
                                      • N Offline
                                        ninjabreadman @Mykle1
                                        last edited by

                                        @Mykle1 It actually might be best to run cat /sys/class/thermal/thermal_zone*/type to see if they’re already populating on your Ubuntu install. If so, you can run cat /sys/class/thermal/thermal_zone*/temp to get all the values, or just cat a specific one. Should be to three decimal places (i.e. 64000 means 64.000°C).

                                        You might run it a few times to see that the values change, and if they do, then use the same exec() method from MMM-SystemStats with the right command and some math.

                                        Problem with config or JavaScript? Copy/paste it into JSHint.
                                        Check out the detailed walkthroughs on install, config, modules, etc.

                                        1 Reply Last reply Reply Quote 0
                                        • Mykle1M Offline
                                          Mykle1 Project Sponsor Module Developer @ninjabreadman
                                          last edited by

                                          @ninjabreadman said in Module Developer Challenge - I surrender!:

                                          acpi seems like a contender, as does lm-sensors.

                                          Made some progress with lm-sensors which gives me great hope. I can see the return in the terminal but not in the node_helper. Still, I’m encouraged. I’ll continue to work on it tomorrow. I’m feeling a bit tired tonight.

                                          Sockets connected & modules started ...
                                          Launching application.
                                          { 'nouveau-pci-0100': { 'PCI adapter': { temp1: [Object] } },
                                            'coretemp-isa-0000': 
                                             { 'ISA adapter': 
                                                { 'Core 0': [Object],
                                                  'Core 1': [Object],
                                                  'Core 2': [Object],
                                                  'Core 3': [Object] } } }
                                          Whoops! There was an uncaught exception...
                                          TypeError: this.sendSocketNotification is not a function
                                              at /home/pop/MagicMirror/modules/MMM-PC-Stats/node_helper.js:32:9
                                              at /home/pop/MagicMirror/modules/MMM-PC-Stats/node_modules/sensors.js/lm-sensors.js:96:12
                                              at ChildProcess.exithandler (child_process.js:209:7)
                                              at emitTwo (events.js:106:13)
                                              at ChildProcess.emit (events.js:194:7)
                                              at maybeClose (internal/child_process.js:899:16)
                                              at Socket. (internal/child_process.js:342:11)
                                              at emitOne (events.js:96:13)
                                              at Socket.emit (events.js:191:7)
                                              at Pipe._handle.close [as _onclose] (net.js:510:12)
                                          

                                          Create a working config
                                          How to add modules

                                          E 1 Reply Last reply Reply Quote 0
                                          • E Offline
                                            E3V3A @Mykle1
                                            last edited by

                                            @Mykle1 Not sure what you’re doing in your code. But…

                                            1. You’ll get a temp reading for each cpu core, so you need to choose|add|average…, and
                                            2. How do you execute the script? Did you give it proper permissions?
                                            3. I’m you already know, but you also need to allow the external file to be read from node_helper.js.

                                            "Everything I do (here) is for free – altruism is the way!"
                                            MMM-FlightsAbove, MMM-Tabulator, MMM-Assistant (co-maintainer)

                                            Mykle1M 1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 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