Skip to content

Commit

Permalink
begin add rate down/up
Browse files Browse the repository at this point in the history
  • Loading branch information
bugsounet committed Mar 30, 2024
1 parent 5df0228 commit 4963ba4
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 20 deletions.
14 changes: 14 additions & 0 deletions MMM-Freebox.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#FREE_IP,
#FREE_DEBIT,
#FREE_BAND,
#FREE_BAND_TYPE,
#FREE_BAND_DOWN,
#FREE_BAND_UP,
#FREE_CLIENT {
display: flex;
font-size: small;
Expand All @@ -35,6 +38,10 @@
white-space: nowrap;
}

#FREE_VALUE.nomargin {
margin-left: 0px;
}

#FREE_RATE {
margin-left: 10px;
text-align: left;
Expand Down Expand Up @@ -223,6 +230,13 @@
background-position: 0 -1px;
}

#FREE_ICON.up {
background-image: url(resources/up.png);
}

#FREE_ICON.down {
background-image: url(resources/down.png);
}

#FREE_ICON.freebox_crystal0 {
background-image: url(resources/players.png);
Expand Down
65 changes: 54 additions & 11 deletions MMM-Freebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ Module.register("MMM-Freebox", {
this.Init = false;
this.Freebox = {
Hidden: true,
Bandwidth: null,
Debit: null,
BandwidthDown: null,
BandwidthUp: null,
DebitDown: null,
DebitUp: null,
IP: null,
Degroup: false,
Type: null,
Expand Down Expand Up @@ -108,8 +110,10 @@ Module.register("MMM-Freebox", {
this.Freebox.Model = payload.Model;
this.Freebox.Type = payload.Type;
this.Freebox.Degroup = payload.Degroup;
this.Freebox.Bandwidth = payload.Bandwidth;
this.Freebox.Debit = payload.Debit;
this.Freebox.BandwidthDown = payload.BandwidthDown;
this.Freebox.BandwidthUp = payload.BandwidthUp;
this.Freebox.DebitDown = payload.DebitDown;
this.Freebox.DebitUp = payload.DebitUp;
this.Freebox.IP = payload.IP;
this.Freebox.Clients = payload.Clients;
this.Freebox.Ping = payload.Ping;
Expand All @@ -133,11 +137,18 @@ Module.register("MMM-Freebox", {
/** Bande Passante **/
var bandWidth = document.getElementById("FREE_BAND");
var bandWidthIcon = bandWidth.querySelector("#FREE_ICON");
var bandWidthType = document.getElementById("FREE_BAND_TYPE");
var bandWidthDown = document.getElementById("FREE_BAND_DOWN");
var bandWidthUp = document.getElementById("FREE_BAND_UP");

var bandWidthValue = bandWidth.querySelector("#FREE_VALUE");
var bandWidthTypeValue = bandWidth.querySelector("#FREE_VALUE");
var bandWidthDownValue = bandWidthDown.querySelector("#FREE_VALUE");
var bandWidthUpValue = bandWidthUp.querySelector("#FREE_VALUE");
if (this.config.showIcon) bandWidthIcon.classList.remove("hidden");
if (this.config.showBandWidth) bandWidth.classList.remove("hidden");
bandWidthValue.textContent = this.Freebox.Type + (this.Freebox.Degroup ? " (Dégroupé): " : ": ") + this.Freebox.Bandwidth;
bandWidthTypeValue.textContent = this.Freebox.Type + (this.Freebox.Degroup ? " (Dégroupé): " : ": "); // + this.Freebox.BandwidthDown;
bandWidthDownValue.textContent = this.Freebox.BandwidthDown;
bandWidthUpValue.textContent = this.Freebox.BandwidthUp;

/** Adresse IP **/
var IP = document.getElementById("FREE_IP");
Expand Down Expand Up @@ -196,7 +207,7 @@ Module.register("MMM-Freebox", {
/** debit client **/
var clientDebit = clientSelect.querySelector("#FREE_RATE");
if (this.config.showClientRate) clientDebit.classList.remove("hidden");
clientDebit.textContent = client.debit;
clientDebit.textContent = client.debitDown;

/** bouton **/
var clientStatus = clientSelect.querySelector("INPUT");
Expand Down Expand Up @@ -224,7 +235,7 @@ Module.register("MMM-Freebox", {
var debitValue = debit.querySelector("#FREE_VALUE");
if (this.config.showIcon) debitIcon.classList.remove("hidden");
if (this.config.showRate) debit.classList.remove("hidden");
debitValue.textContent = this.Freebox.Debit;
debitValue.textContent = `${this.Freebox.DebitDown} - ${this.Freebox.DebitUp}`;

/** Affichage Ping en temps réél **/
var ping = document.getElementById("FREE_PING");
Expand Down Expand Up @@ -280,9 +291,41 @@ Module.register("MMM-Freebox", {
bandWidthIcon.id= "FREE_ICON";
bandWidth.appendChild(bandWidthIcon);

var bandWidthDisplay= document.createElement("div");
bandWidthDisplay.id = "FREE_VALUE";
bandWidth.appendChild(bandWidthDisplay);
var bandWidthType= document.createElement("div");
bandWidthType.id = "FREE_BAND_TYPE";
bandWidth.appendChild(bandWidthType);

var bandWidthTypeValue= document.createElement("div");
bandWidthTypeValue.id = "FREE_VALUE";
bandWidthType.appendChild(bandWidthTypeValue);

var bandWidthDown= document.createElement("div");
bandWidthDown.id = "FREE_BAND_DOWN";
bandWidth.appendChild(bandWidthDown);

var bandWidthDownIcon= document.createElement("div");
bandWidthDownIcon.className = "down";
bandWidthDownIcon.id = "FREE_ICON";
bandWidthDown.appendChild(bandWidthDownIcon);

var bandWidthDownRate= document.createElement("div");
bandWidthDownRate.id = "FREE_VALUE";
bandWidthDownRate.className = "nomargin";
bandWidthDown.appendChild(bandWidthDownRate);

var bandWidthUp= document.createElement("div");
bandWidthUp.id = "FREE_BAND_UP";
bandWidth.appendChild(bandWidthUp);

var bandWidthUpIcon= document.createElement("div");
bandWidthUpIcon.className = "up";
bandWidthUpIcon.id = "FREE_ICON";
bandWidthUp.appendChild(bandWidthUpIcon);

var bandWidthUpRate= document.createElement("div");
bandWidthUpRate.id = "FREE_VALUE";
bandWidthUpRate.className = "nomargin";
bandWidthUp.appendChild(bandWidthUpRate);

wrapper.appendChild(bandWidth);

Expand Down
26 changes: 18 additions & 8 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ module.exports = NodeHelper.create({
ip: null,
type: client.host_type,
vendor: client.vendor_name,
debit: null,
debitDown: null,
debitUp:null,
active: client.active,
repeater: false,
access_type: null,
Expand All @@ -178,8 +179,10 @@ module.exports = NodeHelper.create({
device.signal_percent = this.wifiPercent(device.signal);
device.signal_bar = this.wifiBar(device.signal_percent);
}
if (client.access_point?.tx_rate) device.debit = this.convert(client.access_point.tx_rate*8,0,1); // Warn debit en bytes! (base 8)
else device.debit = "0 Ko/s";
if (client.access_point?.tx_rate) device.debitDown = this.convert(client.access_point.tx_rate*8,0,1); // Warn debit en bytes! (base 8)
else device.debitDown = "0 Ko/s";
if (client.access_point?.rx_rate) device.debitUp = this.convert(client.access_point.rx_rate*8,0,1); // Warn debit en bytes! (base 8)
else device.debitUp = "0 Ko/s";
}

if (this.config.showClientRate || this.config.showClientCnxType) {
Expand All @@ -191,7 +194,10 @@ module.exports = NodeHelper.create({
if (client.l2ident.id === mac) {
if (client.access_point?.connectivity_type === "wifi" && client.access_point?.type === "repeater") device.repeater = true;
else if (res[info.id] && res[info.id].tx_bytes_rate) {
if (this.config.showEthClientRate) device.debit = this.convert(res[info.id].tx_bytes_rate,0,1);
if (this.config.showEthClientRate) {
device.debitDown = this.convert(res[info.id].tx_bytes_rate,0,1);
device.debitUp = this.convert(res[info.id].rx_bytes_rate,0,1);
}
device.access_type = "ethernet";
device.eth = info.id;
}
Expand Down Expand Up @@ -316,17 +322,21 @@ module.exports = NodeHelper.create({
});
FB("Done!");

bandwidth = `${this.convert(cnx.data.result.bandwidth_down,1,2)} - ${this.convert(cnx.data.result.bandwidth_up,1,2)}`;
debit = `${this.convert(cnx.data.result.rate_down,0,2)} - ${this.convert(cnx.data.result.rate_up,0,2)}`;
bandwidthDown = this.convert(cnx.data.result.bandwidth_down,1,2);
bandwidthUp = this.convert(cnx.data.result.bandwidth_up,1,2);
debitUp = this.convert(cnx.data.result.rate_down,0,2);
debitDown = this.convert(cnx.data.result.rate_up,0,2);
type = (cnx.data.result.media === "xdsl") ? "xDSL" : ((cnx.data.result.media === "ftth") ? "FTTH" : "Inconnu");
degroup = (cnx.data.result.type === "rfc2684") ? true : false;

output = {
Model: this.FreeboxVersion,
Type: type,
Degroup: degroup,
Bandwidth: bandwidth,
Debit: debit,
BandwidthDown: bandwidthDown,
BandwidthUp: bandwidthUp,
DebitDown: debitDown,
DebitUp: debitUp,
IP: cnx.data.result.ipv4,
Client: clients.data.result ? clients.data.result : [],
EthCnx: clientRate && ethCnx.data.result ? ethCnx.data.result : [],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"description": "Display Freebox informations",
"main": "MMM-Freebox.js",
"keywords": [
"freebox"
"freebox",
"french"
],
"scripts": {
"register": "node installer/Freebox_Login.js",
Expand Down
Binary file added resources/down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4963ba4

Please sign in to comment.