B4i Library MQTT - MQ Telemetry Transport for B4i

Discussion in 'iOS Libraries' started by Alberto Iglesias, Jan 30, 2015.

  1. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    [​IMG]


    This library was made based on MQTT Protocol

    Installation instructions:

    - Copy the *.a and *.h files into the folder "Libs" in your MAC or in your MAC HOSTED by AnywhereSoftware, normally in "B4i-MacServer\Libs" folder

    -Copy the iMQTT.xml to your custom libraries folder in B4i
    - Select in your REFERENCED LIBRARIES

    [​IMG]

    Version history:
    V2.0.0 (First public release - Donationware):
    - Initial version


    iMQTT

    Author: Alberto Iglesias (alberto@visualnet.inf.br)
    Version: 2



      • MQTT
        Events:
        • Received (Message As String)
        • onConnect (Status As Int)
        • onDisconnect (Status As Int)
        • onInitialized ( As )
        • onPublish (Status As Int)
        • onSubscribe (Topic as String As )
        Methods:
        • ClearWill
        • Connect (Broker As String, Username As String, Password As String, Port As String)
          Connect to Broker
        • Disconnect
          Disconnect from Broker
        • Initialize (EventName As String)
          Initializes the object.
        • IsConnected As BOOL
          Get status of connection
        • Publish: (Topic As String, Payload As String, qos As Int, Retained As BOOL)
          Publish a message to Topic
        • Reconnect
        • Subscribe2: (Topic As String, qos As int)
          Subscribe into a Topic with Quality of Service
        • Subscribe: (Topic As String)
          Subscribe into a Topic
        • Unsubscribe: (Topic As String)
          Unsubscribe a Topic
        Properties:
        • Author As String [read only]
          Author of this Library
        • ClientID As String
          Set/Get the Client ID for broker know who you are. Default = UUID from Device
        • DebugMode As BOOL
          Enable/Disable Debug mode from Library
        • QoS_AtLeastOnce As Int [read only]
          QoS1, At least once: The message is always delivered at least once. It might be delivered multiple times if there is a failure before an acknowledgment is received by the sender. The message must be stored locally at the sender, until the sender receives confirmation that the message has been published by the receiver. The message is stored in case the message must be sent again.
        • QoS_AtMostOnce As Int [read only]
          QoS0, At most once: The message is delivered at most once, or it may not be delivered at all. Its delivery across the network is not acknowledged. The message is not stored. The message could be lost if the client is disconnected, or if the server fails. QoS0 is the fastest mode of transfer. It is sometimes called "fire and forget".
        • QoS_ExactlyOnce As Int [read only]
          QoS2, Exactly once
        • Version As NSString* [read only]
          Library Version


    [​IMG]


    [​IMG]


    How works the MQTT protocol
    [​IMG]


    Communication Infrastructure

    [​IMG]


    [​IMG]

    References:
    http://mqtt.org/
    http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html
    Mosquitto Broker: http://mosquitto.org/



    * This version is fully functional, the only one difference is when publishing a message the text "Donationware" is delivery with your message.
    Please consider a simple €10 donation and I send to you the Library without "Donationware" text in a publish method.

    Already available in B4J too: look in http://www.b4x.com/android/forum/threads/mqtt-mq-telemetry-transport-for-b4j.48184/

    Already available in B4A too: look in http://www.b4x.com/android/forum/threads/mqtt-mq-telemetry-transport-for-b4a.48167/


    [​IMG]
     

    Attached Files:

    Last edited: Jan 30, 2015
    narek adonts, Erel and inakigarm like this.
  2. jndaniels1

    jndaniels1 Member Licensed User

    Hello Alberto.

    Im a bit confused about the *.a/*.h file installation -- I dont have a Mac.
    I develop on a windows machine and use the B4X hosted compiler service.
    Your installation says to put the *.a, *.h files in the B4i-MacServer/Libs folder.
    • Is this only a Mac option?
    • Is it compatible with Anywhere Software hosted compiler service and if so where do these files go on my local windows machine?
    Just seeking a little clarification to keep my app consistent on both platforms.

    searching for B4i-MacServer comes with few results.

    Thank you for the awesome MQTT lib and all your help!!
    Regards
    JEFF D
     
  3. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    Hello Jeff,

    If you don´t have a Mac, you need to ask to Erel to put those files in a Hosted MAC.

    I think in a next versions, can be a option to send the libraries directly from IDE, but for now, you need to send to Erel.

    I use a Macbook with parallels with Windows, then I send the library to my mac.

    For compile a B4i source code, you need a Mac and Xcode instaled, then if you have only windows you need a hosted service or a Mac.

    Regards.

    Alberto
     
  4. narek adonts

    narek adonts Well-Known Member Licensed User

    Erel,

    Please update it to the hosted server. I think this is a great library. A lot of projects can be achieved with it.

    Narek
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    It is problematic as this is not a free library.
     
  6. jndaniels1

    jndaniels1 Member Licensed User

    Eventually I will get a Mac - but for the time will a service like macincloud.com work? It says it comes with Xcode and lots of dev tools and is true apple hardware.

    Regards
    JEFFD
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Yes, it should work.
     
  8. jndaniels1

    jndaniels1 Member Licensed User

    Can one point me the link to down load the B4i-MacBuilder please. I'd greatly appreciate it!

    JEFF Daniels
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Please contact support@basic4ppc.com.
     
  10. klarsys

    klarsys Active Member Licensed User

    @Erel, please add this library to the hosted server.
     
  11. klarsys

    klarsys Active Member Licensed User

    @Alberto Iglesias,

    1. How do I set keep alive interval and LWT?
    2. Also, I do not get any even on connection failure? e.g. when broker is incorrect.
    3. In objMqtt_Received, how do I know what topic I received that message on?
     
    Last edited: May 28, 2015
  12. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    In B4A Mqtt library is implemented look: setWill but in B4i not yet implemented.

    If cannot connect with broker you receive in the event with error.
     
  13. klarsys

    klarsys Active Member Licensed User

    Oh! But I found following in MQTTKit.h:

    Code:
    - (void)setWillData:(NSData *)payload
                toTopic:(NSString *)willTopic
                withQos:(MQTTQualityOfService)willQos
                 retain:(BOOL)retain;
    - (void)setWill:(NSString *)payload
            toTopic:(NSString *)willTopic
            withQos:(MQTTQualityOfService)willQos
             retain:(BOOL)retain;
    - (void)clearWill;
    Please add this feature.

    I could not find onError event. Please share an example.

    Also, I need to know topic on receiving a message.
     
  14. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    Don´t worry, tomorrow I include the setWill method and check the error events....


    and put a updated version of library ok!
     
    klarsys likes this.
  15. klarsys

    klarsys Active Member Licensed User

    That would be great! Thank you!!
     
  16. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    Hello klarsys,

    test this new version, for this moment is in beta version, if those tests is ok, I put in main thread

    In this version have 3 new properties:

    reconnectDelay;
    reconnectDelayMax;
    reconnectExponentialBackoff;

    and 3 new methods
    setWill
    setWillData
    clearWill
     

    Attached Files:

  17. klarsys

    klarsys Active Member Licensed User

    @Alberto Iglesias, Thank you for updated library.

    Unfortunately, I use hosted build service and hence, cannot test individually myself.

    @Erel, when such libraries are uploaded to build server, are they available for everyone or only for a particular user? Is it safe to upload beta version on build server?
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    The libraries are shared. However I think that for now you are the only one who uses this specific library in the hosted builder.

    I've updated the library.
     
  19. klarsys

    klarsys Active Member Licensed User

    @Erel, I'm getting build errors, I'll send you libraries in PM, just in case.
     
  20. klarsys

    klarsys Active Member Licensed User

    Hi @Alberto Iglesias, @Erel, I'm getting this error when trying to build with setWill:

    Untitled.png

    I'm confused why the error talks about B4ILocationManager.
    My project (attached) doesn't even refer to location manager.

    This possible hints similar observation about conflict with location manager library (discussed here: MQTT library on hosted Mac builder)

    Request a fix for this issue.
     

    Attached Files:

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