B4i Library MQTT - MQ Telemetry Transport for B4i

Alberto Iglesias

Well-Known Member
Licensed User



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



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








How works the MQTT protocol



Communication Infrastructure






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/


 

Attachments

Last edited:

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
 

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
 

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
 

jndaniels1

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

JEFF Daniels
 

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:

klarsys

Active Member
Licensed User
but in B4i not yet implemented
Oh! But I found following in MQTTKit.h:

B4X:
- (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.

If cannot connect with broker you receive in the event with error
I could not find onError event. Please share an example.

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

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?
 
Top