Sub Process_Globals
Public serial1 As Serial
Public wifi As SoftwareSerial
Private astream As AsyncStreams
'Private astream1 As AsyncStreams
Private tmr1 As Timer
Private astream As AsyncStreams
Private bc As ByteConverter
Private ana, in3, out7 As Pin
Private eol() As Byte = Array As Byte(13, 10)
Private q() As Byte = Array As Byte(0x22)
End Sub
Private Sub AppStart
serial1.Initialize(9600)
'astream1.Initialize(serial1.Stream, Null, Null)
wifi.Initialize(9600,6,5)
astream.Initialize(wifi.Stream, "astream_NewData", Null)
tmr1.Initialize("tmr1_Tick", 20000)
tmr1.Enabled = False
Log("AppStart")
ana.Initialize(ana.A0, ana.MODE_INPUT)
in3.Initialize(3, in3.MODE_INPUT_PULLUP)
out7.Initialize(7, out7.MODE_OUTPUT)
astream.Write("AT+RST".GetBytes) 'reset wifi
astream.Write(eol)
Delay(1000)
astream.Write("AT+CWMODE=1".GetBytes) 'station mode
astream.Write(eol)
Delay(1000)
'Connect To AP, ADD YOUR ROUTER SSID And PASSWORD
astream.Write("AT+CWJAP=".GetBytes)
astream.Write(q)
astream.Write("Sagemcom-GPHQR3".GetBytes) 'change to your router SSID
astream.Write(q)
astream.Write(",".GetBytes)
astream.Write(q)
astream.Write("XXXXXX".GetBytes) 'enter your router password
astream.Write(q)
astream.Write(eol)
Delay(5000)
Delay(500)
tmr1.Enabled=True
End Sub
Sub tmr1_Tick
Dim msg(8) As String
Dim sl As Byte
Dim sl1 As String
If in3.DigitalRead Then msg(5)="OFF" Else msg(5)="ON"
msg(0) = "GET /a31.php?v1="
msg(1) = 0
msg(2) = "&v2="
msg(3) = ana.AnalogRead
msg(4) = "&v3="
msg(6) = " HTTP/1.1"
msg(7) = "HOST: moty22.co.uk" 'change To your website address
sl = msg(0).Length+msg(1).Length+msg(2).Length+msg(3).Length+msg(4).Length+msg(5).Length+msg(6).Length+msg(7).Length+6
sl1=sl
web_page
Delay(1000)
astream.Write("AT+CIPSEND=".GetBytes)
astream.Write(sl1.GetBytes)
astream.Write(eol)
Delay(1000)
astream.Write(msg(0).GetBytes)
astream.Write(msg(1).GetBytes)
astream.Write(msg(2).GetBytes)
astream.Write(msg(3).GetBytes)
astream.Write(msg(4).GetBytes)
astream.Write(msg(5).GetBytes)
astream.Write(msg(6).GetBytes) '" HTTP/1.1"
astream.Write(eol)
astream.Write(msg(7).GetBytes) '"HOST: moty22.co.uk"
astream.Write(eol)
astream.Write(eol)
End Sub
Sub web_page
astream.Write("AT+CIPSTART=".GetBytes)
astream.Write(q)
astream.Write("TCP".GetBytes)
astream.Write(q)
astream.Write(",".GetBytes)
astream.Write(q)
astream.Write("moty22.co.uk".GetBytes)
astream.Write(q)
astream.Write(",80")
astream.Write(eol)
End Sub
Sub astream_NewData (Buffer() As Byte)
Dim reply() As Byte
Dim off() As Byte = Array As Byte(0x4F,0x46) 'OF
Dim on() As Byte = Array As Byte(0x4F,0x4E) 'ON
If Buffer.Length > 80 Then
reply=bc.SubString2(Buffer, Buffer.Length - 3, Buffer.Length-1)
If bc.ArrayCompare(reply, off)=0 Then out7.DigitalWrite(False)
If bc.ArrayCompare(reply, on)=0 Then out7.DigitalWrite(True)
End If
End Sub