@cotxwx I am experiencing the same issue. Do you by chance turn your mirror monitor off? Mine is hooked up to a TV HDMI input and the issue seems to present itself when I switch between HDMI inputs…
Read the statement by Michael Teeuw here.
Posts
-
RE: Refresh modules / MagicMirror without running pm2 restart?
-
RE: setInterval for multiple API requests
@strawberry-3.141 - thank you for the approach. This is working out beautifully.
-
Consolidate logging to browser console
I wanted to share a simple approach to unify logging across module components that I found incredibly useful during development. This will put all* logging in a browser console and remove the need to monitor pm2/pi console logs.
In your main module code (MMM-ABC.js), where you define your sockets simply add:
if (notification === 'HELPER_MESSAGE') { if (this.config.debug === 1) { Log.info(payload); } //Receive a message, log the payload to the browser console. }
In your node_helper.js module, construct and send messages:
if (self.config.debug === 1) { apiMessage = moment().format('YYYY-MM-DD>>HH:mm:ss.SSSZZ') + ' [node_helper] << your log message content here >>'; self.sendSocketNotification('HELPER_MESSAGE', apiMessage); }
Hope this helps on your development journey!
*any code errors / exceptions will still throw to the raspberry pi console / pm2
-
RE: setInterval for multiple API requests
Big O strikes again! Thank you for the explanation.
@strawberry-3.141 any guidance on location / structure of that function within node_helper? Create something like I did for MMM-Surf module within node_helper? Tack on a simple set interval @ the end of the NodeHelper.create {} stanza?
Current node_helper code can be found at https://github.com/Privacywonk/MMM-Surf/blob/master/node_helper.js for reference.
-
RE: Notifications and commands help please.
So I did some quick googling over coffee this morning. I think there is a two part suggestion for you. Please note, this will require research and testing which I have not done, this is just directional.
- Install MMM-RemoteControl - https://github.com/Jopyth/MMM-Remote-Control
- Add some custom code to the MMM-Remote-Control module to handle requests for turning on/off the motion device.
In MMM-Remote-Control’s node_helper.js module, you can find the “MONITORON” code:
if (query.action === "MONITORON") { exec("tvservice --preferred && sudo chvt 6 && sudo chvt 7", opts, function(error, stdout, stderr){ self.checkForExecError(error, stdout, stderr, res); }); return true; }
Notes:
- query.action defines a trigger word for the MMM-RemoteControl to listen for.
- exec() - executes a command on the OS
- The rest is for error checking that the external command executed.
In your case, we could define the following:
if (query.action === "MOTIONON") { exec("echo "motion_enable on" > ~/pikrellcam/www/FIFO", opts, function(error, stdout, stderr){ self.checkForExecError(error, stdout, stderr, res); }); return true; } if (query.action === "MOTIONOFF") { exec("echo "motion_enable off" > ~/pikrellcam/www/FIFO", opts, function(error, stdout, stderr){ self.checkForExecError(error, stdout, stderr, res); }); return true; }
-
setInterval for multiple API requests
Background:
My module pulls from three data sources: NOAA, Wunderground, and Magicseaweed to render the UI. When I initially made the module, I had 3x setInterval functions loaded in node_helper. This did not work well…the setInterval function was firing haphazardly, resulting in 1000s of calls being made to the APIs.
My initial solution for this was to move the update function to the main module (MMM-Surf.js). This produced the desired effect BUT, I later realized, creates an asynchronous update process across multiple clients vs. synchronizing it in node_helper.
Question(s):
- Is it worthwhile to move the update functionality back into node_helper or if it’s working, leave well enough alone?
- if I do move it back, recommendations for how to structure it to avoid the random firing across the three API calls?
Current solution in MMM-Surf:
scheduleUpdate: function() { var nextload = this.config.updateInterval; var self = this; this.updateTimer = setInterval(function() { if (self.config.debug === 1) { Log.info(moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + " UPDATE: scheduledUpdate called fetching new data: " + self.config.updateInterval); } self.getNOAA(self); self.getWunder(self); self.getMagicseaweed(self); }, nextload); },
Legacy node_helper structure (repeated 3x times):
fetchMagicseaweedData: function() { var self = this; this.MAGICfetcherRunning = true; //block of code removed for brevity setInterval(function() { self.fetchMagicseaweedData(); }, self.config.updateInterval); } // end request(function()) ); //end Magicseaweed request this.MAGICfetcherRunning = false; }, //end Magicseaweed function
-
RE: UI/Data Caching
@retroflex - that is where all of my API requests reside. MMM-Surf calls the node_helper functions. Whenever the app is loaded it makes new calls.
I am looking into node-cache to see if I can integrate that somehow.
-
RE: Notifications and commands help please.
as part of the configuration file for MMM-NetworkScanner there is an “occupiedCMD” and “vacantCMD” that you could try setting with the command sequence above. I haven’t used this tool yet so I am unsure what sort of commands can be passed.