Sub AppStart (Args() As String)
Private i,j As Int
clientID = "BUFTEST" & Rnd(0, 999999999) & DateTime.Now
working=True
ConnectAndReconnect 'Connect to MQTT Server
Do While mqtt.Connected=False
Loop
For i= 0 To 57
wsnpkt(i)=72 ' CREATE a 58 byte packet - fill with 72 (dummy data)
Next
' Fill out the fields that remain the same
wsnpkt(0)=0xFF ' Start of Frame
wsnpkt(1)=0xFF
wsnpkt(56)=0xAA ' End of Frame
wsnpkt(57)=0xAA
seqno=0
For i = 1 To 3000
wsnpkt(2)=make8(seqno,1) ' insert Seq# - High Byte
wsnpkt(3)=make8(seqno,0)
csum=checksum(wsnpkt) ' Calculate a checksum
wsnpkt(54)=make8(csum,1) ' insert checksum - High Byte
wsnpkt(55)=make8(csum,0)
If mqtt.Connected Then
Try
mqtt.Publish(ctopic,wsnpkt)
seqno=seqno+1
Catch
Log ("Exception..")
End Try
For j = 1 To 10000 ' 10000 seems to be the right delay
'delay
Next
End If
Next
Log("DONE ...")
StartMessageLoop
End Sub
Sub ConnectAndReconnect
Do While working
If mqtt.IsInitialized Then mqtt.Close
mqtt.Initialize("mqtt", server, clientID)
Private mo As MqttConnectOptions
mo.Initialize(user, password)
Log("Connecting to MQTT Server: " & server)
mqtt.Connect2(mo)
Wait For mqtt_Connected (Success As Boolean)
If Success Then
Log("Mqtt is connected")
Do While working And mqtt.Connected
Sleep(10000)
Loop
Log("Mqtt is Disconnected")
Else
Log("Mqtt Error connecting.")
End If
Sleep(10000)
Loop
End Sub