Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Private mqtt As MqttClient
Private socket As WiFiSocket
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
If wifi.Connect("dlink") = False Then
Log("Failed to connect to network.")
Return
End If
mqtt.Initialize(socket.Stream, Array As Byte(192, 168, 0, 36), 1883, _
"esp2", "mqtt_MessageArrived", "mqtt_Disconnected")
Connect(0)
End Sub
Sub Connect(u As Byte)
Log("Connecting...")
If mqtt.Connect Then
Log("connected")
Log(mqtt.Subscribe("#", 0))
Else
CallSubPlus("Connect", 1000, 0)
End If
End Sub
Sub mqtt_Disconnected
Connect(0)
End Sub
Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
Log("Message arrived: ", Topic, " ", Payload)
End Sub