vogler75 / winccua-mqtt-client

MQTT Client Custom Web Control for SIEMENS WinCC Unified
MIT License
10 stars 3 forks source link

Connect to MQTT with a Client Certificate #2

Open SergioManuelAema opened 4 months ago

SergioManuelAema commented 4 months ago

Hello,

I am trying to connect to my broker mqtt and i can't be able done. In my screen I have only dragged the control and I have configurated its propierties In Runtime, It does nothing, no message is shown With MQTT Explorer, there isn't any problem Attach two screenshoot Screen Shot 06-07-24 at 12 13 PM 001 Screen Shot 06-07-24 at 12 13 PM with the configuration.

Why can't I be able do it?

Thanks in advanced

SergioManuelAema commented 4 months ago

The broker is mosquitto

vogler75 commented 4 months ago

TCP protocol does not work from a web browser. You must use ws:/ and more better wss:/ With just ws you need to allow insecure connections in your browser settings. Check if websocket is enabled in your broker.

SergioManuelAema commented 4 months ago

I have enabled the websocket in my broker and I don´t connect. In MQTT Explorer is Ok (attach screenshoot with the configuration) Screen Shot 06-07-24 at 01 10 PM

In Runtime it does nothing, no status is shown like in your video. Attach the screeshoot Screen Shot 06-07-24 at 01 14 PM

vogler75 commented 4 months ago

Please open the browser's development console and see if there is any error. You are using ws (with out TLS), did you allow unsecure connections in your webbrowsers settings for the page?

vogler75 commented 4 months ago

and mostly MQTT brokers are using /mqtt as the path. like ws://broker.hivemq.com:8000/mqtt

SergioManuelAema commented 4 months ago

The error that ocurre is the following: image

I am using Microsoft Edge; The ip 192.168.51.172 is the web server of Unified. Server mosquitto permit access anonymous The configuration of CWC is the following: image The configuration of MQTT Explorer is the same as CWC and It is run Ok image

T

vogler75 commented 4 months ago

WebCC is not defined, did you follow this: You have to download the webcc.min.js from SIEMENS and save it to the control/js directory ! You can get it out of a Custom Web Control example from here

SergioManuelAema commented 4 months ago

When I copied the webcc.min.js file to the control/js folder, this error was already solved, but now I get this image In my broker, port 8883 is secure with certificates, but in the CWC I do not see the option to incorporate the certificate to be able to connect. Do you know how I can solve it?

Thanks

vogler75 commented 4 months ago

you used "ws:" and not "wss:" change it to wss: and check the "use SSL" property of the cwc. currently there is no option to pass a certificate. not sure if it accepts unknown signed certs... please check it.

vogler75 commented 4 months ago

you can import your certificate into your browser and mark it as trusted.

SergioManuelAema commented 4 months ago

My certificate of Unified was already trusted image

SergioManuelAema commented 4 months ago

With the optios wss y use SSL not connected image

vogler75 commented 4 months ago

Check the web browsers console. It seems your broker closes the connection. What kind of broker do you use here?

vogler75 commented 4 months ago

are you using the right port for SSL connection? some pics before you have shown that it works with the MQTT Explorer - without encryption on port 9001. Now you are using wss on the same port. This is typically another port, not the same.

SergioManuelAema commented 4 months ago

I have configured the broker server (mosquitto) wss in port 9002 1.- Mqtt Explorer connect Ok; I had have to add the files of certifcartes (server.crt, ca.cert and server.key) in configuration 2.- Custom Control doesn't conect. I think that the cause is that I can't add in configuration the file of certificates image image

vogler75 commented 4 months ago

we need to check if the paho js lib supports this... https://github.com/eclipse/paho.mqtt.javascript/issues/187

SergioManuelAema commented 4 months ago

Ok. I wait you request. thanks for everything

vogler75 commented 4 months ago

sorry, it seems not to support client auth with certificates. Option would be to change the lib to https://github.com/mqttjs. But this would take some time and effort.

htppseb commented 3 months ago

Hey, i am having the same issue. i would love to see this work. if u need someone to test with let me know. Btw it is working in Tia portal it self. i guess tia does not need an secure connection.

vogler75 commented 3 months ago

it seems there is no way to do this in a browser: https://github.com/mqttjs/MQTT.js/issues/1515

what do you mean with "it is working in Tia portal itself"? You cannot set certificates for the MQTT CWC in the Tia portal. Maybe you are talking about another issue (not the issue to have a mqtt client authentication with certificates).

htppseb commented 2 months ago

Sorry for the late reaction (vacation). I get the same error in the web browser console log. as @SergioManuelAema on 11 July, https://github.com/vogler75/winccua-mqtt-client/issues/2#issuecomment-2160471573 I'm using ws://..... in TIA Portal, then it connects to the broker. When i download to the hmi its not working, probably because the hmi it self also runs web based with https? not sure about that. when i connect to the hmi with the web browser i get the error as mentioned above.

Because wss;// needs an certificate for secure connection but i cant add that to tia portal i thought it was the same issue. But maybe i'm wrong and not understanding it right?

If there is a way to connect with wss or ws on the hmi it self i would love to know about that. (dont need the web browser to work)

vogler75 commented 2 months ago

which version of TIA/Unified do you use? On the panel ws: should work. Unfortunatley wss currently not, even if you add the certificate to the panel. Btw. this is not related to this github issue.