Sub Process_Globals
Public Serial1 As Serial
Public WiFi As ESP8266WiFi
Public ESP8266 As ESP8266
Private mqtt As MqttClient
Public WiFiClient As WiFiSocket
Private username As String = "*****"
Private passWD As String = "*****"
Type TipoTab (Val1 As String, Val2 As String, Val3)
Dim ValTypeRx As TipoTab
Dim ValTypeTx As TipoTab
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
If WiFi.Connect2(************", "**********") Then
Log("Connected to : ", "WiFi")
Dim serverIp() As Byte = Array As Byte(192, 168, 1, 31)
Log("my IP : ", WiFi.LocalIp)
mqtt.Initialize(WiFiClient.Stream, serverIp, 28029, "wemos_client", "Mqtt_MessageArrived", "Mqtt_Disconnected")
Connect(0)
Else
Log("Failed to connect.")
End If
End Sub
Sub Connect(unused As Byte)
Dim mo As MqttConnectOptions
mo.Initialize(username,passWD)
Log("Mqtt Inizialize")
Delay(1000)
If mqtt.Connect2(mo) = False Then
Log("Trying to connect again")
CallSubPlus("Connect", 1000, 0)
Return
End If
Log("Connected to broker")
mqtt.Subscribe("MSE24_Dt", 0)
Delay(600)
End Sub
Sub Mqtt_Disconnected
Log("Disconnected")
mqtt.Close
Connect(0)
End Sub
Sub Mqtt_MessageArrived (Topic As String, Payload() As Byte)
Dim obj As Object = Serializator.ConvertBytesToObject(Payload)
If obj Is TipoTab Then
Log("TipoTab")
End If
End Sub