See forum post Any way to view Android screen remotely without root? - Post #9.
- Connect the device via USB and make sure debugging is working;
adb tcpip 5555
. This makes the device to start listening for connections on port 5555;
- Look up the device IP address with
adb shell netcfg
or adb shell ifconfig
with 6.0 and higher;
- You can disconnect the USB now;
adb connect <DEVICE_IP_ADDRESS>:5555
. This connects to the server we set up on the device on step 2;
- Now you have a device over the network with which you can debug as usual.
To switch the server back to the USB mode, run adb usb
, which will put the server on your phone back to the USB mode. If you have more than one device, you can specify the device with the -s
option: adb -s <DEVICE_IP_ADDRESS>:5555 usb
.
No root required!
To find the IP address of the device: run adb shell
and then netcfg
. You'll see it there.
To find the IP address while using OSX run the command adb shell ip route
.
WARNING: leaving the option enabled is dangerous, anyone in your network can connect to your device in debug, even if you are in data network. Do it only when connected to a trusted Wi-Fi and remember to disconnect it when done!
@Sergei suggested that line 2 should be modified, commenting: "-d option needed to connect to the USB device when the other connection persists (for example, emulator connected or other Wi-Fi device)".
This information may prove valuable to future readers, but I rolled-back to the original version that had received 178 upvotes.
On some device you can do the same thing even if you do not have an USB cable:
- Enable ADB over network in developer setting
It should show the IP address
adb connect <DEVICE_IP_ADDRESS>:5555
- Disable the setting when done
Using Android Studio there is a plugin allowing you to connect USB Debugging without the need of using any ADB command from a terminal.
(Updated)
Within Lua code, there is no security on physical access. In addition to other answers: ESP have an option to save wifi settings. Thus this will allow you not putting credentials into a lua file. Program the credentials once and then remove credential code. This will make it a little bit harder to get the credentials. At least one who reads the code will not see it. (but of course not a total security option because of this.)
Every time esp reboots or wifi network is in range, it will connect to the same ssid and network. This is on by default.
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID", "password")
wifi.sta.connect()
Another way to do that is mac address registiration. If your AP allows you to register mac addresses of stations then it will provide one more layer of security since getting password will not be sufficient to connect the wifi network. This is not securing your password! You need to configure your AP to do that.
One more method:
This will require more code. I cannot say it is more secure but it will make it harder to discover. You should compile your lua files to use this. Simply XOR your password with ssid and put the xor'ed version in your code. Survey the networks and create password for each network. Try to connect everyone with the produced pass. The matching pair will connect successfully. The others will fail. This will make connection sequence a little bit longer.
--encode
--retuns a table containing bytes
--also prints what should be in code
-- s is ssid, p is password
function encode(s,p)
key = s..s --encoding key, must be longer than password
enc = {} --new table
uart.write(0,"Key output: {")
for i=1,string.len(p) do
c = bit.bxor(p:byte(i),key:byte(i))
table.insert(enc,c)
if i == string.len(p) then
uart.write(0,c.."}")
else
uart.write(0,c..",")
end
end
return enc
end
--decode
--tries to decode password with table enc
--s is ssid (got from survey) encval is byte table
function decode(s,encval)
key=s..s
pass=""
for ii,i in ipairs(encval) do
c = bit.bxor( key:byte(ii),i)
pass = pass..string.char(c)
end
print("password: "..pass)
return pass
end
-- lets say ssid="network" and password="psswrd12"
encodedpass = encode("network","psswrd12")
-- this will print: Key output: {30,22,7,0,29,22,90,92}
-- this will be included in code
-- and to decode
print(decode("network",encodedpass))
-- will print: password: psswrd12
Best Answer
Lua is interpreted and so programs written in it will not get the maximum performance possible from the ESP8266. It is now possible to program the ESP8266 form the Arduino IDE using it's version of C. This is compiled and likely to be far faster.
I found LUA apps unreliable. I've written a few programs using the Arduino IDE and they are rock solid, so I recommend that path. (https://www.youtube.com/watch?v=hu-g-XTCEpU) I've also seen a video of someone streaming audio using an ESP8266 but they added extra hardware for buffering. Sorry I don't have that link.