Sub Timer1_Tick
'Structure is: ClientId, Command, Tag, zero or more parameters
'"null" strings will be converted to Null references.
SendInsert(Array(ClientId, "insert_animal", "tag", "abc" , "null"))
'Structure is: ClientId, Command, Tag, zero or more parameters
SendSelect(Array(ClientId, "select_animal", "tag", 539))
End Sub
Sub SendInsert (Message() As Object)
mqtt.Publish("insert", ser.ConvertArrayToBytes(Message))
End Sub
Sub SendSelect(Message() As Object)
mqtt.Publish("select", ser.ConvertArrayToBytes(Message))
End Sub
Sub Mqtt_MessageArrived (Topic As String, Payload() As Byte)
If Topic = ClientId Then
Dim be(10) As Object
Dim data() As Object = ser.ConvertBytesToArray(Payload, be)
If data.Length = 0 Then Return
Dim method As String = data(0) 'ignore
Dim tag As Object = data(1)
If method = "insert" Then
Dim success As Boolean = data(2)
Log(method, " - tag: ", tag, ", success: ", success)
Else if method = "select" Then
Dim numberOfRows As Int = data(2)
Log(method, " - tag: ", tag, ", number of rows: ", numberOfRows)
If numberOfRows = 1 Then
For i = 3 To data.Length - 1
Log(data(i))
Next
End If
End If
End If
End Sub