geeks-r-us / mqtt-panel

Simple Grafana panel that allows to communicate with a mqtt server
Apache License 2.0
54 stars 11 forks source link

Connecting with mosquitto #11

Open dewell1 opened 3 years ago

dewell1 commented 3 years ago

Hi,I have setup Grafana now locally with the mqtt panel and on another machine in my network I got a mosquitto mqtt broker.

1599039163: mosquitto version 1.6.9 starting
1599039163: Using default config.
1599039163: Opening ipv6 listen socket on port 1883.
1599039163: Opening ipv4 listen socket on port 1883.

The broker seems to work well, I can reach it with mosquitto_pub, the result is the following:

1599039216: New connection from 192.168.2.18 on port 1883.
1599039216: New client connected from 192.168.2.18 as mosq-d8iFGefTuhJ0RmjoJ1 (p2, c1, k60).
1599039216: No will message specified.
1599039216: Sending CONNACK to mosq-d8iFGefTuhJ0RmjoJ1 (0, 0)
1599039216: Received PUBLISH from mosq-d8iFGefTuhJ0RmjoJ1 (d0, q0, r0, m0, 'grafana/mqtt-panel/set', ... (4 bytes))
1599039216: Received DISCONNECT from mosq-d8iFGefTuhJ0RmjoJ1
1599039216: Client mosq-d8iFGefTuhJ0RmjoJ1 disconnected.

I configured the mqtt panel with websocket as protocol and the right ip and port. When I press "Test" in the grafana configuration I see the query icon rotating in the panel but at first nothing happens.

After a few seconds the mqtt broker gets the following error message:

1599039293: New connection from 192.168.2.18 on port 1883.
1599039293: Client <unknown> disconnected due to protocol error.

I'm starting mosquitto with the basic standard configuration. Is there anything else to configure?

geeks-r-us commented 3 years ago

By default Mosquitto does not accept websocket connections. You need to open another port with ws or wss protocol

Simplest way is to add the following lines to mosquitto.conf :

listener 9001
protocol websockets
dewell1 commented 3 years ago

Thank you very much! I added this now and started mosquitto:

C:\Program Files\mosquitto>mosquitto -v -c mosquitto.conf
1599042024: mosquitto version 1.6.9 starting
1599042024: Config loaded from mosquitto.conf.
1599042024: Opening websockets listen socket on port 9001.
1599042024: Opening ipv6 listen socket on port 1883.
1599042024: Opening ipv4 listen socket on port 1883.

Within the MQTT panel I added the following information

Pressing "TEST" results in no reaction. Right now I install wireshark to see if there's anything arriving at all. The firewalls are completely open, so I guess it's still some configuration issue with websockets.

Is it right that I still open the ports on 1883?

geeks-r-us commented 3 years ago

There should also an open port on 9001

fichetto commented 3 years ago

Hello,

on my setup, grafana is on the same server of mosquitto broker. I've set protocol and port.

1610282323: Config loaded from /etc/mosquitto/mosquitto.conf. 1610282323: Opening ipv4 listen socket on port 1883. 1610282323: Opening ipv6 listen socket on port 1883. 1610282323: Opening websockets listen socket on port 9001.

My panel is configured as follow: { "type": "geeksrus-mqtt-panel", "title": "Commands", "gridPos": { "x": 0, "y": 0, "w": 12, "h": 8 }, "id": 4, "fieldConfig": { "defaults": { "custom": {} }, "overrides": [] }, "pluginVersion": "7.3.4", "timeFrom": null, "timeShift": null, "description": "", "value": "35", "mqttProtocol": "ws", "mqttServer": "127.0.0.1", "mqttServerPort": 9001, "mqttTopicSubscribe": "grafana/mqtt-panel", "mqttTopicPublish": "grafana/mqtt-panel/set", "mqttAuth": "BasicAuth", "mqttUser": "utente", "mqttPassword": "password", "mqttTopicQuery": "", "mode": "Slider", "model": { "text": "Send", "minValue": 0, "maxValue": 100, "step": 1, "offValue": "false", "onValue": "true" }, "viewModel": { "text": "Send", "minValue": "0", "maxValue": "100", "step": "1", "offValue": "false", "onValue": "true" }, "datasource": null }

Watching the logs, this client (panel) hasn't tried to connect to grafana, never. I'm not sure I've installed correctly the plugin, because I'm not using Docker and I've installed the plugin with grafana-cli.

On the panel: I've used "localhost","127.0.0.1", Ethernet IPV4, without success.

Thanks Cosimo

geeks-r-us commented 3 years ago

With version 1 of the plugin the mqtt client is not running on the server, it's running on your webbrowser. So 127.0.0.1 / localhost will fail if your browser is not running on your server maschine. You need to replace it with the ip of the server. in this case the ip you use to access grafana.

fichetto commented 3 years ago

Hello,

Yes, I have to use the address of the mqtt server, but now I have a new problem. Grafana doesn't display more the controls (slider, button, text...) in the panel. Now I'm seeing only then empty panel. I've tried to restart, update, upgrade the server but... nothing. I'm expert of embedded electronics and my experience on server side is poor. But I need this funcion on my grafana server. As I've asked before, can you help me?

Thanks

geeks-r-us commented 3 years ago

Empty means like this ? image

This can have various reasons:

If non of the above applies to your issues debug output of your browser (F12 -> Console) would be helpful.

I know this websocket communication is not very convenient and I work on better solution. But this will take some time until it will be released.

fichetto commented 3 years ago

Yes, our case is the first you've explained. I need to find a solution and I can pay for it, due to restricted time I have on my project. Thanks

fichetto commented 3 years ago

However I've just tried to connect to the server by MQTT websocket application and I haven't any problem, without using TLS.

geeks-r-us commented 3 years ago

What is your timeline? I'm currently available for hire. Just get in touch by root [et] geek-r-us.de

The issue is the security policy of the browser. If the connection to a website is secured all other unsecured connections are disallowed by default.

fichetto commented 3 years ago

I need the dashboards working with your panel, before the end of this month. Can I use wss protocol to solve this problem?

Il giorno lun 11 gen 2021 alle ore 09:55 geeks-r-us < notifications@github.com> ha scritto:

What is your timeline? I'm currently available for hire. Just get in touch by root [et] geek-r-us.de

The issue is the security policy of the browser. If the connection to a website is secured all other unsecured connections are disallowed by default.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/geeks-r-us/mqtt-panel/issues/11#issuecomment-757747719, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACZH4PTLJTRVCLMKAYDYUYTSZK4HHANCNFSM4QSZQ2GQ .

geeks-r-us commented 3 years ago

If you use https + wss it should work

mo802 commented 2 years ago

did anyone solve this problem? i'd like to use the panel with mosquitto broker to control a sonoff switch. on my setup, grafana is on the same server of mosquitto broker. please help.

mo802 commented 2 years ago

@geeks-r-us i'd be so grateful if you could help me, and i can pay for it.