AndroidTV ADB - bash script does not work

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
User avatar
Wolly76
Posts: 24
Joined: Sunday 21 March 2021 8:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands / Utrecht region
Contact:

AndroidTV ADB - bash script does not work

Post by Wolly76 »

Dear all,
I'm trying to implement a connectivity to my AndroidTV using ADB.

When executing the proper calls in the command line it all works:

Code: Select all

adb kill-server
adb start-server
adb connect 192.168.2.7
adb shell input keyevent KEYCODE_POWER
However, if I add these lines to a shell script (according to this thread), it doesn't work properly and I got the following error message after the last line:
error: device unauthorized.
This adb server's $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.


Apparently the ADB-server isn't started. I don't get why this way is not working as it works when executing the lines manually.
Does anybody has a clue?
thanks!
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: AndroidTV ADB - bash script does not work

Post by erem »

when you run the commands manually, what user is this?
when you run the shell script, what user runs it? same?
post your script and it's properties.
Regards,

Rob
User avatar
Wolly76
Posts: 24
Joined: Sunday 21 March 2021 8:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands / Utrecht region
Contact:

Re: AndroidTV ADB - bash script does not work

Post by Wolly76 »

Thanks Rob for consideration. Effectively my shell script isn't more then the manual handled lines.

But your comment about the user is pointing me probably to the right direction.

The "manual lines" were executed as user pi, however, the shell script was executed as root (sudo) as the owner/modes were not set to user pi.
I have changed those and it appeared to work although I'll have to test a bit more thoroughly. I wasn't aware of the fact that the finger print for ADB on the Android TV was user dependent.
User avatar
Wolly76
Posts: 24
Joined: Sunday 21 March 2021 8:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands / Utrecht region
Contact:

Re: AndroidTV ADB - bash script does not work

Post by Wolly76 »

Alas, it's not solved yet :( .

so this is the shell script

Code: Select all

#!/bin/sh

echo "::: Start ADB connect script :::"
adb kill-server
adb start-server
adb connect 192.168.2.7
adb shell input keyevent KEYCODE_POWER
echo "::: End ADB connect script :::"
With owner/mode as:
4 -rw-rw-rw- 1 pi pi 261 Apr 22 10:58 testAdbStartScript.sh

which I run by : bash testAdbStartScript.sh

Thanks in advance.
User avatar
Wolly76
Posts: 24
Joined: Sunday 21 March 2021 8:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands / Utrecht region
Contact:

Re: AndroidTV ADB - bash script does not work

Post by Wolly76 »

Just playing around a bit, with some trial and error I found out the cause.

In my script I started with "adb kill-server" then continued with start-server etc...
By applying once at the start, then skipping this call resulted in a working script.

so the proper script should become:

Code: Select all

#!/bin/sh

echo "::: Start ADB connect script :::"
adb start-server
adb connect 192.168.2.7
adb shell input keyevent KEYCODE_POWER
echo "::: End ADB connect script :::"
Then I still had issues when calling this script in Domoticz but that had another cause.
I used osExecute('bash ~/testAdbStartScript.sh') but when I changed the "~" to /home/pi/ then it worked: :D

Code: Select all

osExecute('bash /home/pi/testAdbStartScript.sh') 
The learning curve is slow .... :(

Code: Select all

        
local function osExecute(cmd)
	local fileHandle     = assert(io.popen(cmd, 'r'))
	local commandOutput  = assert(fileHandle:read('*a'))
	local returnTable    = {fileHandle:close()}
	
	return commandOutput,returnTable[3] 
end
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: AndroidTV ADB - bash script does not work

Post by erem »

if you change

Code: Select all

#!/bin/sh
to

Code: Select all

#!/bin/bash
you can run the script like this

Code: Select all

osExecute('/home/pi/testAdbStartScript.sh')
you are running bash to start sh to execute the script.
you do not need sh.
Regards,

Rob
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests