Android Question Bit confused about Wifi

JMB

Active Member
Licensed User
Longtime User
Hi there,

I am clearly going to show my ignorance about sockets and connections and wifi, but I am a little bit confused.

I have written B4R code that creates an ESP point through which I can communicate via a B4J app which sends the Wifi Credentials that the ESP chip needs to connect to the Wifi.

The first part of the communication on the ESP8266 chip is done via Async comms listening out on a port.

Once the Wifi credentials are passed, they are stored and a Wifi Connection is made, and then comms are carried out using MQTT through a connection to the Wifi Connection.

The B4J app connects to the ESP through the Access point, then once it has programmed the ESP, it reverts back to the Wifi - but it needs an IP address.

Hmmm... where am I going with this?

I am trying to do the B4J app in B4A now.

Question 1)

Why is it that I can immediately set up MQTT communications in B4A without specifying any socket or connection? It obviously is working through the current wifi connection, but how?

Question 2)

If I connect to the ESP from the B4A app, how do I then switch back to the Wifi network that the B4A app was connected to in the first place? How do I get the IP address of the Wifi network?

Bit confused in how to switch between the Access Point and whatever network the device was connected to BEFORE I switched to the AP....

I hope this makes some sort of sense...

JMB
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is no conceptual difference between the B4A and B4J implementations.

Why is it that I can immediately set up MQTT communications in B4A without specifying any socket or connection? It obviously is working through the current wifi connection, but how?
The OS manages the network connection for you. This is always the case in Android, OS and the desktop platforms. The ServerURI parameter includes the ip address or host and the port number.

If I connect to the ESP from the B4A app, how do I then switch back to the Wifi network that the B4A app was connected to in the first place? How do I get the IP address of the Wifi network?
This is not so simple. There are various wifi libraries that allow you to connect to specific networks.
The problem is that Android might prefer the cellular network over the wifi network because the wifi network is not connected to the internet.

See this post for a solution: https://www.b4x.com/android/forum/threads/mqtt-chat-network-error.90892/#post-574610
 
Upvote 0

JMB

Active Member
Licensed User
Longtime User
Thanks Erel.

I am looking at the MLWifi library to see if that can help me out.

JMB
 
Upvote 0
Top