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.

    Problem Adding Buttons & required Remote-Control Modules

    Scheduled Pinned Locked Moved Solved Troubleshooting
    26 Posts 4 Posters 4.0k Views 4 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 Do not disturb
      sdetweil @awwbaker
      last edited by

      @awwbaker on the write

      see second post here

      https://forums.raspberrypi.com/viewtopic.php?t=367431

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      A 1 Reply Last reply Reply Quote 0
      • A Offline
        awwbaker @sdetweil
        last edited by

        Dear Mr @sdetweil
        I think you are teaching me to fish…Did you see the error message below? Beyond the below, I booted the RPI 3B+, ran the “pinctrl set 6 op dl” command. Started MM and as previously the expected modules were hidden on start up. Pressing pushbutton did not have any affect on the display. I ran the button.py script and the button was sensed as previous. As your time permits I could use another push. Your efforts are VERY appreciated. VR Anthony Baker

        2024-09-21 13:33:31.232] [LOG] Connecting socket for: MMM-MktIndex
        [2024-09-21 13:33:31.234] [LOG] Sockets connected & modules started …
        [1856:0921/133334.081312:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.DBus.StartServiceByName: object_path= /org/freedesktop/DBus: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
        [2024-09-21 13:33:35.622] [LOG] Launching application.
        [2024-09-21 13:33:55.076] [INFO] System information:

        SYSTEM: manufacturer: ; model: ; raspberry: undefined; virtual: false

        OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: arm64; kernel: 6.6.47+rpt-rpi-v8

        VERSIONS: electron: 31.1.0; used node: 20.14.0; installed node: 22.9.0; npm: 10.8.3; pm2:

        OTHER: timeZone: America/New_York; ELECTRON_ENABLE_GPU: undefined

        [2024-09-21 13:33:58.321] [ERROR] Whoops! There was an uncaught exception…
        [2024-09-21 13:33:58.343] [ERROR] Error: EINVAL: invalid argument, write
        at Object.writeFileSync (node:fs:2346:20)
        at exportGpio (/home/awwbaker/MagicMirror/modules/MMM-ModuleToggleButton/node_modules/onoff/onoff.js:18:8)
        at new Gpio (/home/awwbaker/MagicMirror/modules/MMM-ModuleToggleButton/node_modules/onoff/onoff.js:172:36)
        at Class.socketNotificationReceived (/home/awwbaker/MagicMirror/modules/MMM-ModuleToggleButton/node_helper.js:20:22)
        at Socket. (/home/awwbaker/MagicMirror/js/node_helper.js:98:11)
        at Socket.emit (node:events:519:28)
        at Socket.emitUntyped (/home/awwbaker/MagicMirror/node_modules/socket.io/dist/typed-events.js:69:22)
        at /home/awwbaker/MagicMirror/node_modules/socket.io/dist/socket.js:704:39
        at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
        errno: -22,
        code: ‘EINVAL’,
        syscall: ‘write’
        }
        [2024-09-21 13:33:58.345] [ERROR] MagicMirror² will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
        [2024-09-21 13:33:58.347] [ERROR] If you think this really is an issue, please open an issue on GitHub: https://github.com/MagicMirrorOrg/MagicMirror/issues
        [1976:0921/133401.533219:ERROR:gl_utils.cc(424)] [.WebGL-0x34004b5b00]GL Driver Message (OpenGL, Performance, GL_CLOSE_PATH_NV, High): GPU stall due to ReadPixels
        [2024-09-21 13:34:01.636] [LOG] Create new calendarfetcher for url: http://p134-caldav.icloud.com/published/2/ODY3MDc3ODQxODY3MDc3OIsPCPqyTd7gfFTuhUgnU3E8veSROaMD9lC0bXMqbeTrcdUcRFgL2q0GROkcc6XtdbepSRYxUGbDtoDb3se2UkE - Interval: 604800000

        S 1 Reply Last reply Reply Quote 0
        • S Do not disturb
          sdetweil @awwbaker
          last edited by sdetweil

          @awwbaker i am on my phone, i can’t edit, and it wants to quote whole thing .

          the os has changed the rules

          i posted a response the other day to a topic that had some workarounds without coding changes

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          A 1 Reply Last reply Reply Quote 0
          • A Offline
            awwbaker @sdetweil
            last edited by

            Dear Mr @sdetweil
            Please see above, it seems “on-off” is throwing errors. It seems it is used by Remote-Control-Modules as well as Buttons. I wnet back and tried buttons. The error is below: Thank you very much. Anthony

            [2024-09-22 11:34:50.557] [LOG] Launching application.
            [2024-09-22 11:35:05.029] [ERROR] ERROR! Could not validate main module js file.
            [2024-09-22 11:35:05.037] [ERROR] ReferenceError: Log is not defined
            at Object. (/home/awwbaker/MagicMirror/modules/MMM-RAIN-MAP/MMM-RAIN-MAP.js:28:158622)
            at Module._compile (node:internal/modules/cjs/loader:1373:14)
            at Module._extensions…js (node:internal/modules/cjs/loader:1432:10)
            at Module.load (node:internal/modules/cjs/loader:1215:32)
            at Module._load (node:internal/modules/cjs/loader:1031:12)
            at c._load (node:electron/js2c/node_init:2:17025)
            at Module.require (node:internal/modules/cjs/loader:1240:19)
            at require (node:internal/modules/helpers:179:18)
            at Class.loadModuleDefaultConfig (/home/awwbaker/MagicMirror/modules/MMM-Remote-Control/node_helper.js:314:30)
            at /home/awwbaker/MagicMirror/modules/MMM-Remote-Control/node_helper.js:268:26
            at FSReqCallback.oncomplete (node:fs:198:5)
            [2024-09-22 11:35:05.689] [INFO] System information:

            SYSTEM: manufacturer: ; model: ; raspberry: undefined; virtual: false

            OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: arm64; kernel: 6.6.47+rpt-rpi-v8

            VERSIONS: electron: 31.1.0; used node: 20.14.0; installed node: 22.9.0; npm: 10.8.3; pm2:

            OTHER: timeZone: America/New_York; ELECTRON_ENABLE_GPU: undefined

            [2024-09-22 11:35:13.286] [LOG] Initialize button monitor_control on PIN 6
            [2024-09-22 11:35:13.293] [ERROR] Whoops! There was an uncaught exception…
            [2024-09-22 11:35:13.318] [ERROR] Error: EINVAL: invalid argument, write
            at Object.writeFileSync (node:fs:2346:20)
            at exportGpio (/home/awwbaker/MagicMirror/modules/MMM-Buttons/node_modules/onoff/onoff.js:18:8)
            at new Gpio (/home/awwbaker/MagicMirror/modules/MMM-Buttons/node_modules/onoff/onoff.js:172:36)
            at Class.intializeButton (/home/awwbaker/MagicMirror/modules/MMM-Buttons/node_helper.js:74:19)
            at Class.intializeButtons (/home/awwbaker/MagicMirror/modules/MMM-Buttons/node_helper.js:90:18)
            at Class.socketNotificationReceived (/home/awwbaker/MagicMirror/modules/MMM-Buttons/node_helper.js:26:18)
            at Socket. (/home/awwbaker/MagicMirror/js/node_helper.js:98:11)
            at Socket.emit (node:events:519:28)
            at Socket.emitUntyped (/home/awwbaker/MagicMirror/node_modules/socket.io/dist/typed-events.js:69:22)
            at /home/awwbaker/MagicMirror/node_modules/socket.io/dist/socket.js:704:39
            at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
            errno: -22,
            code: ‘EINVAL’,
            syscall: ‘write’
            }
            [2024-09-22 11:35:13.335]

            S 1 Reply Last reply Reply Quote 0
            • S Do not disturb
              sdetweil @awwbaker
              last edited by

              @awwbaker yes as i posted before

              errno: -22,
              code: ‘EINVAL’,
              syscall: ‘write’
              }

              the os has changed how this needs to be done
              i posted a link to suggestions on how to resolve it without code changes

              the Log not found is caused by the remotecontrol module

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              A 1 Reply Last reply Reply Quote 0
              • A Offline
                awwbaker @sdetweil
                last edited by

                Thank you, I tried the pinctrl to no avail. Thank you though! Anthony

                S 1 Reply Last reply Reply Quote 0
                • S Do not disturb
                  sdetweil @awwbaker
                  last edited by

                  @awwbaker did you solve this?

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  A 1 Reply Last reply Reply Quote 0
                  • A Offline
                    awwbaker @sdetweil
                    last edited by sdetweil

                    @sdetweil Sorry have been on travel last several weeks. No I never did. I have the remote control module in and working just never could not get the button push. I have mmm-GroveGesture installed and working with sensor. Still working towards getting modules to hide and show. Could I ask another question???

                    What can/should I do on this?:

                    [2024-10-28 10:10:15.299] [ERROR] ERROR! Could not validate main module js file. 
                    [2024-10-28 10:10:15.528] [ERROR] ReferenceError: Log is not defined
                        at Object.<anonymous> (/home/awwbaker/MagicMirror/modules/MMM-RAIN-MAP/MMM-RAIN-MAP.js:28:158622)
                        at Module._compile (node:internal/modules/cjs/loader:1484:14)
                        at Module._extensions..js (node:internal/modules/cjs/loader:1564:10)
                        at Module.load (node:internal/modules/cjs/loader:1295:32)
                        at Module._load (node:internal/modules/cjs/loader:1111:12)
                        at c._load (node:electron/js2c/node_init:2:17025)
                        at Module.require (node:internal/modules/cjs/loader:1318:19)
                        at require (node:internal/modules/helpers:179:18)
                        at Class.loadModuleDefaultConfig (/home/awwbaker/MagicMirror/modules/MMM-Remote-Control/node_helper.js:318:30)
                        at /home/awwbaker/MagicMirror/modules/MMM-Remote-Control/node_helper.js:272:26
                        at FSReqCallback.oncomplete (node:fs:198:5) 
                    
                    ----------------------------------------------------
                    
                    S 1 Reply Last reply Reply Quote 0
                    • S Do not disturb
                      sdetweil @awwbaker
                      last edited by

                      @awwbaker remote control is loading the main js from other modules, but in the wrong runtime context.

                      i don’t know why it is doing that

                      Sam

                      How to add modules

                      learning how to use browser developers window for css changes

                      A 1 Reply Last reply Reply Quote 0
                      • A Offline
                        awwbaker @sdetweil
                        last edited by

                        @sdetweil ,
                        Hmmm…thanks Sam!!!

                        1 Reply Last reply Reply Quote 0
                        • C Offline
                          ChrisLeduex
                          last edited by

                          Hi guys, I’ve been trying to figure this out too. I think I’m close with these two files using ‘pinctrl’ instead of ‘/sys/class/gpio/’ but I can’t figure out what I’m missing.

                          Based on the console log it looks like there’s an issue in my node_helper file, possible with the socketNotification functions because I’m not seeing any of my test messages.

                          And based on the log files there may be something missing from the package.json file because sometimes I get this error “Error: Cannot find module ‘node helper’ MODULE_NOT_FOUND” but other times I don’t. And I tried running this fix but couldn’t get it to work.
                          [https://forum.magicmirror.builders/user/jorickjuh](link url)

                          Other than that I’m not seeing any other errors and module does appear to be working but it’s just not processing any button presses. I’ll keep trying but I’ll post my progress so far on here in case someone can see what I’m missing.

                          test file:

                          Module.register("MMM-PinToggleTest", {
                            defaults: {
                              pin: 19,
                              modulesToToggle: ["clock", "calendar"],
                              interval: 1000
                            },
                          
                          //consol.log("MMM-PinToggleTest is starting...");
                          
                            start: function() {
                              Log.info("MMM-PinToggleTest is starting, sending CONFIG...");
                              consol.log("MMM-PinToggleTest is starting, sending CONFIG...");
                              
                              this.sendSocketNotification("CONFIG", {
                                interval: this.config.interval,
                                pin: this.config.pin
                                });
                              },
                          
                            start: function() {
                              console.log("MMM-PinToggleTest started");
                              this.previousPinState = null;
                          
                              // Request initial pin check from the helper
                              this.sendSocketNotification("CONFIG", this.config);
                            },
                          
                            socketNotificationReceived: function(notification, payload) {
                              if (notification === "PIN_STATE") {
                                const pinState = payload;
                                console.log(`Received pin state: ${pinState}`);  // Log received state
                          
                                // Toggle modules based on pin state
                                if (pinState !== this.previousPinState) {
                                  this.previousPinState = pinState;
                                  this.toggleModules(pinState === 1);
                                }
                              }
                            },
                          
                            toggleModules: function(show) {
                              console.log(`Toggling modules to ${show ? "show" : "hide"}`);
                              this.config.modulesToToggle.forEach(moduleName => {
                                const modules = MM.getModules().withClass(moduleName);
                                modules.forEach(module => {
                                  if (show) {
                                    module.show(1000);  // Show module with fade-in effect
                                  } else {
                                    module.hide(1000);  // Hide module with fade-out effect
                                  }
                                });
                              });
                            },
                            
                          
                            getDom: function() {
                              const wrapper = document.createElement("div");
                              wrapper.innerHTML = "<small>MMM-PinToggleTest</small>";
                              return wrapper;
                            }
                          });
                          

                          node_helper:

                          const NodeHelper = require("node_helper");
                          const exec = require("child_process").exec;
                          //const rpio = require("rpio");
                          //const Gpio = require("onoff").Gpio;
                          
                          module.exports = NodeHelper.create({
                            start: function() {
                              console.log("node_helper for MMM-PinToggleTest has started.");  // Confirm helper initialization
                              this.previousPinState = null;
                              this.lastChangeTime = 0;
                              this.debounceDelay = 200;
                            },
                          
                            socketNotificationReceived: function(notification, payload) {
                              if (notification === "CONFIG") {
                                console.log("Received CONFIG in node_helper:", payload);  // Log receipt of configuration
                                this.config = payload;
                                this.schedulePinCheck();
                              }
                            },
                          
                            schedulePinCheck: function() {
                              console.log(`Setting up pin check every ${this.config.interval} ms`); // Confirmation log
                              setInterval(() => {
                                this.checkPinState();
                              }, this.config.interval);
                            },
                          
                            checkPinState: function() {
                              const pinNumber = this.config.pin;
                          
                              exec(`pinctrl ${pinNumber}`, (error, stdout, stderr) => {
                                if (error) {
                                  console.error(`Error reading GPIO pin ${pinNumber}: ${stderr}`);
                                  return;
                                }
                          
                                const pinState = parseInt(stdout.trim(), 10);
                                const now = Date.now();
                          
                                console.log(`Current pin state for GPIO ${pinNumber}: ${pinState}`);
                          
                                if (pinState !== this.previousPinState && (now - this.lastChangeTime > this.debounceDelay)) {
                                  this.previousPinState = pinState;
                                  this.lastChangeTime = now;
                          
                                  console.log(`Pin state changed to ${pinState} at ${new Date(now).toISOString()}`);
                                  this.sendSocketNotification("PIN_STATE", pinState);
                                  
                                  // Small delay to avoid multiple triggers
                                  //setTimeout(() => {}, 100);
                                }
                              });
                            }
                          });
                          
                          S 1 Reply Last reply Reply Quote 0
                          • S Do not disturb
                            sdetweil @ChrisLeduex
                            last edited by sdetweil

                            @ChrisLeduex well, you don’t have any source errors. altho you have 2 start: functions in the modulename.js

                            I see this as output of the pinctrl command on my pi 4

                             pinctrl
                             0: ip    pu | hi // ID_SDA/GPIO0 = input
                             1: ip    pu | hi // ID_SCL/GPIO1 = input
                             2: ip    pu | hi // GPIO2 = input
                             3: ip    pu | hi // GPIO3 = input
                             4: ip    pu | hi // GPIO4 = input
                             5: ip    pu | hi // GPIO5 = input
                             6: ip    pu | hi // GPIO6 = input
                             7: ip    pu | hi // GPIO7 = input
                             8: ip    pu | hi // GPIO8 = input
                             9: ip    pd | lo // GPIO9 = input
                            10: ip    pd | lo // GPIO10 = input
                            11: ip    pd | lo // GPIO11 = input
                            12: ip    pd | lo // GPIO12 = input
                            13: ip    pd | lo // GPIO13 = input
                            14: ip    pn | hi // GPIO14 = input
                            15: ip    pu | hi // GPIO15 = input
                            16: ip    pd | lo // GPIO16 = input
                            17: ip    pd | lo // GPIO17 = input
                            18: ip    pd | lo // GPIO18 = input
                            19: ip    pd | lo // GPIO19 = input
                            20: ip    pd | lo // GPIO20 = input
                            21: ip    pd | lo // GPIO21 = input
                            22: ip    pd | lo // GPIO22 = input
                            23: ip    pd | lo // GPIO23 = input
                            24: ip    pd | lo // GPIO24 = input
                            25: ip    pd | lo // GPIO25 = input
                            26: ip    pd | lo // GPIO26 = input
                            27: ip    pd | lo // GPIO27 = input
                            28: a5    pu | hi // RGMII_MDIO/GPIO28 = RGMII_MDIO
                            29: a5    pd | lo // RGMIO_MDC/GPIO29 = RGMII_MDC
                            30: a3    pu | lo // CTS0/GPIO30 = CTS0
                            31: a3    pn | lo // RTS0/GPIO31 = RTS0
                            32: a3    pn | hi // TXD0/GPIO32 = TXD0
                            33: a3    pu | hi // RXD0/GPIO33 = RXD0
                            34: a3    pn | hi // SD1_CLK/GPIO34 = SD1_CLK
                            35: a3    pu | hi // SD1_CMD/GPIO35 = SD1_CMD
                            36: a3    pu | hi // SD1_DATA0/GPIO36 = SD1_DAT0
                            37: a3    pu | hi // SD1_DATA1/GPIO37 = SD1_DAT1
                            38: a3    pu | hi // SD1_DATA2/GPIO38 = SD1_DAT2
                            39: a3    pu | hi // SD1_DATA3/GPIO39 = SD1_DAT3
                            40: a0    pn | lo // PWM0_MISO/GPIO40 = PWM1_0
                            41: a0    pn | lo // PWM1_MOSI/GPIO41 = PWM1_1
                            42: op -- pu | lo // STATUS_LED_G_CLK/GPIO42 = output
                            43: ip    pu | hi // SPIFLASH_CE_N/GPIO43 = input
                            44: ip    pu | hi // SDA0/GPIO44 = input
                            45: ip    pu | hi // SCL0/GPIO45 = input
                            46: ip    pu | lo // RGMII_RXCLK/GPIO46 = input
                            47: ip    pu | lo // RGMII_RXCTL/GPIO47 = input
                            48: ip    pd | lo // RGMII_RXD0/GPIO48 = input
                            49: ip    pd | lo // RGMII_RXD1/GPIO49 = input
                            50: ip    pd | lo // RGMII_RXD2/GPIO50 = input
                            51: ip    pd | lo // RGMII_RXD3/GPIO51 = input
                            52: ip    pd | lo // RGMII_TXCLK/GPIO52 = input
                            53and : ip    pd | lo // RGMII_TXCTL/GPIO53 = input
                            

                            and this for output of pinctrl 19

                            19: ip    pd | lo // GPIO19 = input
                            

                            so the “pinctrl 19” command and parseInt(“19: ip pd | lo // GPIO19 = input”, 10);
                            will return 19

                            I think you meant pinctrl get 19, after sometime prior doing pinctrl set

                            pinctrl help
                            shows all it can do

                            Sam

                            How to add modules

                            learning how to use browser developers window for css changes

                            C 1 Reply Last reply Reply Quote 0
                            • C Offline
                              ChrisLeduex @sdetweil
                              last edited by

                              @sdetweil Thank you for catching those, too much copying and pasting.

                              Removed one of the start functions from the module.js file and also updated this line in the node_helper.js file so now it is returning the pin state instead of the pin number.
                              //const pinState = parseInt(stdout.trim(), 10);
                              const pinState = stdout.includes(“hi”) ? 1 : 0;

                              There still seems to be an issue somewhere in my node_helper.js file though because I’m still not seeing anything from that file in the console. Looking through the forum it seems node_helper file issues are common and I’ve tried implementing a few of the solutions I found there but still haven’t found the problem but I will keep trying. I suspect maybe I’m not nesting my socket notifications correctly.

                              PinToggleTest.js

                              Module.register("MMM-PinToggleTest", {
                                defaults: {
                                  pin: 19,
                                  modulesToToggle: ["clock", "calendar"],
                                  interval: 1000
                                },
                              
                                start: function() {
                                  console.log("MMM-PinToggleTest started");
                                  Log.info("MMM-PinToggleTest is starting, sending CONFIG...");
                                  this.previousPinState = null;
                              
                                  // Request initial pin check from the helper
                                  this.sendSocketNotification("CONFIG", this.config);
                                },
                                
                                socketNotificationReceived: function(notification, payload) {
                              		if (notification === 'STARTED') {
                                  console.log("STARTED notification received from node_helper");
                                  this.config.text = 'Started';
                                  this.updateDom();
                              		}
                              	},
                              
                                socketNotificationReceived: function(notification, payload) {
                                  if (notification === "PIN_STATE") {
                                    const pinState = payload;
                                    console.log(`Received pin state: ${pinState}`);  // Log received state
                              
                                    // Toggle modules based on pin state
                                    if (pinState !== this.previousPinState) {
                                      this.previousPinState = pinState;
                                      this.toggleModules(pinState === 1);
                                    }
                                  }
                                },
                              
                                toggleModules: function(show) {
                                  console.log(`Toggling modules to ${show ? "show" : "hide"}`);
                                  this.config.modulesToToggle.forEach(moduleName => {
                                    const modules = MM.getModules().withClass(moduleName);
                                    modules.forEach(module => {
                                      if (show) {
                                        module.show(1000);  // Show module with fade-in effect
                                      } else {
                                        module.hide(1000);  // Hide module with fade-out effect
                                      }
                                    });
                                  });
                                },
                              
                                getDom: function() {
                                  const wrapper = document.createElement("div");
                                  wrapper.innerHTML = "<small>MMM-PinToggleTest</small>";
                                  return wrapper;
                                }
                              });
                              

                              node_helper.js

                              const NodeHelper = require("node_helper");
                              const exec = require("child_process").exec;
                              //const rpio = require("rpio");
                              //const Gpio = require("onoff").Gpio;
                              
                              //module.exports = NodeHelper.create({
                              //  start: function() {
                              //    console.log("Starting node_helper for MMM-PinToggleTest");
                              //    this.previousPinState = null;
                              //    this.config = null;
                              //  },
                              
                              module.exports = NodeHelper.create({
                                start() {
                                  this.started = false;
                                },
                              
                                socketNotificationReceived: function(notification, payload) {
                                  if (notification === "CONFIG" && !this.started) {
                                    const self = this;
                                    console.log("CONFIG notification received");
                                    this.config = payload;
                                    this.schedulePinCheck();
                                    this.sendSocketNotification('STARTED', {message: 'test'});
                                    console.log("STARTED notification sent back to front end");
                                  }
                                },
                              
                                schedulePinCheck: function() {
                                  console.log(`Setting up pin check every ${this.config.interval} ms`);
                                  setInterval(() => {
                                    this.checkPinState();
                                  }, this.config.interval);
                                },
                              
                                checkPinState: function() {
                                  const pinNumber = this.config.pin;
                              
                                  // Execute pinctrl command
                                  exec(`pinctrl get ${pinNumber}`, (error, stdout, stderr) => {
                                    if (error) {
                                      console.error(`Error reading GPIO pin ${pinNumber}: ${stderr}`);
                                      return;
                                    }
                              
                                    //const pinState = parseInt(stdout.trim(), 10);
                                    const pinState = stdout.includes("hi") ? 1 : 0;
                                    console.log(`Detected pin state for pin ${pinNumber}: ${pinState}`);  // Log the detected state
                              
                                    // Only send if state has changed
                                      if (pinState !== this.previousPinState) {
                                      this.previousPinState = pinState;
                                      console.log(`Pin state changed to ${pinState}`);
                                      this.sendSocketNotification("PIN_STATE", pinState);
                                      
                                      // Small delay to avoid multiple triggers
                                      setTimeout(() => {}, 100);
                                    }
                                  });
                                }
                              });
                              
                              S 1 Reply Last reply Reply Quote 0
                              • S Do not disturb
                                sdetweil @ChrisLeduex
                                last edited by

                                @ChrisLeduex I see this from the output of npm start

                                [2024-11-05 12:32:28.225] [LOG]   Current pin state for GPIO 19: 1 
                                [2024-11-05 12:32:28.225] [LOG]   Pin state changed to 1 at 2024-11-05T18:32:28.224Z 
                                [2024-11-05 12:32:28.244] [INFO]  [MMM-MealieMenu] Week starts: 2024-11-04, next week starts: 2024-11-11 
                                [2024-11-05 12:32:28.375] [INFO]  Mealie error={} 
                                [2024-11-05 12:32:28.400] [INFO]  Newsfeed-Fetcher: Broadcasting 15 items. 
                                [2024-11-05 12:32:28.413] [INFO]  Newsfeed-Fetcher: Broadcasting 22 items. 
                                [2024-11-05 12:32:28.819] [INFO]  Newsfeed-Fetcher: reloadInterval set to ttl=5400000 for url http://www.tagesschau.de/xml/rss2 
                                [2024-11-05 12:32:28.847] [INFO]  Newsfeed-Fetcher: Broadcasting 40 items. 
                                [2024-11-05 12:32:29.225] [LOG]   Current pin state for GPIO 19: 1 
                                [2024-11-05 12:32:30.225] [LOG]   Current pin state for GPIO 19: 1 
                                [2024-11-05 12:32:31.225] [LOG]   Current pin state for GPIO 19: 1 
                                [2024-11-05 12:32:32.225] [LOG]   Current pin state for GPIO 19: 1 
                                [2024-11-05 12:32:33.224] [LOG]   Current pin state for GPIO 19: 1 
                                [2024-11-05 12:32:34.225] [LOG]   Current pin state for GPIO 19: 1 
                                [2024-11-05 12:32:35.226] [LOG]   Current pin state for GPIO 19: 1 
                                [2024-11-05 12:32:36.227] [LOG]   Current pin state for GPIO 19: 1 
                                [2024-11-05 12:32:37.229] [LOG]   Current pin state for GPIO 19: 1 
                                [2024-11-05 12:32:38.227] [LOG]   Current pin state for GPIO 19: 1 
                                

                                I wrote a little pinctrl script that just outputs 1

                                #!/bin/bash
                                echo 1
                                

                                as pinctrl is not on my linux desktop

                                Sam

                                How to add modules

                                learning how to use browser developers window for css changes

                                C 1 Reply Last reply Reply Quote 0
                                • C Offline
                                  ChrisLeduex @sdetweil
                                  last edited by

                                  @sdetweil Ah yes, I forgot I have a python script I was kicking off manually that I forgot to run before testing those fixes. It is working now and both files are communicating with each other, thank you.

                                  My next step is to see if I can get this working with the MMM-Buttons/MMM-ModuleToggleButton modules.

                                  S 1 Reply Last reply Reply Quote 0
                                  • S Do not disturb
                                    sdetweil @ChrisLeduex
                                    last edited by

                                    @ChrisLeduex buttons is interrupt driven, but can be changed to polling like you are doing

                                    Sam

                                    How to add modules

                                    learning how to use browser developers window for css changes

                                    C 1 Reply Last reply Reply Quote 0
                                    • C Offline
                                      ChrisLeduex @sdetweil
                                      last edited by

                                      @sdetweil Yeah you’re right, that one might be more difficult. But I do have MMM-ModuleToggleButton working with pinctrl. Here’s the updated node_helper.js file just in case anyone’s interested.

                                      node_helper.js

                                      const NodeHelper = require('node_helper'); // eslint-disable-line import/no-extraneous-dependencies
                                      //const Gpio = require('onoff').Gpio;
                                      const { exec } = require("child_process");
                                      
                                      module.exports = NodeHelper.create({
                                        start() {
                                          this.started = false;
                                        },
                                      
                                        socketNotificationReceived(notification, payload) {
                                          if (notification === 'TOGGLE_BUTTON_CONFIG' && !this.started) {
                                            const self = this;
                                            this.config = payload;
                                      
                                            //const button = new Gpio(this.config.buttonGpioPin, 'in', 'both', { persistentWatch: true, debounceTimeout: this.config.debounceTimeoutInMilliseconds });
                                            //button.watch((err, state) => {
                                            //  if (state === 1) {
                                            //    self.sendSocketNotification(self.config.notificationName, true);
                                            //  }
                                            //});
                                      
                                            //this.started = true;
                                            
                                            // Set up GPIO as input using pinctrl command
                                            const pin = this.config.buttonGpioPin;
                                            const debounceTimeout = this.config.debounceTimeoutInMilliseconds;
                                            const notificationName = this.config.notificationName;
                                            let lastState = null;
                                      
                                            // Function to read the pin state using pinctrl
                                            const checkPinState = () => {
                                            exec(`pinctrl get ${pin}`, (err, stdout, stderr) => {
                                              if (err) {
                                                console.error(`Error reading GPIO state: ${err.message}`);
                                                return;
                                              }
                                             
                                              // Parse the pin state from stdout
                                              const state = stdout.includes("hi") ? 1 : 0;
                                      
                                              // Handle state change with debounce
                                              if (state !== lastState && state === 1) {
                                                this.sendSocketNotification(notificationName, true);
                                              }
                                             
                                              // Update last state
                                              lastState = state;
                                            });
                                            };
                                      
                                          // Set up an interval to check the pin state with debounce
                                          setInterval(checkPinState, debounceTimeout || 100); // Defaults to 100ms if debounce is not defined
                                            
                                          }
                                        }
                                      });
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • S sdetweil has marked this topic as solved on

                                      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