B4R Question MQTT Arrived text message from B4A cannot be decoded by B4R

Discussion in 'B4R Questions' started by Jan Kanon PA7X, Jun 11, 2018.

Similar threads

B4R Tutorial MQTT
B4R Tutorial ESP8266 + Relay = Let there be light
B4A Tutorial [B4X] MQTT Chat Room
B4R Library RDC based on MQTT
B4A Tutorial [B4X] MQTT - Connect & Reconnect
  1. Jan Kanon PA7X

    Jan Kanon PA7X Member Licensed User

    Hi All,

    Almost finalizing my project i have a problem decoding the text message send from Android (B4A code) by MQTT to Arduino (B4R code)

    My Arduino receiving code is :

    Sub MQTT_MessageArrived (Topic As String, Payload() As Byte)
    Dim BC As ByteConverter
    Log("Topic = ", Topic, " and Payload = ", BC.StringFromBytes(Payload))
    End Sub

    My Android sending code is :

    Sub ButtonLeft_Touch(Action As Int, X As Float, Y As Float)
    Select Action
    Case Activity.ACTION_DOWN
    lblStatus.Text = "Draaien naar Links"
    CallSub2(Starter, "SendMessage", "TLEFT")
    Case Activity.ACTION_UP
    lblStatus.Text = "Stop draaien naar Links"
    CallSub2(Starter, "SendMessage", "SLEFT")
    End Select
    End Sub

    Result in log after touching left button is :

    Topic = SmartMove and Payload = x�cde``�qu

    Topic = SmartMove and Payload = x�cde``�qu

    To process further i need the values TLEFT and SLEFT

    Any advices /solutions ?

    Best regards, Jan
  2. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    Use the code style to facilitate and make it faster
  3. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    The problem is not in the B4R code, but in the Android code
    Dim control As String

    Erel likes this.
  4. Jan Kanon PA7X

    Jan Kanon PA7X Member Licensed User

    Hi Johan,

    Thanks for you reply and this solved my problem ! Also thanks for advise using the code style,
    i did not know that feature.

    Best regards, Jan
    Johan Hormaza likes this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    The best option is to use B4RSerializator.
    Johan Hormaza likes this.
  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