MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.24.0 is available! For more information about this release, check out this topic.

    Electricity Bill Module Development

    Utilities
    3
    19
    841
    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.
    • S
      SopaMaruchan last edited by

      Hi there!
      I’m developing a new module for a Magic Mirror to display Electricity Bill data but I’m struggling with something. The thing is that I consume an API which requires Bearer Token as an authentication to retrieve the data. I handle it using a node_helper file, but the thing is that I only get to display the data on the console but not visually on screen: 3001fe30-5cfb-4a4a-923e-f6c58e949e3e-image.png
      How can I send that data from node_helper to my MMM-CFE and place it on a meter element?
      MMM-CFE:
      24a3f6b7-560e-445d-af1a-ed6011281f2a-image.png
      node_helper:
      49c33b4e-73f8-4b3c-ae4f-d6ff6849228f-image.png
      Thought of socketNotification but I couldn’t figure it out, any ideas?

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

        @SopaMaruchan get data from API

        let’s call the object foo

        then

        this.sendSocketNotification(“fribble”, foo)

        then on the module side

          receiveSocketNotification(code, data){
                  if(code === 'fribble'){
                         this.savePointer = data
                         this.updateDom()
                  }
           }
        

        then

              getDom(){
                       //  use  this.savePonter
              }
        

        Sam

        Create a working config
        How to add modules

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

          @sdetweil I named my retreived data as “foo” and then used sendSocketNotification as you previously told me but I got this as output:
          e9ba4fa8-aca0-4167-b503-ec9c105d2bb4-image.png
          I did it this way on my node_helper file (Highlighted the lines I added):
          c59c8d5a-fce8-46b6-8305-9454cad39dbf-image.png
          Did I missed anything?

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

            @SopaMaruchan ah, so much fun!

            you are inside the callback of the request,so ‘this’ I pointing to some request object and not the node_helper instance…

            sooooo

            before request(…

            add
            let self = this

            and change this. to self.

            object oriented programming is tricky

            Sam

            Create a working config
            How to add modules

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

              @SopaMaruchan and {foo} is unnecessary

              you could just use
              res.body

              it’s the same stuff, why waste memory w a new pointer only being used once

              (same w info there too)

              Sam

              Create a working config
              How to add modules

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

                @sdetweil Hahahaha true that!
                Kinda fixed it guided by your recommendations but the thing is that I’m still getting the same output: 098fca99-2a82-4ccd-8758-b81dcaedc3b6-image.png
                Here the code:
                80366fb7-a775-46ea-a207-88b196b918cd-image.png

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

                  @SopaMaruchan hm…

                  sample from one of my modules

                  self.sendSocketNotification("SLEEP_HIDE")
                  

                  Sam

                  Create a working config
                  How to add modules

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

                    hmm, actually it does help. I’ll be testing around and tell you when I get it to work!
                    Anyways your help was a huge pilar to keep myself going with this, much thanks brother💝

                    S 1 Reply Last reply Reply Quote 0
                    • S
                      SopaMaruchan @SopaMaruchan last edited by

                      Does it help if I tell you that I got everything on my onstart function of the node_helper file?

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

                        @SopaMaruchan never done it in start.

                        I usually wait til the module sends it’s 1st request

                        Sam

                        Create a working config
                        How to add modules

                        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 Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy