B4A Library jMQTT - Official Android MQTT client

Discussion in 'Additional libraries, classes and official updates' started by Erel, Oct 20, 2015.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Attached Files:

    Last edited: Oct 20, 2015
  2. sixteen

    sixteen Member Licensed User

    Hi,Erel,Where can I download the lib? thanks a lots!

    I had found it!,thanks for your works~!
     
    Last edited: Oct 21, 2015
  3. Erel

    Erel Administrator Staff Member Licensed User

    In case it is not clear, the jMQTT is a B4A and B4J library.
     
    JakeBullet70 and DonManfred like this.
  4. coslad

    coslad Active Member Licensed User

    So, mqtt can replace push framework!!! Good!
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    That is not really correct. The main advantage of GCM (Google push service) is that it will work even if the process is not running. This is not the case with any other solution that requires an active network connection.
     
  6. b4auser1

    b4auser1 Well-Known Member Licensed User

    The canvas client works perfectly with the MQTT Broker on tcp port.
    I tried to use SSL port in URI for mqtt.Initialize and got the error:
    "(SocketException) java.net.SocketException: Connection reset".

    How to setup mqtt client to use SSL ?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    The ServerURI should start with ssl:// instead of tcp://
     
  8. b4auser1

    b4auser1 Well-Known Member Licensed User

    Erel,

    Thank you very much !
    With "ssl://" it works.
     
  9. sarmanho

    sarmanho Member Licensed User

    Erel,
    Which brokers MQTT do you recommend for thousands of simultaneous connections?
    What is the best brokers MQTT?
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Mosquitto is a very popular broker. I haven't run any server side performance tests.
     
  11. Mr Mo

    Mr Mo Member Licensed User

    Hi all,
    I am just a one week newbie. My first try is working with jMQTT.
    My application dialog with an Arduino broker via Wifi. The Arduino is connected by Nrf24L01 to 3 sensors.
    I have no problem with subcribed message.
    If I try to publish... it seem not working.
    The topic is MyMQTT/21/1/V_LIGHT and the payload must be "0" or "1".
    For information I have other application working with this Arduino broker.
    Here is the code for publishing.
    Any help welcome.

    Code:
    Sub tbnLight_CheckedChange(Checked As Boolean)
        
    Dim msg(1As Byte
        
    Select tbnLight.Checked
            
    Case True
                msg(
    0) = 0x31
            
    Case False
                msg(
    0) = 0x30
        
    End Select
        
    Log("Sent Payload: " & BytesToString(msg, 0, msg.Length, "utf8"))
        
    Try
            mqtt.Publish(
    "MyMQTT/21/1/V_LIGHT",msg)
        
    Catch
            
    Log(LastException)
            
    If mqtt.Connected = False Then
                mqtt.Connect
            
    End If
        
    End Try
    End Sub
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this (in the questions forum).
     
  13. TommyBee

    TommyBee Member Licensed User

    I tried to use SSL port in URI for mqtt.Initialize and got the error:
    (CertificateExpiredException) java.security.cert.CertificateExpiredException

    I use my own Cloudmqtt, the unsecure connection works fine, what's to do to fix that? :confused:
    Thanx in advance.
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Note that the URI should start with ssl:// instead of tcp://. However currently self signed certificates are not supported by this library.
     
  15. TommyBee

    TommyBee Member Licensed User

    Yes indeed, it starts with ssl://
    I use no self signed certificates, i just try to connect to ssl://m20.cloudmqtt.com:27019 then i get this error.
    With tcp://m20.cloudmqtt.com:17019 it works.
     
  16. TommyBee

    TommyBee Member Licensed User

    Hi Erel,
    could you please add this Paho-Callback to the library:

    deliveryComplete
    void deliveryComplete(IMqttDeliveryToken token)
    Called when delivery for a message has been completed, and all acknowledgments have been received. For QoS 0 messages it is called once the message has been handed to the network for delivery. For QoS 1 it is called when PUBACK is received and for QoS 2 when PUBCOMP is received. The token will be the same token as that returned when the message was published.

    Think it's essentielly needed in most all cases.
    Thank's in advance ;)
     
    cimperia and rboeck like this.
  17. Erel

    Erel Administrator Staff Member Licensed User

    Why do you need it? If you need to make sure that the message is delivered then set the QOS to 1 or 2. If it will not be delivered then the connection will break.
     
  18. oymyakon

    oymyakon Member Licensed User

    Hi,
    When i receive a payload i get [B@996b933 instead of the string i sent (20.6 C, 6.0, -57) can you help paul.
     
    liuje likes this.
  19. Erel

    Erel Administrator Staff Member Licensed User

    Payload is an array of bytes. It is not a string.

    You can convert it to a string with:
    Code:
    Log(BytesToString(Payload, 0, Payload.Length, "utf8"))
     
  20. haungmaojung

    haungmaojung Member Licensed User

    Hi Erel,
    1. I found that jMQTT library did not support client to set up LWT (Last Will Testment)
    2. I've setup a client (MQTT-Spy running on my NB computer) to publish message with
    a last will message> Will-Topic: 'LastWill/Sensor1' Will-Payload: 'sensor lost contact'
    3. Then I created a situation(unplug RJ45 cable) to simulate network error to
    cause Broker to publish Last will message
    4. In my B4A android device, I've subscribe this topic(modify MQTTCanvas sample)
    5. When KeepAlive interval timeout, MQTTCanvas received a message callback,
    but it prompts Error Occurred
    ---------------------------------------------------------------------
    An error has occurred in sub:main_mqtt_messagearrived(java
    line: 487)
    java io.IOException
    Continue?


    I found the error line 487 in b4a java source code which is
    ......
    //BA.debugLineNum = 83;BA.debugLine="obj = serializator.ConvertBytesToObject(Payload)";
    _obj = _serializator.ConvertBytesToObject(_payload);
    ....

    Did I miss something? Please help.

    Best Regards,
    Victor
     
Loading...