iOS Question B4RSerializator problem.

tzfpg

Active Member
Licensed User
Longtime User
i using esp8266 MQTT send data to B4A and B4I, but only B4I get the error message.
How to solve it?

ESP8266 code
B4X:
If MqttConnected Then
        Dim robj(3) As Object
        robj(0)="im_online"
        robj(1)=""
        robj(2)=""
        mqtt.Publish2(get_device_id,Ser.ConvertArrayToBytes(robj),False)
End If

B4A code:
B4X:
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
    If selected_device_id=Topic Then
    Dim obj() As Object=rser.ConvertBytesToArray(Payload)
        Dim case_type As String=obj(0)
        If case_type="im_online" Then
            DateTime.DateFormat="yyyy-MM-dd HH:mm:ss"
            Dim date_now As String=DateTime.Date(DateTime.Now)
            sql1.ExecNonQuery2("UPDATE tbl_location SET datetime_online=? WHERE device_id=?",Array As String(date_now,Topic))
        End If  
    End If
End Sub

B4I code:
B4X:
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
    If selected_device_id=Topic Then
    Dim obj() As Object=rser.ConvertBytesToArray(Payload)
        Dim case_type As String=obj(0)
        If case_type="im_online" Then
            DateTime.DateFormat="yyyy-MM-dd HH:mm:ss"
            Dim date_now As String=DateTime.Date(DateTime.Now)
            sql1.ExecNonQuery2("UPDATE tbl_location SET datetime_online=? WHERE device_id=?",Array As String(date_now,Topic))
        End If  
    End If
End Sub

when run B4A all going smooth no error, but in B4I i got this error:
B4X:
Out of bounds. Index=0 Length=0
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  Smart Home Pro       -[B4IArray getObjectFast:] + 224
  CoreFoundation       <redacted> + 144
  CoreFoundation       <redacted> + 292
  Smart Home Pro       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
  Smart Home Pro       -[B4IShell runMethod:] + 448
  Smart Home Pro       -[B4IShell raiseEventImpl:method:args::] + 1648
  Smart Home Pro       -[B4IShellBI raiseEvent:event:params:] + 1580
 Smart Home Pro       +[B4IObjectWrapper raiseEvent:::] + 300
 Smart Home Pro       -[MQTTClient handleMessage:onTopic:retained:] + 232
 Smart Home Pro       -[MQTTSessionManager newMessage:data:onTopic:qos:retained:mid:] + 144
 Smart Home Pro       -[MQTTSession handlePublish:] + 996
 Smart Home Pro       -[MQTTSession decoder:newMessage:] + 2204
 Smart Home Pro       -[MQTTDecoder stream:handleEvent:] + 2260
 CoreFoundation       <redacted> + 216
 CoreFoundation       <redacted> + 244
 CoreFoundation       <redacted> + 308
 CFNetwork            <redacted> + 64
 CFNetwork            <redacted> + 156
 CFNetwork            <redacted> + 88
 CoreFoundation       <redacted> + 1316
 CoreFoundation       <redacted> + 24
 CoreFoundation       <redacted> + 88
 CoreFoundation       <redacted> + 176
 CoreFoundation       <redacted> + 1004
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 104
 UIKitCore            UIApplicationMain + 212
 Smart Home Pro       main + 124
 libdyld.dylib        <redacted> + 4

i saw the the different is when receive the payload()
B4A = picture1
B4I = picture2

Thank you.
 

Attachments

  • picture1.png
    picture1.png
    27.9 KB · Views: 173
  • picture2.png
    picture2.png
    20.4 KB · Views: 186
Last edited:

tzfpg

Active Member
Licensed User
Longtime User
Can you add this line to the B4i code and post the output (post the text not screenshot):
B4X:
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
Dim bc As ByteConverter
Log(bc.HexFromBytes(Payload))

here the result:
B4X:
7E09086465766963655F6461746100083030303030303030303030303030303030303030303031313130313130313131000830303030303030303030303030303030303030303030303030303030303030300008303030303030303030303030303030303030303030303031313031313030313100083030303030303030303030303030303030303030303030303030303030303130000830303030303030303030303030303030303030303030313031303031303031310008303030303030303030303030303030303030303030303030303030303030313000083030303030303030303030303030303030303030303030303030303030303130000801007F
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code returns the exact same result in B4J and B4i:
B4X:
Dim s As String = "7E09086465766963655F6461746100083030303030303030303030303030303030303030303031313130313130313131000830303030303030303030303030303030303030303030303030303030303030300008303030303030303030303030303030303030303030303031313031313030313100083030303030303030303030303030303030303030303030303030303030303130000830303030303030303030303030303030303030303030313031303031303031310008303030303030303030303030303030303030303030303030303030303030313000083030303030303030303030303030303030303030303030303030303030303130000801007F"
Dim ser As B4RSerializator
ser.Initialize
Dim bc As ByteConverter
Dim o() As Object = ser.ConvertBytesToArray(bc.HexToBytes(s))
For Each oo As String In o
   Log(oo)
Next
Log(Asc(oo))
The last string includes a control character, not sure whether it is by design or not.
 
Upvote 0
Top