Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Private server As WiFiServerSocket
Private astream As AsyncStreams
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Log(wifi.StartAccessPoint("esp_server"))
Delay(200)
RunNative("SetAP", Null)
Delay(200)
Log(wifi.LocalIp)
Log(wifi.AccessPointIp)
server.Initialize(80, "server_NewConnection")
server.Listen
End Sub
#if C
void SetAP(B4R::Object* o) {
const char *ssid = "ESP32ap";
const char *password = "12345678";
// Serial.begin(115200);
// Serial.println("Configuring access point...");
//WiFi.mode(WIFI_AP_STA);
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid, password);
//Serial.println("Wait 100 ms for AP_START...");
delay(100);
//Serial.println("Set softAPConfig");
IPAddress Ip(192, 168, 10, 1);
//IPAddress Ipgw(192, 168, 1, 1);
IPAddress NMask(255, 255, 255, 0);
WiFi.softAPConfig(Ip, Ip, NMask);
}
#end if
Sub Server_NewConnection (NewSocket As WiFiSocket)
astream.InitializePrefix(NewSocket.Stream, False, "astream_NewData", "astream_Error")
astream.Initialize(NewSocket.Stream, "astream_NewData", "astream_Error")
Log("new connection")
End Sub
Sub astream_NewData (Buffer() As Byte)
Log(Buffer)
'server.Socket.Close 'disconnect to allow new connections
End Sub
Sub astream_Error
Log("error")
server.Listen
End Sub