Android Question How To get the IP adress of a connected device to the hotspot

Amateurtje

Member
Licensed User
Longtime User
Hello All,

to solve a problem that a B4A app can not make a connection with a ESP8266 device in AP mode through a Wifi and at the same time, post this data to the internet throuugh the mobile connection, I had the idea to connect the ESP8266 to the hotspot and hopefully, the app can in this way connect to the ESP8266 and the internet......

To connect to the ESP8266, I need to know it's IP adress.. Not the IP address of the hotspot, (192.168.43.1) but of the ESP8266... I do not have to make a hotspot from the app or anything, just know the IP adress... I can not find any app in the store to do this, so the only solution is to try to detect it myself.....

Anybod any idea??
 

Amateurtje

Member
Licensed User
Longtime User
Putting the phone as hotspot resolves my problem... For now, I have to use another device which I put in the same hotspot network and do an IP portscan... With this, I could get the desired IP address of the ESP8266... IT was actually 192.168.43.51....

Can I build a kind of portscan ping command??

PS, the, looking at the portscan, the telephone itself did not have 192.168.43.1 but a different IP... It is not relevant for my problem, but...
 
Upvote 0

pliroforikos

Active Member
Licensed User
You can set your router to give a static IP to your ESP8266 based in ESP's MAC Address

1626882149126.png
 
Upvote 0

Amateurtje

Member
Licensed User
Longtime User
Dear Pliroforikos,

The router is the hotspot on the phone... This is Normally a dhcp server and as far as i can see, there is no app where I can set the IP fixed or based on the MAC addresses. Like stated, a wroking app which shows the IP addresses on the hotspot device does not even exists.. Many apps say they do but I did not find a working one yet....

Scanning IP ports from a third device on the (hotspot) network, that seems to works but is a bit overdone... Therefore my question....
 
Upvote 0

Amateurtje

Member
Licensed User
Longtime User
Have you tried Network Analyzer? I have just scanned my network with mobile phone as hotspot.

View attachment 116786
Hi Pliroforikos,

This app indeed works and shows the clients on my hotspot... In this case, I do not need to scan them in my app...For now...
At this moment I am going to test myself wit hthe system but in the future, other people will have to use this app.. I think, all this is way to difficult to let people define their phone as hotspot, scan the ports and declare this ip in the app..... I need to find a better way for this system and I do not know if I can do this...

I have to review the complete system and see if Android is the way to go.
 
Upvote 0

pliroforikos

Active Member
Licensed User
Hi Pliroforikos,

This app indeed works and shows the clients on my hotspot... In this case, I do not need to scan them in my app...For now...
At this moment I am going to test myself wit hthe system but in the future, other people will have to use this app.. I think, all this is way to difficult to let people define their phone as hotspot, scan the ports and declare this ip in the app..... I need to find a better way for this system and I do not know if I can do this...

I have to review the complete system and see if Android is the way to go.
As is said before mqtt server is worth to use it.
Let me explain how i use it.
I have an NodeMCU which is checking oil limit (for heating purpose), temperature, humidity and fire sensor also. It checks every 30secs and send to mqtt server the data. I think i saw a mqtt library here in b4x.
Mosquito mqtt Server runs on rock64 board (almost like raspberry pi 4 but u can use rpi3 also.) with debian 24/7.
Other solution naisbto install mqtt server on web or use some readymade servers.
From mobile phone i check mqtt server.

Screenshot_2021-07-21-23-39-55-120_b4a.example.jpg

labels are in Greek but it should show the above values from sensors.
All connected to home wifi and i can open ports to router using dyndns for example to use it from everywhere i want.
Good luck
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
to solve a problem that a B4A app can not make a connection with a ESP8266 device in AP mode through a Wifi and at the same time, post this data to the internet throuugh the mobile connection, I had the idea to connect the ESP8266 to the hotspot and hopefully, the app can in this way connect to the ESP8266 and the internet......
This is an Android limitation.

I would have run a MQTT broker on the Android device and configure the ESP8266 to connect to the broker.
 
Upvote 0

Amateurtje

Member
Licensed User
Longtime User
I am looking at the MQTT but what benefit does it bring me?

the setup I use:

PIC-based device generates information (time) and sends it via the ESP8266 to the android device... This is local but just annoying to do with a cable.
The android device (android chosen while everybody has that and has normally a mobile data and wifi connection) adds information that the pic device can not measure..(not yet)....

This data has to go to a central internet database.


From esp8266 to android I use the serial connection and from android to internet the data connection.

how would i benefit from using mqtt? it does not delete devices or anything.

Another idea was to not use ESP8266 but a GSM coonection from the PIC-based device and do everything in the cloud.... This means that a GSM card needs to be bought and maintained for every PIC-device..... and a telephone with that, every user already have....
 
Upvote 0

Amateurtje

Member
Licensed User
Longtime User
This is an Android limitation.

I would have run a MQTT broker on the Android device and configure the ESP8266 to connect to the broker.

does using MQTT solve my problem with the connection?

- Do I not have to configure the telephone as hotspot?
- can i download from the device, add data and upload to the cloud without difficulty?
- does the device not need it's own GSM connection?

Solutions i have seen for that are LORA etc but the coverage is quet bad from that...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Amateurtje

Member
Licensed User
Longtime User
not having to scan or know the ip port is a benefit. on the other side, if I could scan them automitcally (there will be only 1 user connected) and using that ip address, this could be overcome..

regsrding your last answer, MQTT needs a carrier.. That means a data connection of somesort: Mobile data, wifi,...

Maybe GSM was not the correct term, but I meant a data connection... I thought that was understandable. sorry.. Looking at the answer for the hotspot, I get the answer on the last question. Sorry, english is not my native tongue so sometimes you try to find the easiest terms.

I saw a forum item about setting up a hotspot.. Maybe if I integrate that bit, I can make that easier for the user... some of the users will be older people with not a lot of knowledge of mobile phones.....
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I think that you misunderstood me.

1. You need to turn the Android device to a hotspot.
2. You cannot do it programmatically as it will result in a random SSID and password and it will be difficult to pass it to the ESP8266.
3. Once the ESP is connected to the Android network there are two options:
a. Make the ESP connect to the Android with Socket <-> ServerSocket.
b. Run MQTT broker on the Android and connect the Android and ESP to the broker.
 
Upvote 0

Amateurtje

Member
Licensed User
Longtime User
yes, clear summary..

2nd item I did not know.. And you are right, setting it in the ESP (actually, in the pic-device, the ESP gets it from the pic-device..) is a disaster..

thanks for the input, lots of things to think about....

3rd solution(I was playing with in my mind) (disadvantages are clear and selfexplainatory)
- placing a local gsm/wifi router in the field m aybe even same housing as the pic device, and connect both devices......
 
Upvote 0

Amateurtje

Member
Licensed User
Longtime User
ow, i thought you knew..sorry, that works..
with the telephone as hotspot, the complete setup work.. the app can enter the internet and post data and can get data from the esp in the wifi.
 
Upvote 0

DavideV

Active Member
Licensed User
Longtime User
Hi, not sure if it will work on the phone hotspot, but at home i can discover in few seconds all my esp based devices' IP address using UDP broadcasting. I wrote some b4A apps for my own to communicate with the heating system and even my digital clock, discovering them with broadcsting, just in case the router changes their IP casually (I don't like to use fixed IP that needs to change router settings).

Hope this help
Davide
 
Upvote 0

Amateurtje

Member
Licensed User
Longtime User
@ DavideV,

mmm, i would be very interested in how you did that...

Did you also change something in the ESP program (to broadcast that UDP?)?
 
Upvote 0

DavideV

Active Member
Licensed User
Longtime User
@ DavideV,

mmm, i would be very interested in how you did that...

Did you also change something in the ESP program (to broadcast that UDP?)?
Yes, the ESP has a short routine to answer to the app. It sends a json containing its IP and some other info about it (i.e. the device name, so it's easy to know what it does). The app lists all devices found and I can choose from the list the one I want to connect to.

A simple example of UDP broadcasting is somewhere in this forum, I started with it.
The UDP example for the ESP is built-in in the arduino ide.

Sorry today I'm in a hurry...
 
Upvote 0
Top