Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Dim wsc As WebSocketClient
Dim st As WiFiServerSocket
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
'example of connecting to a local network
If wifi.Connect2("******", "*******") Then
Log("Connected to network")
Else
Log("Failed to connect to network")
End If
wsc.Initialize("incoming","loggedOff") ' routines to handle the data we get or handle disconnection
Log("after init")
connect(0)
Log("after host connect")
' set up some data we want to send
Dim datamap() As String = Array As String("key1","data1") ' can use this or just use Array As String(...)
Log("after datamap")
' send it to the server
' the function to run on server MUST have an underscore in name XXXXX_YYYYYY one at the start like _fred won't work
wsc.SendEventToServer("hello_there",Array As String("key1","value1")) ' run the sub hello_there on the server with the supplied datamap.
Log("after send to server")
End Sub
Sub connect(unused As Byte)
' the sneaky st.Socket.Stream caught me out - stop hiding things so deep lol
If wsc.ConnectHost(st.Socket.Stream,"192.168.0.12" , 51042, "/test") Then ' must be real address of server
Log("Connected...")
Else
Log("Connection failed")
CallSubPlus("Connect", 1000, 0)
End If
End Sub
public Sub incoming (FunctionName As String, Params() As String)
' handle the server talking to us
' I guess FunctionName is the routine we call in our app with the data supplied (Params)
' do something with FunctionName eg if FunctionName = "doThis" then doThis(Params)
Log(FunctionName)
Log(Params(0))
End Sub
' handle being disconnected
public Sub loggedOff
'Sub loggedOff
Log("disconnected")
End Sub