I try to connect NodeMcu and Android.
The NodeMcu code as server ( with Cableguy's example):
B4X:
Sub Process_Globals
Public Serial1 As Serial
Private Server As WiFiServerSocket
Private Wstream As AsyncStreams
Private APSSID As String = "esp"
Public WiFi As ESP8266WiFi
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Select WiFi.StartAccessPoint(APSSID)
Case 1
Log("Access Point Initialisation Successful")
Log("SSID: ",APSSID)
Log("ip: ", WiFi.AccessPointIp)
Server.Initialize(80,"Server_NewConnection")
Server.Listen
Case 0
Log("Something Went wrong!")
WiFi.Disconnect
End Select
End Sub
Sub Server_NewConnection(NewSocket As WiFiSocket)
Log("new connection")
Wstream.Initialize(NewSocket.Stream,"Wstream_NewData", "Wstream_Error")
Wstream.Write("ok".GetBytes())
End Sub
The B4A code as client:
B4X:
Sub Activity_Create(FirstTime As Boolean)
Client.Initialize("Client")
...
End Sub
Sub contmr_tick
If Client.Connected = False Then
Client.Connect("192.168.4.1",80,1000)
End If
End Sub
Sub Client_Connected (Successful As Boolean)
If Successful Then
wtmr.Enabled = True
contmr.Enabled = False
Log("Connected to Car")
Else
Log("Failed to connect to Car")
End If
End Sub
Sub wtmr_tick
Astream.Initialize(Client.InputStream, Client.OutputStream,"Astream")
wtmr.Enabled = False
End Sub
The problem is that I start the NodeMcu and get this log:
AppStart
Access Point Initialisation Successful
SSID: esp
ip: 192.168.4.1
In the B4A log I get the log "Connected to Car" which testify that the Client is connected to the server, but in the NodeMcu the event of NewConnection is not fired, I don't get the log "new connection".
Can someone explain ?
Last edited: