B4J Library MqttBroker

Discussion in 'B4J Libraries & Classes' started by Erel, Dec 20, 2015.

Similar threads

B4J Tutorial [IoT] MQTT Protocol
B4A Tutorial [B4X] MQTT Chat Room
B4J Question MqttBroker problem
B4A Tutorial [B4X] MQTT - Connect & Reconnect
B4J Question MQTT Connection & messages
  1. Erel

    Erel Administrator Staff Member Licensed User

    jMqttBroker library is based on the moquette open source project: https://github.com/andsel/moquette

    It implements a MQTT broker. If you are not familiar with MQTT then start with this tutorial: http://www.b4x.com/android/forum/threads/59471/#content

    The broker is like a "black box". It is responsible for managing the clients and routing the messages.

    With this library you can embed the broker inside your app instead of using an external broker.

    Note that this library can also be used with B4A. You can turn any Android or Linux board to a MQTT broker.
    With B4A you need to add the INTERNET permission with the manifest editor:
    Code:
    AddPermission(android.permission.INTERNET)
    Using this library is simple:
    Code:
    Sub Process_Globals
       
    Dim broker As MqttBroker
    End Sub

    Sub AppStart (Args() As String)
       broker.Initialize(
    ""51041'first parameter is the event name. It is currently not used.
       broker.Start
       StartMessageLoop 
    'Non-UI app
    End Sub
    Download link: www.b4x.com/b4j/files/moqueutte.zip
     
    Last edited: Sep 25, 2016
    Peter Simpson, besoft, jmon and 15 others like this.
  2. b4auser1

    b4auser1 Well-Known Member Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    You can set a single user name and password with broker.SetUserAndPassword.

    The other authorization methods are not exposed.
     
    Peter Simpson likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    V1.01 was released (same link as before). It fixes an issue related to the LastWill message.
     
  5. b4auser1

    b4auser1 Well-Known Member Licensed User

    Is it possible to setup SSL ?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Currently no.
     
  7. woniol

    woniol Active Member Licensed User

    Hi,
    I tried it with jMQTT client, and every time i publish a message from the client i get this in the server logs:
    Code:
    Serious error processing the message org.eclipse.moquette.proto.messages.PubAckMessage@58121280 for session [clientID: fsdfsdf]org.eclipse.moquette.server.netty.NettyChannel@3ad9b9ea
    Is it normal, or am I doing something wrong?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

  9. freedom2000

    freedom2000 Well-Known Member Licensed User

    thank you for this --> very good features for home automation
     
  10. woniol

    woniol Active Member Licensed User

  11. woniol

    woniol Active Member Licensed User

    What's the problem with QOS 1 and QOS 2, can't we use it with b4j broker?
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Not sure why it doesn't work for you with QOS 1 or 2. It works here when I test it (slower but works).
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    I do see this error message in the logs though everything seems to work fine. It looks like a problem inside the moquette project.
     
  14. woniol

    woniol Active Member Licensed User

    One more thing,
    although i set credentials on for the broker with
    Code:
    broker.SetUserAndPassword("user","pass")
    I can connect to it with
    Code:
    client.Connect
    When I use
    Code:
    client.Connect2(MqttConnectOptions)
    , credentials are veryfied.
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    This is indeed a bug. It is fixed in v1.03 (same link as before).
     
  16. woniol

    woniol Active Member Licensed User

    Credentials work fine now, thanks for the fix.

    Here is a short example of the problems with setting QOS.
    It looks like it has something to do with Subscribe QOS, try to change it to 1 or 2

    In all Subscribe QOS settings, when i publish a message with QOS2 it is published with payload lenght = 0 (see the example)
     

    Attached Files:

  17. Erel

    Erel Administrator Staff Member Licensed User

    The problem is inside the open source project. For now you should use QOS 0 or 1.
     
  18. woniol

    woniol Active Member Licensed User

    Ok, undertood, thanks for the explanation.
     
  19. fishwolf

    fishwolf Active Member Licensed User

    I have done a No-UI application B4J with broken library and 3 lines of code.

    I'm try to use the B4A chat example and the connection failed.

    any suggestion?
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    The broker library should work in UI app. If you aren't able to solve it then please start a new thread and provide more information.
     
Loading...