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.

    MMM-Stock Cannot read property 'toLowerCase'

    Scheduled Pinned Locked Moved Troubleshooting
    34 Posts 2 Posters 12.8k Views 2 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.
    • B Offline
      brendan_c23
      last edited by

      Stock module used to run just fine, now I am given this error when pulling up ‘npm start dev’ can anyone offer any guidance on how to fix this?

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @brendan_c23
        last edited by sdetweil

        @brendan_c23 usually this happens when a module retrieves data and EXPECTS success, but never really checks, or the data changes format.

        this specific error is related to a string (“abcdefgh”) and wanting to convert all the chars to lowercase before comapring… BUT the string didn’t get created…

        in json data its like this
        if(json_data.key.toLowerCase() ==‘test’)
        but the item changed name to Key, so its undefined.toLowercase()…

        or key is not a string anymore,
        but an object {}

        net, the code has to change

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        B 1 Reply Last reply Reply Quote 1
        • B Offline
          brendan_c23 @sdetweil
          last edited by

          @sdetweil Could you help guide me on how to fix the code? Would you like me to post the .js file?

          S 2 Replies Last reply Reply Quote 0
          • S Offline
            sdetweil @brendan_c23
            last edited by

            @brendan_c23 which module is that

            this one works fine (with the example stocks)

            https://github.com/hakanmhmd/MMM-Stock

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 0
            • S Offline
              sdetweil @brendan_c23
              last edited by sdetweil

              @brendan_c23 ok, I see the error on refresh…

              change line 90 from

              	if(this.config.currency.toLowerCase() != "usd"){
              

              to

              	if(that.config.currency.toLowerCase() != "usd"){
              

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              B 1 Reply Last reply Reply Quote 1
              • B Offline
                brendan_c23 @sdetweil
                last edited by sdetweil

                @sdetweil Hey I tried that, now it says Cannot read property ‘toLowerCase’ of undefined at MMM-stock.js:90
                Any other suggestions?

                u are only changing the word this to the word that on that one line

                B 1 Reply Last reply Reply Quote 0
                • B Offline
                  brendan_c23 @brendan_c23
                  last edited by

                  @brendan_c23 Uncaught TypeError: Cannot read property ‘toLowerCase’ of undefined

                  S 1 Reply Last reply Reply Quote 0
                  • S Offline
                    sdetweil @brendan_c23
                    last edited by

                    @brendan_c23 you are only changing one word
                    ‘this’ to the word ‘that’ on one line

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    B 1 Reply Last reply Reply Quote 0
                    • B Offline
                      brendan_c23 @sdetweil
                      last edited by

                      @sdetweil Yes I made that change, but the error was still coming up for me

                      S 1 Reply Last reply Reply Quote 0
                      • S Offline
                        sdetweil @brendan_c23
                        last edited by

                        @brendan_c23 show me those 10 lines

                        Sam

                        How to add modules

                        learning how to use browser developers window for css changes

                        B 1 Reply Last reply Reply Quote 0
                        • B Offline
                          brendan_c23 @sdetweil
                          last edited by

                          @sdetweil //if another currency is required - usd is default
                          var differentCurrency = false;
                          if(that.config.currency.toLowerCase() != “usd”){
                          differentCurrency = true;
                          var requiredCurrency = this.config.currency.toUpperCase();
                          }

                          	for (var key in data) {
                          		if (!data.hasOwnProperty(key)) {continue;}
                          		var symbol = key;
                          		var obj = data[key];
                          		var current = obj[0];
                          		var prev = obj[1];
                          		var price = current["4. close"];
                          		var change = prev["4. close"] - current["4. close"];
                          
                          		var html = "";
                          		var priceClass = "greentext", priceIcon="up_green";
                          		if(change < 0) {
                          			priceClass = "redtext";
                          			priceIcon="down_red";
                          		}
                          
                          S 1 Reply Last reply Reply Quote 0
                          • S Offline
                            sdetweil @brendan_c23
                            last edited by

                            @brendan_c23 no, these, around line 90

                            	scheduleUpdate: function(delay) {
                            		var loadTime = this.config.updateInterval;
                            		if (typeof delay !== "undefined" && delay >= 0) {
                            			loadTime = delay;
                            		}
                            
                            		var that = this;
                            		setInterval(function() {
                            			that.getStocks();
                            			if(that.config.currency.toLowerCase() != "usd"){ // line 90 changed
                            				that.getExchangeRate();
                            			}
                            		}, loadTime);
                            	},
                            

                            Sam

                            How to add modules

                            learning how to use browser developers window for css changes

                            B 1 Reply Last reply Reply Quote 0
                            • B Offline
                              brendan_c23 @sdetweil
                              last edited by

                              @sdetweil Ok, I changed the ‘this’ to ‘that’ some lines above! not on those lines, going to try running it after changing the line you just sent

                              S 1 Reply Last reply Reply Quote 0
                              • S Offline
                                sdetweil @brendan_c23
                                last edited by

                                @brendan_c23 just the ONE line, line 90…

                                Sam

                                How to add modules

                                learning how to use browser developers window for css changes

                                B 1 Reply Last reply Reply Quote 1
                                • B Offline
                                  brendan_c23
                                  last edited by

                                  @sdetweil still waiting to see if it will display, theres a big delay, but no errors have popped up yet

                                  scheduleUpdate: function(delay) {
                                  var loadTime = this.config.updateInterval;
                                  if (typeof delay !== “undefined” && delay >= 0) {
                                  loadTime = delay;
                                  }

                                  	var that = this;
                                  	setInterval(function() {
                                  		that.getStocks();
                                  		if(that.config.currency.toLowerCase() != "usd"){
                                  			that.getExchangeRate();
                                  		}
                                  	}, loadTime);
                                  },
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • B Offline
                                    brendan_c23 @sdetweil
                                    last edited by

                                    @sdetweil No errors have come up, but it also has not displayed, have been waiting for around 10 minutes

                                    S 1 Reply Last reply Reply Quote 0
                                    • S Offline
                                      sdetweil @brendan_c23
                                      last edited by

                                      @brendan_c23 did u change the other lines back?

                                      open the developers window ctrl-shift-i, console tab, ‘stock’ in the filter field (no quotes)

                                      Sam

                                      How to add modules

                                      learning how to use browser developers window for css changes

                                      B 2 Replies Last reply Reply Quote 0
                                      • B Offline
                                        brendan_c23 @sdetweil
                                        last edited by

                                        @sdetweil They should be, but just in case Im missing something…

                                        Module.register(“MMM-Stock”, {
                                        result: {},
                                        defaults: {
                                        updateInterval: 60000,
                                        fadeSpeed: 1000,
                                        companies: [“GOOGL”, “YHOO”],
                                        currency: “usd”,
                                        baseURL: “https://www.alphavantage.co/”,
                                        apikey: “IPWULBT54Y3LHJME”
                                        },

                                        getStyles: function() {
                                        	return ["MMM-Stock.css"];
                                        },
                                        
                                        getTranslations: function() {
                                        	return false;
                                        },
                                        
                                        start: function() {
                                        	this.getStocks();
                                        	if(this.config.currency.toLowerCase() != "usd"){
                                        		this.getExchangeRate();
                                        	}
                                        	this.scheduleUpdate();
                                        },
                                        
                                        getDom: function() {
                                        	var wrapper = document.createElement("div");
                                        	wrapper.className = "quotes";
                                        	var list = document.createElement("ul");
                                        
                                        	var data = this.result;
                                        	// the data is not ready
                                        	if(Object.keys(data).length === 0 && data.constructor === Object){
                                        		return wrapper;
                                        	}
                                        
                                        	//if another currency is required - usd is default
                                        	var differentCurrency = false;
                                        	if(this.config.currency.toLowerCase() != "usd"){
                                        		differentCurrency = true;
                                        		var requiredCurrency = this.config.currency.toUpperCase();
                                        	}
                                        
                                        	for (var key in data) {
                                        		if (!data.hasOwnProperty(key)) {continue;}
                                        		var symbol = key;
                                        		var obj = data[key];
                                        		var current = obj[0];
                                        		var prev = obj[1];
                                        		var price = current["4. close"];
                                        		var change = prev["4. close"] - current["4. close"];
                                        
                                        		var html = "";
                                        		var priceClass = "greentext", priceIcon="up_green";
                                        		if(change < 0) {
                                        			priceClass = "redtext";
                                        			priceIcon="down_red";
                                        		}
                                        		html = html + "<span class='" + priceClass + "'>";
                                        		html = html + "<span class='quote'> (" + symbol + ")</span> ";
                                        		html = html + parseFloat(price).toFixed(2) + " USD";
                                        		html = html + "<span class='" + priceIcon + "'></span>" + parseFloat(Math.abs(change)).toFixed(2);
                                        
                                        		var stock = document.createElement("span");
                                        		stock.className = "stockTicker";
                                        		stock.innerHTML = html;
                                        
                                        		var listItem = document.createElement("li");
                                        		listItem.innerHTML = html;
                                        		list.appendChild(listItem);
                                        	}
                                        
                                        	wrapper.appendChild(list);
                                        	return wrapper;
                                        },
                                        
                                        scheduleUpdate: function(delay) {
                                        	var loadTime = this.config.updateInterval;
                                        	if (typeof delay !== "undefined" && delay >= 0) {
                                        		loadTime = delay;
                                        	}
                                        
                                        	var that = this;
                                        	setInterval(function() {
                                        		that.getStocks();
                                        		if(that.config.currency.toLowerCase() != "usd"){
                                        			that.getExchangeRate();
                                        		}
                                        	}, loadTime);
                                        },
                                        
                                        getStocks: function () {
                                        	var allCompanies = this.config.companies;
                                        	var urls = [];
                                        	for(var company in allCompanies){
                                        		var url = this.config.baseURL + "query?function=TIME_SERIES_DAILY&outputsize=compact&symbol=" + allCompanies[company] + "&apikey=" + this.config.apikey;
                                        		urls.push(url);
                                        	}
                                        	this.sendSocketNotification("GET_STOCKS", urls);
                                        },
                                        
                                        getExchangeRate: function () {
                                        	var url = this.config.baseURL + "?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20('USD" + this.config.currency + "')&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback="
                                        	this.sendSocketNotification("GET_EXCHANGE_RATE", url);
                                        },
                                        socketNotificationReceived: function(notification, payload) {
                                        	if (notification === "STOCK_RESULT") {
                                        		this.result = payload;
                                        		this.updateDom(self.config.fadeSpeed);
                                        	} else if(notification === "EXCHANGE_RATE"){
                                        		this.rate = payload;
                                        	}
                                        }
                                        

                                        });

                                        1 Reply Last reply Reply Quote 0
                                        • B Offline
                                          brendan_c23 @sdetweil
                                          last edited by

                                          @sdetweil Load script: modules/MMM-Stock//MMM-Stock.js
                                          module.js:517 Module registered: MMM-Stock
                                          loader.js:148 Bootstrapping module: MMM-Stock
                                          loader.js:153 Scripts loaded for: MMM-Stock
                                          loader.js:195 Load stylesheet: modules/MMM-Stock/MMM-Stock.css
                                          loader.js:155 Styles loaded for: MMM-Stock
                                          loader.js:157 Translations loaded for: MMM-Stock

                                          S 1 Reply Last reply Reply Quote 0
                                          • S Offline
                                            sdetweil @brendan_c23
                                            last edited by

                                            @brendan_c23 so, no errors

                                            does the config entry have a position:

                                            if not the content is thrown away

                                            Sam

                                            How to add modules

                                            learning how to use browser developers window for css changes

                                            B 1 Reply Last reply Reply Quote 0

                                            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