This page describes commands to connecting and viewing the screen of Android device.
Device connection
Enable ADB over TCP/IP (plug your device):
adb tcpip 5555
Adb allows you to connect a device by ip address.
adb connect IP:5555
IP is ip address of your Android device.
You can find IP address of your device in your phone’s network settings. Alternatively, you can plug the device to a PC and run the second command:
adb shell ip route
10.89.75.208/28 dev rmnet_data2 proto kernel scope link src 10.89.75.215
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.150
For example, device IP address is 192.168.1.150 (the second line of outputs). To get the address we can use follow command:
adb shell ip route | awk 'NR==2{print $9};'
192.168.1.150
Command for defining and connecting a device:
adb kill-server && adb tcpip 5555 && sleep 5 && adb shell ip route | awk 'NR==2{print $9};' | xargs adb connect
So, you can use your remote device to develop an android application.
Remote control
Application scrcpy provides display and control of Android devices.
scrcpy --bit-rate 2M --max-size 800
These commands are very useful if you need to develop and debug a remote embedded device application without physical access.