Skip to content

Commit

Permalink
Version 1.0.1
Browse files Browse the repository at this point in the history
    * fixed exception on wrong mqtt server url
    * panel variables can be used in server config section
  • Loading branch information
geeks-r-us committed Apr 14, 2020
1 parent 33868e9 commit 36e82b6
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 14 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Version 1.0.1
* fixed exception on wrong mqtt server url
* panel variables can be used in server config section

## Version: 1.0.0
* initial working version of the mqtt-panel


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ to servers reachable by your browser.
If you like to test this plugin the easies way is to load it into a grafana docker container.

```
docker run -d -p 3000:3000 -e "GF_INSTALL_PLUGINS=https://github.com/geeks-r-us/mqtt-panel/releases/download/v1.0.0/geeksrus-mqtt-panel-1.0.0.zip;mqtt-panel" --name=grafana grafana/grafana
docker run -d -p 3000:3000 -e "GF_INSTALL_PLUGINS=https://github.com/geeks-r-us/mqtt-panel/releases/download/v1.0.0/geeksrus-mqtt-panel-1.0.1.zip;mqtt-panel" --name=grafana grafana/grafana
```
Open http://localhost:3000 in your browser

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "geeksrus-mqtt-panel",
"version": "1.0.0",
"version": "1.0.1",
"description": "A panel to enable grafana to fulfil simple control tasks via MQTT",
"scripts": {
"build": "grafana-toolkit plugin:build",
Expand All @@ -11,14 +11,15 @@
"author": "geeks-r-us",
"license": "Apache-2.0",
"devDependencies": {
"@grafana/runtime": "^6.7.2",
"@grafana/data": "next",
"@grafana/toolkit": "next",
"@grafana/ui": "next",
"@types/jquery": "^3.3.34",
"@types/paho-mqtt": "^1.0.4",
"@types/grafana": "github:CorpGlory/types-grafana.git"
},
"dependencies": {
"@types/jquery": "^3.3.34",
"@types/paho-mqtt": "^1.0.4",
"angular": "^1.7.9",
"jquery": "^3.4.1",
"mqtt": "^3.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ to servers reachable by your browser.
If you like to test this plugin the easies way is to load it into a grafana docker container.

```
docker run -d -p 3000:3000 -e "GF_INSTALL_PLUGINS=https://github.com/geeks-r-us/mqtt-panel/releases/download/v1.0.0/geeksrus-mqtt-panel-1.0.0.zip;mqtt-panel" --name=grafana grafana/grafana
docker run -d -p 3000:3000 -e "GF_INSTALL_PLUGINS=https://github.com/geeks-r-us/mqtt-panel/releases/download/v1.0.0/geeksrus-mqtt-panel-1.0.1.zip;mqtt-panel" --name=grafana grafana/grafana
```
Open http://localhost:3000 in your browser

Expand Down
24 changes: 17 additions & 7 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class MqttCtrl extends MetricsPanelCtrl {
firstValues: KeyValue[] = [];

/** @ngInject */
constructor($scope, $injector) {
constructor($scope, $injector, public templateSrv) {
super($scope, $injector);
defaultsDeep(this.panel, this.panelDefaults);

Expand All @@ -56,13 +56,18 @@ export default class MqttCtrl extends MetricsPanelCtrl {
this.events.on('data-error', this.onDataError.bind(this));

// Create a client instance: Broker, Port, Websocket Path, Client ID
var url = this.panel.mqttProtocol + '://' + this.panel.mqttServer + ':' + this.panel.mqttServerPort;
var url =
this.panel.mqttProtocol +
'://' +
this.templateSrv.replace(String(this.panel.mqttServer)) +
':' +
this.templateSrv.replace(String(this.panel.mqttServerPort));
console.log(url);
this.client = mqtt.connect(url);
this.client.on('connectionLost', this.onConnectionLost.bind(this));
this.client.on('connect', this.onConnect.bind(this));
this.client.on('message', this.onMessage.bind(this));
this.client.subscribe(this.panel.mqttTopicSubscribe);
this.client.subscribe(this.templateSrv.replace(String(this.panel.mqttTopicSubscribe)));

angluar.module('grafana.directives').directive('stringToNumber', this.stringToNumber);
}
Expand Down Expand Up @@ -150,7 +155,12 @@ export default class MqttCtrl extends MetricsPanelCtrl {

connect() {
this.client.end(true);
var url = this.panel.mqttProtocol + '://' + this.panel.mqttServer + ':' + this.panel.mqttServerPort;
var url =
this.panel.mqttProtocol +
'://' +
this.templateSrv.replace(String(this.panel.mqttServer)) +
':' +
this.templateSrv.replace(String(this.panel.mqttServerPort));
console.log(url);
this.client = mqtt.connect(url);
}
Expand All @@ -166,12 +176,12 @@ export default class MqttCtrl extends MetricsPanelCtrl {
value = this.panel.value.toString();
break;
}
console.log('Published : ' + this.panel.mqttTopicPublish + ' : ' + value);
this.client.publish(this.panel.mqttTopicPublish, value);
console.log('Published : ' + this.templateSrv.replace(String(this.panel.mqttTopicPublish)) + ' : ' + value);
this.client.publish(this.templateSrv.replace(String(this.panel.mqttTopicPublish)), value);
}

connected() {
return this.client.connected ? 'successful' : 'failed';
return this.client != null && this.client.connected ? 'successful' : 'failed';
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
},
"links": [],
"screenshots": [],
"version": "1.0.0",
"updated": "2020/04/05"
"version": "1.0.1",
"updated": "2020/04/14"
},
"dependencies": {
"grafanaVersion": "6.3.x",
Expand Down
71 changes: 71 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -947,11 +947,30 @@
lodash "4.17.15"
rxjs "6.5.4"

"@grafana/[email protected]":
version "6.7.2"
resolved "https://registry.yarnpkg.com/@grafana/data/-/data-6.7.2.tgz#f3f303654923cac17da6b3664d31227fc088fe54"
integrity sha512-W/oygRtN8FrFalaIaCndUqSWN0lRQQA05/q4sulxy7wMY6o+JXJwtmFA83tDeJ4l4SmVPISK5XewA1um4U77Pw==
dependencies:
apache-arrow "0.15.1"
lodash "4.17.15"
rxjs "6.5.4"

"@grafana/eslint-config@^1.0.0-rc1":
version "1.0.0-rc1"
resolved "https://registry.yarnpkg.com/@grafana/eslint-config/-/eslint-config-1.0.0-rc1.tgz#3b0a1abddfea900a57abc9526ad31abb1da2d42c"
integrity sha512-xmcJR6mUYw1llq3m8gT2kE7xoq6yLMUgNf2Mf1yZvDCx2cXFSyaLlGs1dqjFWjJDbV46GdhYRAyRbyGR+J9QKg==

"@grafana/runtime@^6.7.2":
version "6.7.2"
resolved "https://registry.yarnpkg.com/@grafana/runtime/-/runtime-6.7.2.tgz#2b8e7279f45f3b361b30b4032c20b97d52ecf6a1"
integrity sha512-r4bohPeeWiaDRcV6S7NnfLCuPEH/oE9cjlVE6C1S7uuQrh4rLU/CqOlOFcZ4YlapS34DaBhxFonsEgamGHb1pQ==
dependencies:
"@grafana/data" "6.7.2"
"@grafana/ui" "6.7.2"
systemjs "0.20.19"
systemjs-plugin-css "0.1.37"

"@grafana/[email protected]":
version "0.22.9-grafana"
resolved "https://registry.yarnpkg.com/@grafana/slate-react/-/slate-react-0.22.9-grafana.tgz#07f35f0ffc018f616b9f82fa6e5ba65fae75c6a0"
Expand Down Expand Up @@ -1108,6 +1127,48 @@
slate "0.47.8"
tinycolor2 "1.4.1"

"@grafana/[email protected]":
version "6.7.2"
resolved "https://registry.yarnpkg.com/@grafana/ui/-/ui-6.7.2.tgz#cc27f17220bfecb76731d268dc72535be2891e4a"
integrity sha512-YXunXjBi2SgF9QhSa3koNHW2eS83tByiR9+e6trJONrzwpMtxfSytBOzt4IeZb3dH9dofP0I6P20K4VX//HnKQ==
dependencies:
"@emotion/core" "^10.0.27"
"@grafana/data" "6.7.2"
"@grafana/slate-react" "0.22.9-grafana"
"@grafana/tsconfig" "^1.0.0-rc1"
"@torkelo/react-select" "3.0.8"
"@types/react-color" "2.17.0"
"@types/react-select" "3.0.8"
"@types/react-table" "7.0.2"
"@types/slate" "0.47.1"
"@types/slate-react" "0.22.5"
bizcharts "^3.5.5"
classnames "2.2.6"
d3 "5.15.0"
emotion "10.0.27"
immutable "3.8.2"
jquery "3.4.1"
lodash "4.17.15"
moment "2.24.0"
papaparse "4.6.3"
rc-cascader "0.17.5"
rc-drawer "3.0.2"
rc-slider "8.7.1"
rc-time-picker "^3.7.2"
react "16.12.0"
react-calendar "2.19.2"
react-color "2.17.0"
react-custom-scrollbars "4.2.1"
react-dom "16.12.0"
react-highlight-words "0.11.0"
react-hook-form "4.5.3"
react-popper "1.3.3"
react-storybook-addon-props-combinations "1.1.0"
react-table "7.0.0-rc.15"
react-transition-group "2.6.1"
slate "0.47.8"
tinycolor2 "1.4.1"

"@icons/material@^0.2.4":
version "0.2.4"
resolved "https://registry.yarnpkg.com/@icons/material/-/material-0.2.4.tgz#e90c9f71768b3736e76d7dd6783fc6c2afa88bc8"
Expand Down Expand Up @@ -10793,6 +10854,16 @@ symbol-tree@^3.2.2:
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==

[email protected]:
version "0.1.37"
resolved "https://registry.yarnpkg.com/systemjs-plugin-css/-/systemjs-plugin-css-0.1.37.tgz#684847252ca69b7da24a1201094c86274324e82f"
integrity sha512-wCGG62zYXuOlNji5FlBjeMFAnLeAO/HQmFg+8UBX/mlHoAKLHlGFYRstlhGKibRU2oxk/BH9DaihOuhhNLi7Kg==

[email protected]:
version "0.20.19"
resolved "https://registry.yarnpkg.com/systemjs/-/systemjs-0.20.19.tgz#c2b9e79c19f4bea53a19b1ed3f974ffb463be949"
integrity sha512-H/rKwNEEyej/+IhkmFNmKFyJul8tbH/muiPq5TyNoVTwsGhUjRsN3NlFnFQUvFXA3+GQmsXkCNXU6QKPl779aw==

table-layout@^0.4.3:
version "0.4.5"
resolved "https://registry.yarnpkg.com/table-layout/-/table-layout-0.4.5.tgz#d906de6a25fa09c0c90d1d08ecd833ecedcb7378"
Expand Down

0 comments on commit 36e82b6

Please sign in to comment.