This is driving me nuts and I'm hoping one of you experts can spot my mistake. I have mosquitto broker installed on a local BeagleBone black listening on their default port 1883. I can successfully publish from my workstation so I know the broker is working correctly. But it fails when I try to connect to the BeagleBone from my Huzzah 8266. The Huzzah successfully grabs an IP from my Netgear router but cannot connect to the server.
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Private WiFi As ESP8266WiFi
Private mqtt As MqttClient
Private ServerIP() As Byte = Array As Byte(192, 168, 1, 111)
Private const ServerPort As UInt = 1883
Private client As WiFiSocket
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
ConnectToNetwork
mqtt.Initialize(client.Stream, ServerIP,ServerPort, "huzzah", "Mqtt_MessageArrived", "Mqtt_Disconnected")
Connect(0)
End Sub
Public Sub ConnectToNetwork
WiFi.Disconnect
Dim SSID As String = "ITM"
Dim Password As String = "400westwhitmandrive"
Log("Trying to connect to: ", SSID, " password: ", Password)
If WiFi.Connect2(SSID, Password) Then
Log("Connected successfully to: ", SSID)
Log(WiFi.LocalIp)
Else
Log("Failed to connect.")
End If
End Sub
Sub Connect(unused As Byte)
If mqtt.Connect = False Then
Log("trying to connect again")
CallSubPlus("Connect", 1000, 0)
Return
End If
Log("Connected to broker")
Dim pub As String = JoinStrings(Array As String("{","test","}"))
mqtt.Publish("dev/test",pub.GetBytes)
End Sub
Sub Mqtt_MessageArrived (Topic As String, Payload() As Byte)
Log("Message arrived. Topic=", Topic, " payload: ", Payload)
End Sub
Sub Mqtt_Disconnected
Log("Disconnected")
mqtt.Close
Connect(0)
End Sub