#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
Private ssid As String = "***" 'ignore
Private password As String = "********" 'ignore
Private channel As Int = 1 'ignore
Private udp As WiFiUDP : Public Ser As Serial
Private timCmd As Timer : Private led As Pin
Private x As Byte = 0 : Private i As Byte
End Sub
Private Sub AppStart
led.Initialize(2, led.MODE_OUTPUT) : led.DigitalWrite(True)
RunNative("setSoftAP", Null)
udp.Initialize(6000,"UDPrec") : Delay(2000) '// delay needed ?
Ser.Initialize(115200) : Delay(1000) '// PIC start-delay 3000
timCmd.Initialize("CMDtim",50) : timCmd.enabled = True
End Sub
Sub CMDtim : Dim buf(1) As Byte : buf(0) = 3
If x <> 0 Then : buf(0) = x : x = 0 : End If
For i = 0 To 2
Ser.Stream.WriteBytes(buf,0,1)
led.DigitalWrite(False) '// ON, led to 3.3 V
Do While (Ser.Stream.ReadBytes(buf,0,1) < 1)
DelayMicroseconds(200) : Loop '// FOR BAD FLASH MEMORY ?
led.DigitalWrite(True)
buf(0) = 47 '// byte 0=3, 1=47, 2=47
Next
End Sub
Sub UDPrec(buf() As Byte, IP() As Byte, Port As UInt)
x = buf(0) '// from B4A Android phone
End Sub
#if C
void setSoftAP(B4R::Object* o) { uint8_t i = 0;
WiFi.softAP(b4r_main::_ssid->data, b4r_main::_password->data, b4r_main::_channel);
while (WiFi.status() != WL_CONNECTED && i++ < 20) delay(500); }
#end if