• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
  1. Home
  2. jchariot
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.
J
Offline
  • Profile
  • Following 0
  • Followers 0
  • Topics 1
  • Posts 1
  • Groups 0

jchariot

@jchariot

0
Reputation
186
Profile views
1
Posts
0
Followers
0
Following
Joined Nov 21, 2018, 3:50 AM
Last Online Dec 7, 2018, 3:47 PM

jchariot Unfollow Follow

Latest posts made by jchariot

  • Need help in Javascript for resetting module if user no longer interacts after x seconds.

    I am using a Sonar module on Raspberry Pi to indicate whether someone is in front of the mirror or not. I use MMM-websocket to transfer this information to MagicMirror and it works correctly. Now, when there is nobody in front of the mirror for x seconds, I would like to call a function to reset the module. However, I got an issue on Javascript side:

    Currently I have this function for resetting in my module:

    userNoLongerInFrontSoReset: function(){
        if (this.resetTimeout != null){
            clearTimeout(this.resetTimeout);
        }
    
        this.resetTimeout = setTimeout(function(){
            console.log("resetTimeout setTimeout");
    
            this.myVar = null;
            this.myVar2 = null;
            this.myVar3 = null;
    
            this.sendNotification("PAGE_CHANGED", 0); 
    
            this.updateDom();
    
        }, 3000)
    }
    

    I see from the console that resetTimeout setTimeout is being printed out from the code above, but then it got:

    Uncaught TypeError: this.sendNotification is not a function at myOwnModule.js:xxx
    

    So this is the problem. All those variables myVar, etc. are not being referred correctly as well as the function sendNotification. How can I set all myVar and call sendNotification from the anonymous function in this case? Or is there a better way to do this?

    Thank you,

    posted in Troubleshooting
    J
    jchariot
    Nov 21, 2018, 4:25 AM
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