ADB Wi-Fi connection disconnects when device goes to sleep in Moto G 2014 I can connect the device via USB and manage to play the app from Android studio without issues. Then I do adb tcpip 5555 and adb connect &lt;IP_ADDRESS:PORT&gt; without problems. Same goes for running the app. 

But for some reason, when the device goes to sleep (screen shuts down), so does the connection to ADB.  I configured the Wi-Fi settings to be "Always" so that shouldn't be the problem. I tried restarting the device and the PC, even re-installing the drivers but no luck.

Here's what I get from Logcat in the last seconds before the screen shuts down:    

07-28 20:23:17.924     997-1222/? I/PowerManagerService﹕ Nap time (uid 1000)...
07-28 20:23:17.924     997-1222/? I/PowerManagerService﹕ Going to sleep due to screen timeout (uid 1000)...
07-28 20:23:18.477     997-1222/? D/bsthal﹕ activate, handle: 2, enabled: 0, index 5
07-28 20:23:18.490     997-1219/? I/DisplayManagerService﹕ Display device changed: DisplayDeviceInfo{"Schermo incorporato": 720 x 1280, 60.0 fps, supportedRefreshRates [60.0], density 320, 294.967 x 295.563 dpi, appVsyncOff 0, presDeadline 17666667, touch INTERNAL, rotation 0, type BUILT_IN, state OFF, FLAG_DEFAULT_DISPLAY, FLAG_ROTATES_WITH_CONTENT, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS}
07-28 20:23:18.496      997-997/? V/ActivityManager﹕ Display changed displayId=0
07-28 20:23:18.551      317-317/? D/SurfaceFlinger﹕ Set power mode=0, type=0 flinger=0xb7459550
07-28 20:23:18.557      317-317/? D/qdhwcomposer﹕ hwc_blank: Blanking display: 0
07-28 20:23:18.796      317-804/? I/qdhwcomposer﹕ handle_blank_event: dpy:0 panel power state: 0
07-28 20:23:18.800      317-317/? I/qdhwcomposer﹕ enable_dcabc: Done setting OFF mode
07-28 20:23:18.800      317-317/? D/qdhwcomposer﹕ hwc_blank: Done blanking display: 0
07-28 20:23:18.801      317-317/? I/SFPerfTracer﹕ triggers: (rate: 26:893) (compose: 0:2) (post: 0:0) (render: 0:16) (19:9416 frames) (20:12477)
07-28 20:23:18.801      317-317/? D/SFPerfTracer﹕ layers: (5:10) (FocusedStackFrame (0xb74da368): 0:156)* (DimLayer (0xb756f868): 0:19)* (DimLayer (0xb7572170): 0:7)* (StatusBar (0xb755f198): 2:8497) (com.android.systemui.ImageWallpaper (0xb7564e30): 0:499) (com.teslacoilsw.launcher/com.teslacoilsw.launcher.NovaLauncher (0xb7592e58): 0:195) (NavigationBar (0xb7562cf0): 0:18) (ColorFade (0xb7568e60): 20:22)
07-28 20:23:18.805     997-1347/? D/SurfaceContro
device not found


And when the screen shutdowns completely, the device simply disconnects mid transmission. 

It seems I can connect to it after it had disconnected and went in IDLE. This is the log i managed to get by connecting to the device the second it disconnected:
http://pastebin.com/afqpA0Ch

EDIT: I tried creating a new user on the phone and connecting it via wi-fi to adb, and it seems the problem does not present itself with this new account. I'll try factory-resetting the device and see if I can solve the problem for good.

I have a Motorola G 2014, XT1068, with Android 5.0.2, and running Android Studio on Windows x64 Home Premium.

How do I stop the device from disconnecting from ADB?
So it seems the problem was with the settings of the device. Having a Screen Lock (even if SmartLock is enabled, and you are in a "safe location") disconnects ADB on device idle. Only way around it for me was to disable the device screen lock.