Android Question MQTT with CA file

Discussion in 'Android Questions' started by August Jimenez, Oct 18, 2018.

  1. August Jimenez

    August Jimenez Member Licensed User

    HI,

    I'm developing a MQTT client and I would like to know how to connect with a broker using a certificate file.

    The connection must use mqtts/tls protocol.

    Thanks
     
  2. udg

    udg Expert Licensed User

    In my Starter service, I use something like this:
    Code:
    Sub Process_Globals
      
    Private mqtt As MqttClient 
      
    Private ServerAndPort As String = "ssl://<your MQTT broker IP address>:<port number>"
      ...
    End Sub

    Public Sub Connect(ThisUser As TUser)
       CurrentUser = ThisUser    
    'this is a type used in my program, you can use a simple integer
       If mqtt.Connected Then mqtt.Close
       mqtt.Initialize(
    "mqtt", ServerAndPort, CurrentUser.Name)
       
    Dim mo As MqttConnectOptions
       mo.Initialize(ThisUser.Name,ThisUser.Pwd)
       
    'this message will be sent if the client is disconnected unexpectedly.
       mo.SetLastWill("servizio/disconnect", CurrentUser.Name.GetBytes("UTF8"), 0False)
       mqtt.Connect2(mo)
    End Sub
    Main calls Connect when needed.

    My MQTT broker server resides on a cheap VPS server where I installed a free Let'sEncrypt certificate which I have to renew every three months.
     
  3. August Jimenez

    August Jimenez Member Licensed User

    Thanks udg, but I need also to add a CA file. If not, I wil not connect with the broker.

    Regards
     
  4. udg

    udg Expert Licensed User

    Sorry, I missed the "file" part of your question. Time for a coffe..
     
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. August Jimenez

    August Jimenez Member Licensed User

    Udg, of course ;-)

    Erel, I need to authenticate the client.

    Thanks to both.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    This is currently not supported.
     
  8. August Jimenez

    August Jimenez Member Licensed User

    Thanks, Erel. I have used the second option you have mentioned, and it works, without specified the CA file.

    I will open another thread about the publish method.

    Regards
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice