├── others ├── MMM-NetworkConnection-screenshot-01.png └── MMM-NetworkConnection-screenshot-02.png ├── translations ├── en.json └── id.json ├── .gitignore ├── .gitattributes ├── package.json ├── node_helper.js ├── README.md └── MMM-NetworkConnection.js /others/MMM-NetworkConnection-screenshot-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slametps/MMM-NetworkConnection/HEAD/others/MMM-NetworkConnection-screenshot-01.png -------------------------------------------------------------------------------- /others/MMM-NetworkConnection-screenshot-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slametps/MMM-NetworkConnection/HEAD/others/MMM-NetworkConnection-screenshot-02.png -------------------------------------------------------------------------------- /translations/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "NETCONN_CONNECTED": "Internet is connected", 3 | "NETCONN_NOTCONNECTED": "Internet is not connected", 4 | "NETCONN_MILLISECOND": "ms", 5 | "NETCONN_NA": "N/A", 6 | 7 | "TXT_NETCONN": "NETWORK CONNECTION", 8 | "TXT_NETCONN_DESC": "display internet connection status" 9 | } 10 | -------------------------------------------------------------------------------- /translations/id.json: -------------------------------------------------------------------------------- 1 | { 2 | "NETCONN_CONNECTED": "Terhubung ke internet", 3 | "NETCONN_NOTCONNECTED": "Tidak terhubung ke internet", 4 | "NETCONN_MILLISECOND": "md", 5 | "NETCONN_NA": "N/A", 6 | 7 | "TXT_NETCONN": "NETWORK CONNECTION", 8 | "TXT_NETCONN_DESC": "menampilkan status koneksi internet" 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows thumbnail cache files 2 | Thumbs.db 3 | ehthumbs.db 4 | ehthumbs_vista.db 5 | 6 | # Folder config file 7 | Desktop.ini 8 | 9 | # Recycle Bin used on file shares 10 | $RECYCLE.BIN/ 11 | 12 | # Windows Installer files 13 | *.cab 14 | *.msi 15 | *.msm 16 | *.msp 17 | 18 | # Windows shortcuts 19 | *.lnk 20 | 21 | # ========================= 22 | # Operating System Files 23 | # ========================= 24 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MMM-NetworkConnection", 3 | "version": "1.0.0", 4 | "description": "Display network connection test result (connection status, ping, download, upload speed)", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/slametps/MMM-NetworkConnection.git" 8 | }, 9 | "keywords": [ 10 | "MagicMirror", 11 | "NetworkConnection", 12 | "network", 13 | "connection", 14 | "speedtest" 15 | ], 16 | "author": "Slamet Puji Santuso", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/slametps/MMM-NetworkConnection/issues" 20 | }, 21 | "homepage": "https://github.com/slametps/MMM-NetworkConnection#readme", 22 | "dependencies": { 23 | "speedtest-net": ">=1.2.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /node_helper.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file node_helper.js for MMM-NetworkConnection 3 | * 4 | * @author slametps 5 | * @license MIT 6 | * 7 | * @see https://github.com/slametps/MMM-NetworkConnection 8 | */ 9 | var NodeHelper = require('node_helper'); 10 | var speedtest = require('speedtest-net'); 11 | 12 | module.exports = NodeHelper.create({ 13 | start: function(){ 14 | console.log(this.name + ' helper started ...'); 15 | }, 16 | socketNotificationReceived : function(notification, payload){ 17 | if(notification == 'NETCONN_TEST_START') 18 | { 19 | console.log('starting network connection testing') 20 | var that = this; 21 | var st = speedtest({maxTime: payload.config.maxTime || 5000}); 22 | st.on('downloadspeed', function (speed) { 23 | var download = speed.toFixed(payload.config.decimal); 24 | //console.log("download : " + download); 25 | that.sendSocketNotification('NETCONN_RESULT_DOWNLOAD', download); 26 | }); 27 | 28 | st.on('uploadspeed', function (speed) { 29 | var upload = speed.toFixed(payload.config.decimal); 30 | //console.log("upload : " + upload); 31 | that.sendSocketNotification('NETCONN_RESULT_UPLOAD', upload); 32 | }); 33 | 34 | st.once('testserver', function(server){ 35 | var ping = Math.round(server.bestPing); 36 | //console.log("ping : " + ping); 37 | that.sendSocketNotification('NETCONN_RESULT_PING', ping); 38 | }); 39 | } 40 | } 41 | }); 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MMM-NetworkConnection [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)] 2 | 3 | Network Connection Status (ping, download, upload) Module for MagicMirror2. 4 | This module combines [internet-monitor](https://github.com/ronny3050/internet-monitor) and [MMM-connection-status](https://github.com/sheyabernstein/MMM-connection-status). 5 | 6 | ## Example 7 | 8 | ![](others/MMM-NetworkConnection-screenshot-01.png) ![](others/MMM-NetworkConnection-screenshot-02.png) 9 | 10 | ## Dependencies 11 | 12 | * An installation of [MagicMirror2](https://github.com/MichMich/MagicMirror) 13 | * [speedtest-net](https://www.npmjs.com/package/speedtest-net) module of nodejs 14 | 15 | ## Installation 16 | 17 | 1. Clone this repo into `~/MagicMirror/modules` directory. 18 | 2. Go to `~/MagicMirror/modules/MMM-NetworkConnection` directory and do `npm install` 19 | 3. Configure your `~/MagicMirror/config/config.js`: 20 | 21 | ``` 22 | { 23 | module: 'MMM-NetworkConnection', 24 | position: 'top_right', 25 | config: { 26 | } 27 | } 28 | ``` 29 | 30 | ## Config Options 31 | 32 | | **Option** | **Default** | **Description** | 33 | | --- | --- | --- | 34 | | `updateInterval` | `600000 ms` (10 minutes) | how often should the devices states refreshed | 35 | | `maxTime` | `5000` milliseconds | how long to do speedtest | 36 | | `initialLoadDelay` | `2500` milliseconds | how long to delay to load the module | 37 | | `decimal` | `1` | how many decimals for the round | 38 | | `displayTextStatus` | `true` | display connection text status or not | 39 | | `animationSpeed` | `2500` milliseconds | speed of the update animation | 40 | -------------------------------------------------------------------------------- /MMM-NetworkConnection.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file MMM-NetworkConnection.js 3 | * 4 | * @author slametps 5 | * @license MIT 6 | * 7 | * @see https://github.com/slametps/MMM-NetworkConnection 8 | */ 9 | 10 | Module.register('MMM-NetworkConnection', { 11 | 12 | // Default module config. 13 | defaults: { 14 | updateInterval: 60 * 1000, 15 | animationSpeed: 2.5 * 1000, 16 | maxTime: 5 * 1000, 17 | initialLoadDelay: 2.5 * 1000, 18 | decimal: 1, 19 | displayTextStatus: true, 20 | language: config.language || 'en', 21 | }, 22 | 23 | getScripts: function() { 24 | return ["moment.js"]; 25 | }, 26 | 27 | // Subclass getStyles method. 28 | getStyles: function () { 29 | return ['font-awesome.css']; 30 | }, 31 | 32 | // Define required translations. 33 | getTranslations: function() { 34 | return { 35 | 'en': 'translations/en.json', 36 | 'id': 'translations/id.json' 37 | }; 38 | }, 39 | 40 | // Define start sequence. 41 | start: function() { 42 | Log.info('Starting module: ' + this.name); 43 | var self = this; 44 | 45 | // Set locale 46 | moment.locale(self.config.language); 47 | 48 | this.downloadSpeed = -1; 49 | this.uploadSpeed = -1; 50 | this.pingDelay = -1; 51 | this.firstLoad = true; 52 | 53 | setTimeout(() => { 54 | this.testUpdate(); 55 | setInterval(() => { 56 | this.testUpdate(); 57 | }, self.config.updateInterval); 58 | }, self.config.initialLoadDelay); 59 | }, 60 | 61 | // Override dom generator. 62 | getDom: function() { 63 | var self = this; 64 | var wrapper = document.createElement('div'); 65 | 66 | if (self.firstLoad && self.pingDelay == -1) { 67 | wrapper.className = "bright small light"; 68 | wrapper.innerHTML = this.translate("LOADING"); 69 | } 70 | else { 71 | self.firstLoad = false; 72 | var connectionActive = this.checkConnection(); 73 | 74 | if (connectionActive) { 75 | wrapper.className = 'small'; 76 | let s = '' 77 | if (self.config.displayTextStatus) { 78 | s += this.translate("NETCONN_CONNECTED"); 79 | s += " ("; 80 | } 81 | s += " "+ (self.pingDelay > -1 ? self.pingDelay + this.translate("NETCONN_MILLISECOND") : this.translate("NETCONN_NA")); 82 | s += " "; 83 | s += ""+ (self.downloadSpeed > -1 ? self.downloadSpeed + "Mbps" : this.translate("NETCONN_NA")); 84 | s += " "; 85 | s += " "+ (self.uploadSpeed > -1 ? self.uploadSpeed + "Mbps" : this.translate("NETCONN_NA")); 86 | if (self.config.displayTextStatus) { 87 | s += ")"; 88 | } 89 | wrapper.innerHTML = s; 90 | } else { 91 | wrapper.className = 'normal bright'; 92 | wrapper.innerHTML = this.translate("NETCONN_NOTCONNECTED"); 93 | } 94 | } 95 | 96 | return wrapper; 97 | }, 98 | 99 | checkConnection: function() { 100 | return window.navigator.onLine; 101 | }, 102 | 103 | testUpdate: function() { 104 | this.sendSocketNotification('NETCONN_TEST_START', {'config':this.config}); 105 | }, 106 | 107 | /*testUpdate: function(delay, fn) { 108 | var nextLoad = this.config.updateInterval; 109 | if (typeof delay !== 'undefined' && delay >= 0) { 110 | nextLoad = delay; 111 | } 112 | 113 | var self = this 114 | setInterval(function() { 115 | self.getDom(); 116 | }, nextLoad); 117 | },*/ 118 | 119 | socketNotificationReceived: function(notification, payload) { 120 | if (notification == 'NETCONN_RESULT_DOWNLOAD') { 121 | this.downloadSpeed = payload; 122 | } 123 | if (notification == 'NETCONN_RESULT_UPLOAD') { 124 | this.uploadSpeed = payload; 125 | } 126 | if (notification == 'NETCONN_RESULT_PING') { 127 | this.pingDelay = payload; 128 | } 129 | this.updateDom(this.config.animationSpeed); 130 | } 131 | }); 132 | --------------------------------------------------------------------------------