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.

    How to use the 'node_helper', 'serialport'

    Scheduled Pinned Locked Moved Development
    23 Posts 2 Posters 7.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.
    • S Offline
      sdetweil
      last edited by sdetweil

      @nhpunch said in How to use the 'node_helper', 'serialport':

         if(this._isPushed==false)
      

      where is _isPushed defined or set?

      i know it is in module_name.js, but node_helper cannot see it…

      you should send that as the payload on button_pressed message

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • N Offline
        nhpunch
        last edited by

        socketNotificationReceived: function (notification, payload) {
        
            if (notification === 'CONFIG') {
              const self = this;
              self.config = payload;
            }
            else if(notification ==='BUTTON_PRESSED')
            {
              this._isPushed = payload;
            var serialport = new Serialport('/dev/ttyACM0', {   
        		baudRate: 9600
        		});
        
        

        Is that right? I’m really sorry for you.

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

          @nhpunch yes if you send it that way

          this.sendSocketNotification(“BUTTON_PUSHED”,this._isPushed)

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          N 2 Replies Last reply Reply Quote 0
          • N Offline
            nhpunch @sdetweil
            last edited by

            @sdetweil

            0_1560202018149_2019-06-11-062442_1920x1080_scrot.png
            false, true works with two button in module

            It seems that the value can not be sent to the node_helper

            why?

            	buttonoff.addEventListener('click', ()=> {
            			Log.log("button pushed 'on'")
               			this._isPushed = false;
            			console.log(this._isPushed);
               	});
            	button.addEventListener('click', ()=> {
            			Log.log("button pushed 'off' ")
               			this._isPushed = true;
            			console.log(this._isPushed);
               	});
            

            this is module

                      serialport.write(this._isPushed==true? '1' : '0');
            

            this is node_helper

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

              @sdetweil

                  else if(notification ==='BUTTON_PRESSED')
                  {
                    this._isPushed = payload;
                    console.log(payload);
              

              ‘false’ is displayed in the terminal window

              ._isPushed is passed to node_helper, but I think that the changed value is not sent when the button is pressed.

              Please advise…:folded_hands_light_skin_tone: :folded_hands_light_skin_tone: :folded_hands_light_skin_tone:

              If this is solved, it’s really a success.:flexed_biceps_light_skin_tone:

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

                @nhpunch said in How to use the 'node_helper', 'serialport':

                	buttonoff.addEventListener('click', ()=> {
                			Log.log("button pushed 'on'")
                   			this._isPushed = false;
                			console.log(this._isPushed);
                                        this.sendSocketNotification(“BUTTON_PUSHED”,this._isPushed)
                   	});
                 	 button.addEventListener('click', ()=> {
                 			Log.log("button pushed 'off' ")
                    			this._isPushed = true;
                 			console.log(this._isPushed);
                                        this.sendSocketNotification(“BUTTON_PUSHED”,this._isPushed)
                         });
                

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • N Offline
                  nhpunch
                  last edited by

                  0_1560203753373_2019-06-11-065545_1920x1080_scrot.png

                  ._isPushed was sent

                  but there was an error… im really sad

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

                    @nhpunch that is in the node_helper, serial library

                    looks like serialport.write(data: string|Buffer|Array,

                    i don’t know anything about serial port api… looks like promise based, so would need callbacks or .then()

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    N 1 Reply Last reply Reply Quote 0
                    • N Offline
                      nhpunch @sdetweil
                      last edited by

                      @sdetweil

                      omg… I’m so screwed up

                      My ignorantness makes me cry…'ㅠ I don’t know why there was a mistake

                      Thank you @sdetweil You’re awesome!

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