B4i Library iMQTT - Official iOS MQTT client

Attachments

  • B4i-MQTTCanvas.zip
    2.8 KB · Views: 132
Last edited:

RichardHirst

Member
Licensed User
Longtime User
Hello Erel.

Very interested in this library.. Installed the lastest IDE and libs. I receive the error "<B4IExceptionWrapper: (null)>" when I run the app. Connection Error.

Any help would be great

Richard
 

Hypnos

Active Member
Licensed User
Longtime User
Hi All,

I'm now testing the MQTT library, eveything ok if I using host builder but if I using my own mac local builder, the app will quit immediately after I run it. seems the problem related to my local builder.

I download the library from : www.b4x.com/b4i/files/iMQTT.zip
and put the iMQTT.h and libiMQTT.a into the Libs folder

Build Server version : 2.3

Any hints?

Thanks!
 

gjt211

Member
Licensed User
Hi Erel,

I have downloaded the attached file in the first post, but how do I open it in B4i?
 

cloner7801

Active Member
Licensed User
Longtime User
Hello Erel.

Very interested in this library.. Installed the lastest IDE and libs. I receive the error "<B4IExceptionWrapper: (null)>" when I run the app. Connection Error.

Any help would be great

Richard
I have this problem too.

How can I fix this?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

Descartex

Well-Known Member
Licensed User
Longtime User
Hi.
When i try to run this sample, changing the data for my cloudMQTT account... it raises an error
Application_Start
MQTTSessionManager connecting
Application_Active
MQTTSessionManager reconnecting
Unexpected event (missing RaisesSynchronousEvents): mqtt_disconnected
<B4IExceptionWrapper: (null)>
<B4IExceptionWrapper: (null)>
Error occurred on line: 55 (Main)
-[__NSCFString setDataBuffer:]: unrecognized selector sent to instance 0x155fa050
Stack Trace: (
CoreFoundation <redacted> + 154
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 202
CoreFoundation <redacted> + 706
CoreFoundation _CF_forwarding_prep_0 + 24
MQTT Example -[MQTTDecoder stream:handleEvent:] + 1978
CoreFoundation <redacted> + 118
CoreFoundation <redacted> + 196
CoreFoundation <redacted> + 328
CFNetwork <redacted> + 74
CFNetwork <redacted> + 36
CFNetwork <redacted> + 42
CFNetwork <redacted> + 122
CFNetwork <redacted> + 34
CFNetwork <redacted> + 54
CFNetwork <redacted> + 144
CFNetwork <redacted> + 58
CoreFoundation <redacted> + 578
CoreFoundation <redacted> + 14
CoreFoundation <redacted> + 206
CoreFoundation <redacted> + 622
CoreFoundation CFRunLoopRunSpecific + 522
CoreFoundation CFRunLoopRunInMode + 106
GraphicsServices GSEventRunModal + 138
UIKit UIApplicationMain + 1136
MQTT Example main + 108
libdyld.dylib <redacted> + 2
)

on my android version, it runs good, same data.
 

Descartex

Well-Known Member
Licensed User
Longtime User
Yes,
B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: MQTT Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #ProvisionFile: DescartexGeneral.mobileprovision
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private mqtt As MqttClient
    Private mytopic As String
    Private serializator As B4XSerializator
    Type CircleData (x As Double, y As Double, clr As Int)
    Private serverURI As String = "tcp://***.cloudmqtt.com:*****"
    Private canvas1 As Canvas
    Private lblStatus As Label
    Private Panel1 As Panel
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("1")
    NavControl.ShowPage(Page1)
    canvas1.Initialize(Panel1)
    mqtt.Initialize("mqtt", serverURI, Rnd(0, 999999999) & DateTime.Now)
    Dim mo As MqttConnectOptions
    mo.Initialize("myuser", "mypass") 'set user name and password!!!
'    mo.SetLastWill("last", "test iohui".GetBytes("utf8"), 1, False)
    mqtt.Connect2(mo)
    mytopic = "mytopic/" & mqtt.ClientId
End Sub



Private Sub Page1_Resize(Width As Int, Height As Int)
    canvas1.Initialize(Panel1)   
End Sub

Sub mqtt_Connected (Success As Boolean)
    If Success = False Then
        Log(LastException)   
        lblStatus.Text = "Error connecting"
    Else
        lblStatus.Text = "Connected"
        mqtt.Subscribe("mytopic/#", 0)
    End If
End Sub

Private Sub mqtt_Disconnected
    lblStatus.Text = "Disconnected"
    mqtt.Connect
End Sub

Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
    Dim obj As Object = serializator.ConvertBytesToObject(Payload)
    If obj Is CircleData Then
        If Topic = mytopic Then Return 'the circle was already drawn
        Dim cd As CircleData = obj
        DrawCircleData(cd)
    Else 'obj is string
        Dim s As String = obj
        Select s
            Case "clear"
                canvas1.DrawColor(Colors.White)
                canvas1.Refresh
            Case "close"
                'no closing in iOS...
        End Select
    End If
End Sub

Private Sub DrawCircleData(cd As CircleData)
    canvas1.DrawCircle(cd.X * (100dip / 100), cd.Y  * (100dip / 100), 20dip, cd.clr, True, 0)
    canvas1.Refresh
End Sub

Private Sub Page1_Touch(Action As Int, X As Float, Y As Float)
    If mqtt.Connected = False Then  Return
    Dim cd As CircleData
    cd.x = x * (100 / 100dip)
    cd.y = y * (100 / 100dip)
    cd.clr = Rnd(0x80000000, -1)
    DrawCircleData(cd)
    mqtt.Publish2(mytopic, serializator.ConvertObjectToBytes(cd), mqtt.QOS_2_EXACTLY_ONCE, True)
End Sub

Private Sub Application_Background
   
End Sub
s:
 
Top