Read the statement by Michael Teeuw here.
Multiple "Mirrors" from a single device
-
Is it possible to run multiple mirrors from a single device?
My current MM utilises the default Calendar module to display family member calendars from Google in the top_left section and the MMM-CalendarWeek module in the bottom_bar section to display another Google calendar.
I know I can display the MM via a web browser on any number of devices, but this is just a duplicate of what I see from the directly-connected host device.I want to output the family calendars on one display while the other calendar displays on another.
This could be where one is displayed to a directly-connected output, while the other is viewed from a browser, or possibly, both are displayed via a browser if physically locating the host with either display isn’t possible.Is this sort of setup doable?
I had read online that I would have to create a second config.js file, configured as required for the alternate view.
Within that file, I would have to specify an alternate port (say 8081) and initiate a secondary instance of MM.
However, the instructions never indicated or specified how the second config.js file would be referenced in order to display the appropriate output. -
@DarrenO-0 how did you add it to pm2 . just doing mm2.sh doesn’t
pm2 start xxxx
xxx is the mm2.sh
or the MagicMirror2.json
it should run and you should see with statusthen pm2 save so that it will be saved to the bootup start list
-
@DarrenO-0 yes you can run multiple instances from the same folder with different configurations
there is a section in the doc on doing this
see
https://docs.magicmirror.builders/configuration/introduction.html#advanced-configuration-and-frequently-asked-how-to-configure-examples -
@sdetweil
Thanks. That has sort of help me out and pointed me in the right direction.Is it just as simple as copying the existing:
and editing the pm2_MagicMirror2_new.json file to reference:
- the app name of MagicMirror2
- the script of mm2.sh (is there anything to change in this?)
- watching the config2.js file for changes
and then executing pm2 start config2.js --name MagicMirror2
-
@DarrenO-0 the json file my installer script creates is just to give the app name in pm2 a meaningful mame,
if you use
pm2 start mmfoo.sh
the the app name will be mmfoothe watch function is broken, pm2 now only supports watching a folder for changes, but file updates don’t count as a folder change
can you change the name of the script, yes, anything you like
once you update the json file , just
pm2 start xxxx.json
and it will take the info from there -
As I rewrote that section in the docs - I’ll give a (semi) live example (My second mirror is down due to lack of space, I’m working on a solution) - this is what works for me at the moment. I do realize I’m doubling up on some things.
In my Pi’s config, I also reverted to X11 desktop rather than wayland for reasons unrelated. I have not tested this on Wayland.
cd /home/bkey1970/MagicMirror DISPLAY=:0 npm start
cd /home/bkey1970/MagicMirror export MM_CONFIG_FILE=config/config2.js export MM_PORT=8081 DISPLAY=:0 npm start
the start of config.js:
var config = { address: "0.0.0.0", port: 8080, ipWhitelist: [], language: "en", timeFormat: 12, units: "imperial", //logLevel: ["INFO", "LOG", "WARN", "ERROR", "DEBUG"], modules: [
The start of config2.js:
var config = { address: "0.0.0.0", port: 8081, electronOptions: { x: 1920 }, ipWhitelist: [], language: "en", timeFormat: 12, units: "imperial", //logLevel: ["INFO", "LOG", "WARN", "ERROR", "DEBUG"], customCss: "css/custom2.css", modules: [
PM2 commands to tie it all together:
pm2 start /home/<username>/<path>/mm.sh --name "MM Main" pm2 start /home/<username>/<path>/mm2.sh --name "MM 2nd" pm2 save
-
@sdetweil
OK, so no requirement to update the “name” and “watch” values in the .json file, but it doesn’t hurt to do so from an fyi perspective, right???When I run “pm2 start config2.js”, I can then access the second instance via browser on another device with no issue, but it also takes over the display directly connected to the MM host device.
I can view both MM instances via a browser on different devices (great, as that was one of my original questions), but what if i want to view instance #1 via the display directly connected to the MM host device and instance #2 via a remote browser (or vice versa?My .sh files to start each MM instance are as follows:
mm.sh
#!/bin/bash
cd ~/MagicMirror
DISPLAY=:0 npm startmm2.sh
#!/bin/bash
cd ~/MagicMirror
export MM_CONFIG_FILE=config/config2.js
export MM_PORT=8081
npm start
#DISPLAY=:0 npm startShould I change anything, or what would I need to change, to have the desired outcome described above?
-
@DarrenO-0 npm start run the ui locally and the server for remotes
npm run server starts the server for remote and browsers locally
both cases remotes need the server config to allow outside connection
pm2 start xxxx
where xxxx is the script name ( end in . sh)
OR
the json file where it can get the infothe different config is set thru an environment variable
MM_CONFIG_FILE=in linux by default env variables are NOT passed to children processes
so you have to use export to
make it passed onon Windows env variables ARE passed to children processes by default
the port number is used on the remote system to access the appropriate instance
http://mm-server-address:mm-instance-port-number
-
@sdetweil
so mm2.sh should/would be:
#!/bin/bash
cd ~/MagicMirror
export MM_CONFIG_FILE=config/config2.js
export MM_PORT=8081
npm run server
#DISPLAY=:0 npm startwhile mm.sh remains untouched
When I have this in place:
- instance #1 correctly displays on the screen attached to the MM host… tick
- i can also view instance #1 on a browser (on port 8080)… tick
- can view instance #2 in a browser (on port 8081)… tick
However, when I run mm2.sh while I am SSH’d to the MM, I am not returned to the command line so I can save the pm2 setup.
I just have a prompt saying “Ready to go! Please point your browser to http://ipaddress:8081”I have to Ctrl-C to cancel out, which then stops the server function and the #2 instance is no longer displayed
-
@DarrenO-0 in Windows when you want an app to run when started from the command prompt you do
detach command…
in linux you add and & as the last charactercomand… &
now… STOPPING those detached/background things are tough…
here is one value for pm2… it EXPECTS the script to blockand so you can kill it thru pm2 stop xxxx
BUT
pm2’s JOB is to start and app AND KEEP IT RUNNING…
so you kill it (ctrl-q) or it fails, pm2 will restart itSO, if you want both to run and want to do it manually, open a second ssh session
until you are happy and then let pm2 run them both -