MQTT TLS Broker
Hi all,
I have a Flexy 205, and I want to connect it to a broker by MQTT TLS (port 8883). The broker sends to me a CA in format PEM (root.ca.pem). How could do the BASIC script?
Up to now, I have done the next code, but the state of the connection is 3, so the device is trying to connect, but it does not connect.
Addition, the broker tell me that Flexy want to connect but the certificate is unknown, but this certificate is used in other devices and they connect.
I believe that Flexy needs certificate .cert and .key but I do not sure and I do not know how to do it.
Can you help me?
Thanks
-
@sego_yunior
You can definitely use the cert and key files however you will need to ensure they are in the eWON usr directory. How is the MQTT broker sending you certificates? Can you manually transfer them? Are you able to retrieve them via an HTTP GET request? Once you get the certificates you simply need to set the CA/KEY files as a connection parameter after you issue your open request.
MQTT "open", "my_flexy", "my.test.com" MQTT "setparam", "CAFile", "/path/to/pem"
Just ensure to put the pem file into a directory in the eWON.0 -
Hi Jordan,
Thanks for yo answer. I have the CA file and by FTP I have access to folder /usr/ where I create a new folder Ignition/ so I have copied the CA file (root.ca.pem) into folder /usr/Ignition/
My code is:
MQTT "OPEN", SerNum$ , "xxx.xxx.xxx.xxx" // Office Broker
MQTT "setparam", "port", "8883"
MQTT "setparam", "username", "admin"
MQTT "setparam", "password", "changeme"// Una u otra de las opciones las dos no pueden se a la vez.
MQTT "setparam", "cafile", "/usr/Ignition/root.ca.pem"MQTT "SUBSCRIBE","ewon", 0
MQTT "CONNECT"
ConnStatus% = MQTT "STATUS"
Print "state: " ConnStatus%My problem is that "state" always is 3 --> Trying to connect.
I think that I need generate KEY / CERT files and add it to the folder /usr/Ignition/ and the following lines
MQTT "setparam", "certfile", "/usr/Ignition/cert.pem"
MQTT "setparam", "Keyfile", "/usr/Ignition/key.pem"But my question is how can I generate this files from root.ca.pem (CA file)?
Thanks
0 -
@sego_yunior
Are you certain this just isn't an issue with the execution sequence? You aren't waiting for a response to opening the connection. You are simply dropping into checking the connection status. There is going to be some delay in connecting to the server so immediately checking is always going to tell you that you are still connecting (because you are).
Have you tried calling ONMQTTSTATUS to check the status of the connection? Can you try adding this function this to your code and let me know the results?
rem CONTINUING FROM YOUR MQTTCONNECT MQTT "CONNECT" ONMQTTSTATUS '@MqttStatusChange(mqtt("status"))' FUNCTION MqttStatusChange($status%) IF $status% = 5 THEN PRINT "MQTT CONNECTED" ELSE PRINT "MQTT DISCONNECTED" END ENDFNCode taken from page 62 of RG-0006 (programming reference guide)
0 -
Hi Jordan,
Yes, I did it and after 30 - 60 min the state continues equal, even so, I have returned to do it and the result is the same.
0 -
@sego_yunior
Do you have any errors in the event logs? Could you provide me access to this unit?
0 -
Hello, good afternoon, I have a concern, I seek to connect the ewon by mqtt protocol in order to send the data to a broker like mosquito, I have seen some example codes but what is not clear to me is when I make the tag declaration that they will be sent to this broker or there is already a script ready for communication with mosquito.
I send the found scriptsMosquito.txt (1.0 KB) Mqtt Ejemplo.txt (5.5 KB)
0 -
We have an application document document with some helpful links in it on using MQTT with the flexy.
aug-0073-00-en-getting-started-with-mqtt-on-ewon-flexy.pdf
We also have a broker that you can test your connection with.
https://tools.ewonsupport.biz/mqtt/0 -
The first script you posted looks like it just sends a message every 5 seconds that says test plus a number that iterates up.
The ejemplo script checks the number of tags the Flexy has and iteracts through them updating the broker.
Could you clarify what you are trying to do or if you have a question on this?
0 -
my question is in the example script (which is https://tools.ewonsupport.biz/mqtt/) should I declare somewhere in this script the tags that I have already configured in ewon or it automatically sends the tags that you already configure
0 -
The example code that appears in the manual of an implementation with mosquitto is simply to execute it in Basic ide but as it would be possible to check that the data is being published in mosquitto, there is a manual
Mqtt Ejemplo.txt (5.5 KB)
0
Por favor, entrar para comentar.
Comentários
10 comentários