Android Question Problem re-establishing http connection after changing WiFi connection

Acuario

Active Member
Licensed User
Longtime User
I'm using MLwifi to connect to an ESP8266 in AP mode and configure it. After configuration I want to swap back to my original WiFi connection and continue connected to the original WiFi network.

I can successfully connect to the ESP8266 and send the configuration information. I then force the ESP8266 to reboot (so the AP disappears).
The problem is that when I reconnect to my original WiFi my app can no longer communicate via http.

Here is a log:
Reconnect to original WiFi:
[MLwifi] Connected to PCSystem
Connected to WiFi = true
                        
                        
    '///   Disconnect pressed
disconnectWifiAP = true
Wifi_ConnectionResult = true
Connected - false
IP address - 192.168.4.2
Is online - true
SSID - PCSystem
5GHz - true
Ping returned true
                        
   '/// Disconnect pressed again
disconnectWifiAP = true
Wifi_ConnectionResult = true
Connected - true
IP address - 192.168.0.119
Is online - true
SSID - Terrapico
5GHz - true
Ping returned true

   '/// Now a call to 192.168.0.105 which is on the network and is active and will return data
  
ResponseError. Reason: java.net.SocketException: socket failed: ENONET (Machine is not on the network), Response:
Website response (settings):java.net.SocketException: socket failed: ENONET (Machine is not on the network)

On returning to the original WiFi my phone correctly connects to my WiFi and I can browse/ping etc. but my app returns a SocketException.
I use the disconnectWiFiAP to disconnect and connectWiFiAP to connect to the ESP8266 then disconnectWiFiAP to disconnect from the ESP8266 and let the phone reconnect to the original WiFi network.
I have tried forcing a connection to the original WiFi using connectWiFiAP but that returns an error saying it's not available. Just letting it reconnect itself seems to work for everything except my app. If I restart my app it then correctly connects and can communicate with the device at 192.168.0.105

Is it possible that my app is trying to communicate via the 4G network instead of the WiFi network?
 

Acuario

Active Member
Licensed User
Longtime User
I've ruled out the 4G connectivity by setting airplane mode on and wifi on. Same result.
If I reconnect to the AP then I once again get connectivity.
It seems something in the HttpJob isn't getting cleared. In my code it is declared as private in a sub so should get created/destroyed with each call to the sub so shouldn't be influenced by previous instances.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
If both your ESP and your Phone are connected to the same network then you shouldn't have an issue, but if they are not connected to the same network but they are both on the internet as in ESP via LAN and Phone via 4G, then you should try using MQTT via a free online service to send data from your phone to your ESP.
 
Upvote 0
Top