I want to make a Mqtt device, for that, they need to send unique topics, the MAC is a good option:
somename/MAC/somefunction
somename/MAC/somefunction
But as JoinStrings is said to be an expensive function, it should be more convenient to create the topics at the start and reuse them. I tried GlobalStore with no success.
In AppStart:
And then use it like:
And, in the other side, the Topic recived is something like this: "1073669004" instead of the text
Is the GlobalStore the correct way to do this?
somename/MAC/somefunction
somename/MAC/somefunction
But as JoinStrings is said to be an expensive function, it should be more convenient to create the topics at the start and reuse them. I tried GlobalStore with no success.
In AppStart:
B4X:
GlobalStore.Put(0, JoinStrings(Array As String("home/", MyMac, "/out")))
'Also:
Dim Topic As String = JoinStrings(Array As String("home/", MyMac, "/in"))
GlobalStore.Put(1, Topic)
And then use it like:
B4X:
mqtt.Subscribe(GlobalStore.Slot0, 0)
mqtt.Publish(GlobalStore.Slot1, Serializator.ConvertArrayToBytes(Array(iBtnNum, iState)))
B4X:
Sub Mqtt_MessageArrived (Topic As String, Payload() As Byte)
Log("Topic: ", Topic)
Log ("Slot1: ", GlobalStore.Slot1)
'In the logs it prints the correct text, but this fails:
If Topic = GlobalStore.Slot1 Then
'Not true
Else
Log("Topic <> Slot1")
End If
'It prints: "Topic <> Slot1"
End Sub
And, in the other side, the Topic recived is something like this: "1073669004" instead of the text
Is the GlobalStore the correct way to do this?