Genymobile / Genymobile/scrcpy

Automagically connect scrcpy wirelessly on windows

Open
#3,003 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
150k
Forks
13.7k
Avg merge
4d 13h
Merged PRs (30d)
2

Description

- [X] I have read the [FAQ](https://github.com/Genymobile/scrcpy/blob/master/FAQ.md).
- [X] I have searched in existing [issues](https://github.com/Genymobile/scrcpy/issues).

**Environment**
- OS: Windows
- scrcpy version: 1.12.1+
- installation method: amy
- device model: any
- Android version: any

**Describe the bug**
Not a bug, but a possible solution for using scrcpy wirelessly
Getting scrcpy connect to android phone wirelessly it's not too easy. With the below windows script after attaching your phone with usb for one time everything works until you restart you're phone.

My primary use case is: Enable tethering on phone, attach pc to this wifi, connect phone via USB to PC, run script. After this is done, running script should connect via wifi without USB connection.

(script it's not really readable, let me know if you have problems using it.)
`echo off
set %ADBPath=
rem set ADBPath=C:\Programs\scrcpy1.21\
rem echo %cd%

setlocal EnableDelayedExpansion
setlocal EnableExtensions

rem to clear local variable and registry use following instructions from command prompt
rem set AndroidIPLocal=
rem reg add "HKCU\Volatile Environment" /v "AndroidIP"

echo This script will try to connect your phone with this computer via Scrcpy over wifi! Modify ADBPath to match adb and scrcpy directory (they must be on same dir)
%ADBPath%adb version

rem echo argument %1
echo reading saved phone ip from registry...
for /f "tokens=3" %%i in ('reg query "HKCU\Volatile Environment" /v "AndroidIP" ') do (set AndroidIPLocal=%%i)
rem goto EndOfBatch
rem echo Check if android ip is set
if NOT DEFINED AndroidIPLocal goto CheckPhoneConnected
echo Current saved phone ip %AndroidIPLocal%
echo restarting server
%ADBPath%adb kill-server
echo enabling tcpip mode
%ADBPath%adb tcpip 5555

echo Trying to connect to %AndroidIPLocal% wait...
%ADBPath%adb connect %AndroidIPLocal% | find /i "connected to"

rem echo %ERRORLEVEL%
goto DoConnectionOk%ERRORLEVEL%
:DoConnectionOk0
%ADBPath%scrcpy --serial %AndroidIPLocal%
echo Scrcpy ended correctly
goto EndOfBatch
:DoConnectionOk1
echo Connection failed... Verifying correct phone's ip
%ADBPath%adb usb
echo attach phone via USB and confirm connection on phone
pause
rem %ADBPath%adb devices
goto CheckPhoneConnected
:do0
echo searching ip on wlan0
FOR /F "tokens=2" %%a in ('%ADBPath%adb -d shell ip addr show wlan0 ^| FIND "inet "') DO (FOR /F "tokens=1 delims=/" %%b in ('echo %%a') DO (set AndroidIPLocal=%%b:5555) )
goto doWlan0%ERRORLEVEL%
:doWlan00
echo searching ip on wlan1
echo wlan0 not found -> searching on wlan1
%ADBPath%adb shell ip addr show wlan1
echo searching....
FOR /F "tokens=2" %%a in ('%ADBPath%adb shell ip addr show wlan1 ^| FIND "inet "') DO (FOR /F "tokens=1 delims=/" %%b in ('echo %%a') DO (set AndroidIPLocal=%%b:5555) )
goto doWlan1%ERRORLEVEL%
:doWlan10
reg add "HKCU\Volatile Environment" /v "AndroidIP" /d "%AndroidIPLocal%" /f
echo trying to enable tcpip.
%ADBPath%adb tcpip 5555
pause Confirm on phone
:connectViaWifi
%ADBPath%adb connect %AndroidIPLocal%
goto connectViaWifi%ERRORLEVEL%
:connectViaWifi0
echo connectViaWifi to %AndroidIPLocal%
%ADBPath%scrcpy --serial %AndroidIPLocal%
echo Scrcpy ended correctly

goto EndOfBatch
:connectViaWifi1
echo Unable to communicate with device. Is computer on same wifi or connected to phone tethering network?
goto EndOfBatch

:doWlan11
echo no ip found on wlan1. Ensure that phone and computer are connected to the same wifi (also ok if computer is attached to phone wifi tethering )
pause
goto EndOfBatch

:doWlan01
:do1
Echo No device found. Connect phone via USB and run script again
goto EndOfBatch
:CheckPhoneConnected
echo check if android is connected via USB
%ADBPath%adb devices
for /f "tokens=2 skip=1" %%i in ('%ADBPath%adb devices ^| find "device"') do (goto PhoneConnected)
goto do1
:PhoneConnected
echo check if it's connected
for /f "tokens=1" %%i in ('%ADBPath%adb devices ^| find "."') do (goto SetIpAndConnectWifi)
echo not connected via wifi
goto do0
:SetIpAndConnectWifi
for /f "tokens=1" %%i in ('%ADBPath%adb devices ^| find "."') do (set AndroidIPLocal=%%i)
goto connectViaWifi

:EndOfBatch`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with FAQ.md and the supplied Windows batch script, which uses adb and scrcpy to discover the device and connect over Wi‑Fi. The issue names no repository file or test; done would be a clearly supported Windows workflow that automates the described wireless connection after USB setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, shell
Domain
cli, mobile-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.