HDMI for Channels

Is there a silent way to send a key event to Android TV via ADB to keep the session alive after 4 hours? I've run into this when recording the US Open today. Doesn't matter if you have sleep set to never, the Onn box will go down if you don't press a key.

I'm sure I can send the d-pad center but was wondering if there's a silent way to do this that doesn't appear onscreen.

I am sending a brightness down and up which works on Amazon devices but the wecool device would show the brightness indicator going down and up whereas Amazon silently does not show this.

		adb -s 10.0.250.154 shell input keyevent 224
		adb -s 10.0.250.154 shell input keyevent 221

Seems to work OK I tested a 5 hour recording a few days ago. I seem to lately get bitten with are you there within 3 minutes of starting which my keep alive script also handles.

I'm betting that there's some box setting you can do to disable the power down but maybe I'm wrong.

2 Likes

Let us know if you find one and I'll do the same.

I’m definitely not a programmer, I’ll need to clean these up, they reference the file locations I chose, they are not complete instructions, but here are the steps I’ve gone through on an M1 Mac Mini.

After step 14, I’ve been slowly working on the go file and bmitune files, and only just got success in bringing up a YouTubeTV channel and then switching between two of them this afternoon right before it was time to pick up the kids.

I’m happy to move/remove these if they belong elsewhere or aren’t helpful.

Step 1: Install Homebrew from a new Terminal window:
	/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 2: Install Android Platform Tools:
	brew install --cask android-platform-tools

Step 3: Install golang:
	brew install golang

Step 4: Download the AndroidHDMI-for-Channels from GitHub:
	https://github.com/tmm1/androidhdmi-for-channels

Step 5: Put that folder where you want it and then navigate to it:
	cd /Users/hammer32/Dropbox/androidhdmi-for-channels

Step 6: Build the Helper Application there:
	go build

Step 7: Turning on ADB Debugging on the Android TV device.  Connect the device to the Mac using USB.  Navigate to the ADB platform tools folder location:
	cd /Users/hammer32/Dropbox/Home\ Automation/ChannelsDVR\ ADB\ Mac\ OS/platform-tools

Step 8: Run this command turn turn on USB Debugging Mode:
	./adb devices

	Which results in the following:

	* daemon not running; starting now at tcp:5037
	* daemon started successfully
	List of devices attached
	GUSA2310007499	unauthorized

 Step 9: Select always allow from this computer and Allow on the Android TV, then re-run the same command to verify:
	./adb devices

	Which should result in:
	List of devices attached
	GUSA2310007499	device

Step 10: Next turn on wifi ADB mode:
	adb tcpip 5555

	Which should result in:
	restarting in TCP mode port: 5555

Step 11:
	adb connect [your Android device's IP address]
	adb connect 192.168.1.204

	Which should result in:
	connected to 192.168.1.204:5555

Step 12: Test the device:
	./adb devices

	Which results in:
	List of devices attached
	GUSA2310007499	device
	192.168.1.204:5555	device

Step 13: Navigate to the AdroidHDMI-for-Channels folder:
	cd /Users/hammer32/Dropbox/androidhdmi-for-channels

Step 14: Launch the AdroidHDMI-for-Channels app:
	./androidhdmi-for-channels

4 Likes

I am not sure if you read my post correctly... It isn't a script for TVE Its a script that allows all of youtube tv and it does not have a limit or restriction to 4 streams.

2 Likes

Sounds interesting, but also a little shady. Where is that script from? And why do you no longer have access to it?

I ended up sending a simple KEYCODE_DPAD_CENTER every hour w/Task Scheduler, it doesn't put anything onscreen in the NBC app. Using brightness events with the ONN box puts the brightness OSD bar up top and it doesn't go away.

If the box is asleep the adb command times out silently after a few seconds, box doesn't wakeup.

I ended up sending a simple KEYCODE_DPAD_CENTER every hour w/Task Scheduler, it doesn't put anything onscreen in the NBC app. Using brightness events with the ONN box puts the brightness OSD bar up top and it doesn't go away.

I'll give this a try in my script as well. Thanks for sharing!
EDIT: it pauses in my case. Back to brightness for me.

1 Like

Well I finally got my 3 encoder system up and running. It seems to be working but I have not gotten into it enough to find the long record issues others are getttng ("are you still here"). My config is running on an Mac M2, a 4 channels encoder (encoder), two MECOOL Android TV boxes (MECOOL) and a Chromecast dongle (CC). Many thanks to the smart people on this thread!

After pulling together many examples/suggestions from others, I am using this code for this 3-channel system. I tried to eliminate any unnecessary items in the scripts. Maybe it will help someone.

The encoder ip is 192.168.0.168 and the video feeds for ports 1,2 and 3 are:

http://192.168.0.168/0.ts
http://192.168.0.168/4.ts
http://192.168.0.168/8.ts

The three Android dongles are at 192.168.0.27, 192.168.0.29 and 192.168.0.118.
I renamed the prebmitune.sh, bmitune.sh and stopbmitune.sh to append the fourth octet of the ip address to make it clear which dongles use which shell files.
For example the first MECOOL dongle (192.168.0.27) uses these scripts:

prebmitune-27.sh
bmitune-27.sh
stopbmitune-27.sh

Similar sets of scripts exist for the other two dongles (x.29 & x.118) for the second and third tuner.

From the main.go file, here are the tuner declarations:

var (
	tunerLock sync.Mutex

	tuners = []tuner{
	
		{
			url:   "http://192.168.0.168/0.ts",
			pre:   "/Users/chrisyoungers/GoLang/androidhdmi-for-channels-main/prebmitune-27.sh",
			start: "/Users/chrisyoungers/GoLang/androidhdmi-for-channels-main/bmitune-27.sh",
			stop:  "/Users/chrisyoungers/GoLang/androidhdmi-for-channels-main/stopbmitune-27.sh",
		},
				{
			url:   "http://192.168.0.168/4.ts",
			pre:   "/Users/chrisyoungers/GoLang/androidhdmi-for-channels-main/prebmitune-29.sh",
			start: "/Users/chrisyoungers/GoLang/androidhdmi-for-channels-main/bmitune-29.sh",
			stop:  "/Users/chrisyoungers/GoLang/androidhdmi-for-channels-main/stopbmitune-29.sh",
		},
				{
			url:   "http://192.168.0.168/8.ts",
			pre:   "/Users/chrisyoungers/GoLang/androidhdmi-for-channels-main/prebmitune-118.sh",
			start: "/Users/chrisyoungers/GoLang/androidhdmi-for-channels-main/bmitune-118.sh",
			stop:  "/Users/chrisyoungers/GoLang/androidhdmi-for-channels-main/stopbmitune-118.sh",
		},

	}
)

prebmitune-27.sh

#!/bin/bash
IPADD="192.168.0.27:5555"
CONNECT="connect 192.168.0.27"
IS_ASLEEP=`adb -s 192.168.0.27:5555 shell dumpsys display | grep mScreenState=OFF`
WAKE="input keyevent KEYCODE_WAKEUP"
HOME="input keyevent KEYCODE_HOME"
adb $CONNECT

# YouTube TV sometimes fails to load video if the app is already open when waking up from sleep.
if [ $IS_ASLEEP ];
then
adb -s $IPADD shell $WAKE; sleep 2
fi

adb -s $IPADD shell $HOME; sleep 2

bmitune-27.sh

#!/bin/bash
IPADD="192.168.0.27:5555"

#NBC
if [ $1 = "nbc" ]; then CODE="9iwfkw-dMAw"; fi

#MSNBC
if [ $1 = "msnbc" ]; then CODE="q6bWEVqhP8o"; fi

#E!
if [ $1 = "e!" ]; then CODE="ILTrUfLFrHI"; fi

#Bravo
if [ $1 = "bravo" ]; then CODE="xNk2Sv4t4Tc"; fi

#Oxygen
if [ $1 = "oxygen" ]; then CODE="v4upAc0UExk"; fi

#USA
if [ $1 = "usa" ]; then CODE="DJ7m0fdLKEY"; fi

#SYFY
if [ $1 = "syfy" ]; then CODE="2_WogcoZ1cY"; fi

#CNBC
if [ $1 = "cnbc" ]; then CODE="GIBoX-XF5i0"; fi

#Golf
if [ $1 = "golf" ]; then CODE="XK34g7QRvGk"; fi

#NFL Network
if [ $1 = "nfl" ]; then CODE="_pYg9qMKKIA"; fi

#NFL Network
if [ $1 = "newsnation" ]; then CODE="ZIzM3eNrylg"; fi

#MTV Classic
if [ $1 = "mtvclassic" ]; then CODE="isxl2N52bUQ"; fi

#BBC News
if [ $1 = "bbcnews" ]; then CODE="g5BmB1qXulc"; fi

#Smithsonian Channel
if [ $1 = "smithsonian" ]; then CODE="c05ACdzJxiE"; fi

#Send the command
adb -s $IPADD shell am start -a android.intent.action.VIEW -d https://tv.youtube.com/watch/$CODE -n com.google.android.youtube.tvunplugged/com.google.android.apps.youtube.tvunplugged.activity.MainActivity

stopbmitune.sh

#!/bin/bash
IPADD="192.168.0.27:5555"

adb -s $IPADD shell input keyevent  86

4 Likes

It would be really cool if the androidhdmi-for-channels program would allow you to specify an IP address for each pre, start and stop scripts that would get passed in at execution. That way you would just have 3 scripts to maintain. In the 3 channel system like I have, the prebmitune.sh, bmitunbe.sh and stopbmitune.sh scripts are identical for each channel except for the dongle IP address.

1 Like

Maybe just one script that takes a start/stop argument also?

Pre/start/stop would be great!

Did you end up getting your Fire Cube working with the same scripts that worked with your other devices?

Yep, was literally drop in replacement with exception of changing out the IP addresses. Working great!

Awesome, thanks! Are you still getting the 5-6 second load times? And is that with YouTube TV, or did I see that you were using Hulu? I’m just trying to guage how much faster load times I could expect. YouTube TV is 13 seconds for me with the Onn 4k Streaming Box (2023 model)a

Dumb question time:

Why is the adb "-n" option everyone is using on the adb shell command. I am finding it generates and error and is not in the current docs. At least in my testing I am finding it unnecessary and leaving it off works fine on fire sticks.

Yeah, still getting around 6-8 second times consistently.

Do you mean -s ? If so this specifies the Android device to send command to. It's needed when you have more than one tuner and have connections to multiple devices.

Are you are talking about this -n in this command? I have no idea what it does as I'm not smart about the adb command syntax, I'm just copying what others have done. It works for me.

#Send the command
adb -s $IPADD shell am start -a android.intent.action.VIEW -d https://tv.youtube.com/watch/$CODE -n com.google.android.youtube.tvunplugged/com.google.android.apps.youtube.tvunplugged.activity.MainActivity