iOS Question How can I send hex value with hm10 ble.

dnaci

Member
Licensed User
Longtime User
Hello. I also added the project file. Help me. Thank you.

B4X:
Public Sub SendMessage(msg() As Byte)
 
    messagesToSend.Add(msg)
    If messagesToSend.Size = 1 Then
        manager.WriteDataWithResponse(ServiceId, WriteChar, msg)
    End If
End Sub

Private Sub Manager_WriteComplete (Characteristic As String, Status As Int)
    If connected = False Or messagesToSend.Size = 0 Then Return
    messagesToSend.RemoveAt(0)
    If messagesToSend.Size > 0 Then
        Try
            manager.WriteDataWithResponse(ServiceId, WriteChar, messagesToSend.Get(0))
        Catch
            Log(LastException)
        End Try
    End If
End Sub

Private Sub Manager_Disconnected
    connected = False
    SetState
    StartScan
End Sub

Sub NewMessage (Data() As Byte)
    txtLogs.Text = BytesToString(Data, 0, Data.Length, "utf8")' & CRLF & txtLogs.Text
End Sub

Sub txtMessage_EnterPressed
    btnSend_Click
End Sub

Sub btnSend_Click
    If txtMessage.Text.Length = "5" Then Return
    Dim s As String = txtMessage.Text
    Dim msg() As Byte = s.GetBytes("utf8")
    SendMessage(msg)
    txtMessage.RequestFocus
    txtMessage.SelectAll
End Sub
 
Last edited by a moderator:
Top