Error in config file when adding modules, looking for another set of eyes



  • Hello, first off I am a hardware guy, coding is not something I regularly use, and I’m slowly slogging through this, it is intimidating.

    I am trying to add a Camera module with voice control to my Magic Mirror (RPi3), from https://github.com/alexyak/camera

    Here is what I have for a config file so far, but I am getting the error:

    “If you get this message while your config file is already created, your config file probably contains an error.”

    Here is my config.js contents:

    /* Magic Mirror Config Sample
     *
     * By Michael Teeuw http://michaelteeuw.nl
     * MIT Licensed.
     *
     * For more information how you can configurate this file
     * See https://github.com/MichMich/MagicMirror#configuration
     *
     */
    
    var config = {
    	address: "localhost", // Address to listen on, can be:
    	                      // - "localhost", "127.0.0.1", "::1" to listen on loopback interface
    	                      // - another specific IPv4/6 to listen on a specific interface
    	                      // - "", "0.0.0.0", "::" to listen on any interface
    	                      // Default, when address config is left out, is "localhost"
    	port: 8080,
    	ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], // Set [] to allow all IP addresses
    	                                                       // or add a specific IPv4 of 192.168.1.5 :
    	                                                       // ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.1.5"],
    	                                                       // or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format :
    	                                                       // ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"],
    
    	language: "en",
    	timeFormat: 12,
    	units: "imperial",
    
    	modules: [
    		{
    			module: "alert",
    		},
    		{
    			module: "updatenotification",
    			position: "top_bar"
    		},
    		{
    			module: "clock",
    			position: "top_left"
    		},
    		{
    			module: "calendar",
    			header: "US Holidays",
    			position: "top_left",
    			config: {
    				calendars: [
    					{
    						symbol: "calendar-check-o ",
    						url: "webcal://www.calendarlabs.com/templates/ical/US-Holidays.ics"
    					}
    				]
    			}
    		},
    		{
    			module: "compliments",
    			position: "lower_third"
    		},
    		{
    			module: 'camera',
    			position: 'top_center',
    			config: selfieInterval: 3,  // Time interval in seconds before the photo will be taken.
    				emailConfig: {
    				service: 'GMail', // Email provider to use to send email with a photo.
    				auth: {
    					user: '', // Your email account
    					pass: ''        // Your password for email account
    			}
    		},
    		{
    			module: 'voicecontrol',
    			position: 'bottom_left',
    			config: {
    				models: [
    				{
    					keyword: "Show Camera",
    					description: "Say 'Show Camera' to display camera",
    					file: "showCamera.pmdl",
    					message: "SHOW_CAMERA"
    				},
    				{
    					keyword: "Hide Camera",
    					description: "Say 'Hide Camera' to hide camera",
    					file: "hideCamera.pmdl",
    					message: "HIDE_CAMERA"
    				},
    				{
    					keyword: "Selfie",
    					description: "Say 'Selfie' when camera is visible",
    					file: "selfie.pmdl",
    					message: "SELFIE"
    				},
    			]
    		},
    		{
    			module: "currentweather",
    			position: "top_right",
    			config: {
    				location: "Boston",
    				locationID: "4930956",  //ID from http://www.openweathermap.org/help/city_list.txt
    				appid: "My API"
    			}
    		},
    		{
    			module: "weatherforecast",
    			position: "top_right",
    			header: "Weather Forecast",
    			config: {
    				location: "Boston",
    				locationID: "4930956",  //ID from http://www.openweathermap.org/help/city_list.txt
    				appid: "My API"
    			}
    		},
    		{
    			module: "newsfeed",
    			position: "bottom_bar",
    			config: {
    				feeds: [
    					{
    						title: "New York Times",
    						url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml"
    					}
    				],
    				showSourceTitle: true,
    				showPublishDate: true
    			}
    		},
    	]
    
    };
    

    I had a difficult time editing this natively on the Pi, have copied the config.js files to a Windows machine and using NotePad++ to edit the file, the lines lining the code up help me immensely. Wish there was an easier workflow for me to use?



  • Hi,

    your config is missing a closing bracket } in the config of the camera module. To be specific, it seems like the closing bracket of “auth:” is missing.

    And it also seems weird to me that after “config:” there is no object (in brackets), but that’s how the readme of the module shows the example configuration.

    {
        module: "camera",
        position: "top_center",
        config: { // added this one, maybe missing/wrong in the example?
            selfieInterval: 3,  // Time interval in seconds before the photo will be taken.
            emailConfig: {
                service: "GMail", // Email provider to use to send email with a photo.
                auth: {
                    user: "", // Your email account
                    pass: ""        // Your password for email account
                } //  this one was missing
            }
        } // added this one, maybe missing/wrong in the example?
    },
    

    And also a closing bracket missing for the config: of the voicecontrol module:

    {
        module: "voicecontrol",
        position: "bottom_left",
        config: {
                models: [
                    {
                    keyword: "Show Camera",
                    description: "Say 'Show Camera' to display camera",
                    file: "showCamera.pmdl",
                    message: "SHOW_CAMERA"
                },
                {
                    keyword: "Hide Camera",
                    description: "Say 'Hide Camera' to hide camera",
                    file: "hideCamera.pmdl",
                    message: "HIDE_CAMERA"
                },
                {
                    keyword: "Selfie",
                    description: "Say 'Selfie' when camera is visible",
                    file: "selfie.pmdl",
                    message: "SELFIE"
                },
            ]
        } // this one was missing
    },
    

    Some thing’s to consider: Use one sort of quotes throughout the file for strings of text. The config.js uses " while some module’s authors use '. Usually not a problem, but it’s cleaner to stick with one and helps minimize problems, for example when we look at this line from your config (which is not a problem but shows where it gets complicated):

    description: "Say 'Show Camera' to display camera",
    

    Some good ideas for people running into this to check their configs:

    • remove the last added module, run again, see if the problem is gone, if so, re-add the module and check brackets and commas, if not, re-add it, it wasn’t the source of the problem, check the next one.
    • or directly go through your file and check that every opening bracket has a matching closing bracket.
      Some text editors will highlight the closing bracket if you select the opening bracket be setting the cursor to it, or the other way round (Sublime Text does).


  • Wish there was an easier workflow for me to use?

    I installed samba on my pi & shared my home directory.

    You can then just browse to it from a windows machine & directly open your config.js, edit (notepad++ is the best choice imo) & then use putty to send a pm2 restart command.

    Google rpi samba as there’s plenty good info out there

    For bonus ease you could then access the mirror in a Web browser on the pc using for example 192.168.1.100:8080 (sub in your mm ip). You will first need to set the ‘interface’ parameter in your config.js to 0.0.0.0 and set the access list to include pc ip or subnet. This is how I do it so I don’t have to go & stand in front of the mirror while I’m making changes to it.



  • Anyone having config.js issues can first copy/paste the module config (or whole thing) into JSHint (removing any API secrets or passwords). It will immediately draw attention to any syntax issues.



  • Wow, thanks for these replies everyone.

    Blows my mind how it was just basically missing just a few “small,” to me, pieces.

    Hard to pick those out, need to step my game up and hit up CodeAcademy.

    JSHint is perfect! That will help me out a TON!

    And @RandomNoise, thank you for that idea, going to make it MUCH easier to browse and modify files that way!

    You guys rock thanks, what a great community


Log in to reply
 

Looks like your connection to MagicMirror Forum was lost, please wait while we try to reconnect.