• 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
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Add symboly/icon in a modul

Scheduled Pinned Locked Moved Troubleshooting
14 Posts 3 Posters 7.5k Views 4 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.
  • D Offline
    dominic
    last edited by Oct 3, 2017, 7:36 PM

    It works!! Ehm is it possible to make it varriable, so i can choose the symbol with an entrie in the defaults ?

    Module.register('MMM-mqtt', {
    
     defaults: {
       mqttServer: 'mqtt://test.mosquitto.org',
       loadingText: 'Loading MQTT Data...',
       topic: '',
       showTitle: false,
       title: 'MQTT Data',
       interval: 300000,
       postText: ''
     },
    
    J 1 Reply Last reply Oct 3, 2017, 7:43 PM Reply Quote 0
    • J Offline
      j.e.f.f Project Sponsor Module Developer @dominic
      last edited by j.e.f.f Oct 3, 2017, 7:44 PM Oct 3, 2017, 7:43 PM

      @dominic indeed. it’s just a string, so you can have the string in the config, then insert it when you create the symbol object. Like so:

      var symbolEl = document.createElement("span");
      symbol.className = "fa " + this.config.symbol;
      1 Reply Last reply Reply Quote 0
      • D Offline
        dominic
        last edited by Oct 3, 2017, 9:15 PM

        Now with this code ( is the original code with added css file and with your part) i only get the text “loading MQTT DATA” before it has still worked with your code. Maybe it is to late or i don´t see the error…but if you can be so nice, can you add tell me wehre my error is and can you add the varribale code ? And thank you very much for your help. :)

        'use strict';
        /* global Module */
        
        /* Magic Mirror
        * Module: MMM-mqtt
        *
        * By Javier Ayala http://www.javierayala.com/
        * MIT Licensed.
        */
        
        Module.register('MMM-mqtt', {
        
         defaults: {
           mqttServer: 'mqtt://test.mosquitto.org',
           loadingText: 'Loading MQTT Data...',
           topic: '',
           showTitle: false,
           title: 'MQTT Data',
           interval: 300000,
           postText: ''
         },
        
        
         start: function() {
           Log.info('Starting module: ' + this.name);
           this.loaded = false;
           this.mqttVal = '';
           this.updateMqtt(this);
         },
        
          getStyles: function() {
           return ["MMM-DHT-Sensor.css", "font-awesome.css"];
         },
        
         updateMqtt: function(self) {
           self.sendSocketNotification('MQTT_SERVER', { mqttServer: self.config.mqttServer, topic: self.config.topic });
           setTimeout(self.updateMqtt, self.config.interval, self);
         },
        
         getDom: function() {
           var wrapper = document.createElement('div');
        
           if (!this.loaded) {
             wrapper.innerHTML = this.config.loadingText;
             return wrapper;
           }
        
           if (this.config.showTitle) {
             var titleDiv = document.createElement('div');
             titleDiv.innerHTML = this.config.title;
             wrapper.appendChild(titleDiv);
           }
        
           var mqttDiv = document.createElement('div');
           
           var symbolEl = document.createElement("span");
           symbol.className = "fa fa-calendar"; //font awesome calendar icon
           var textEl = document.createElement("span");
           textEl.innerHTML = this.mqttVal.toString().concat(this.config.postText);
        
           mqttDiv.appendChild(symbol)
           mqttDiv.appendChild(textEl);
        
           wrapper.appendChild(mqttDiv);
        
           return wrapper;
         },
        
         socketNotificationReceived: function(notification, payload) {
           if (notification === 'MQTT_DATA' && payload.topic === this.config.topic) {
             this.mqttVal = payload.data.toString();
             this.loaded = true;
             this.updateDom();
           }
        
           if (notification === 'ERROR') {
             this.sendNotification('SHOW_ALERT', payload);
           }
         }
        
        });
        
        
        
        
        
        J 1 Reply Last reply Oct 3, 2017, 9:48 PM Reply Quote 0
        • J Offline
          j.e.f.f Project Sponsor Module Developer @dominic
          last edited by Oct 3, 2017, 9:48 PM

          @dominic can you look to see if there are errors in the console? Two places you can look: Errors from node_helper.js will be output to the pm2 logs. Type pm2 logs mm to monitor this. The second place to look for errors is in Electron’s console. Start MagicMirror in debug mode with npm start dev and you’ll get the screen divided into to halves. On the right side you’ll see a white panel. Click on “CONSOLE” and if there are any errors there they will be in red.

          1 Reply Last reply Reply Quote 0
          • D Offline
            dominic
            last edited by Oct 4, 2017, 10:12 AM

            @j.e.f.f said in Add symboly/icon in a modul:

            with npm start dv i get this info, i dont get es divided screen in to halves.

            pi@raspberrypi:~ $ npm start dev
            npm ERR! Linux 4.9.41-v7+
            npm ERR! argv “/usr/bin/node” “/usr/bin/npm” “start” “dev”
            npm ERR! node v6.11.3
            npm ERR! npm v3.10.10
            npm ERR! path /home/pi/package.json
            npm ERR! code ENOENT
            npm ERR! errno -2
            npm ERR! syscall open

            npm ERR! enoent ENOENT: no such file or directory, open ‘/home/pi/package.json’
            npm ERR! enoent ENOENT: no such file or directory, open ‘/home/pi/package.json’
            npm ERR! enoent This is most likely not a problem with npm itself
            npm ERR! enoent and is related to npm not being able to find a file.
            npm ERR! enoent

            npm ERR! Please include the following file with any support request:
            npm ERR! /home/pi/npm-debug.log

            and with pm2 logs mm this one
            pi@raspberrypi:~ $ pm2 logs mm
            [TAILING] Tailing last 15 lines for [mm] process (change the value with --lines option)

            ach with the other code

             mqttDiv.innerHTML = "< span class='fa fa-calendar'>< /span>" + this.mqttVal.toString().concat(this.config.postText);
            

            i get a symbol, only with the var version, it does not work.

            M 1 Reply Last reply Oct 4, 2017, 7:46 PM Reply Quote 0
            • M Offline
              Mykle1 Project Sponsor Module Developer @dominic
              last edited by Oct 4, 2017, 7:46 PM

              @dominic said in Add symboly/icon in a modul:

              pi@raspberrypi:~ $ npm start dev

              You have to cd in the MagicMirror directory first, then run npm start or npm start dev

              Create a working config
              How to add modules

              D 1 Reply Last reply Oct 4, 2017, 7:56 PM Reply Quote 1
              • D Offline
                dominic @Mykle1
                last edited by Oct 4, 2017, 7:56 PM

                @Mykle1 Ah Thanks :D, now i have the console, but there is no error.

                1 Reply Last reply Reply Quote 0
                • 1
                • 2
                • 2 / 2
                2 / 2
                • First post
                  12/14
                  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