Command to Trigger Android Sleep?

I tried to search for this, but did not find what I was looking for. I am trying to avoid overly complex and failure prone methods to wake up and put my VIM3 to sleep. I think I see a method to wake it by USB, but not put it to sleep. However, I have an Arduino that is already “watching” the ignition switch state in the car. If I were to pass the switch state to RD, could it trigger a command to put the tablet to sleep via software? I think I can wake it with some USB activity (not yet proven).

This is done! Just exit the RD application by tracking the ignition key commands, after which the android will go from the desktop to sleep at the minimum timeout (android screen settings, go to sleep after …)

Awakening is also implemented. In recent updates! Read the recent announcements!

I wouldn’t rely heavily on these methods. the point is that VIM3 can wake up. I have 10 different Khadases … and VIM3 and VIM3L … VIM3 sleeps better than VIM3L … VIM3L has huge problems with real deep sleep. by button Power it is not there.
therefore, in my project, I manage and control the sleep of VIM3 through arduino.
a script is launched on vim3, which monitors the voltage on Pin37 GPIO in an eternal loop. if there is no tension, then the script forces the VIM into deep sleep. Voltage 3.3V I get from PWM-pin arduino.
For wakeup I use Power button linked with any D-pin arduino.

USB control of sleep/wakeup on Khadas is very, very, very unreliable. you can come to your car on Monday morning and find it with a dead battery.

Would it be possible for you to share your script and setup? This is all that is holding me back from deploying the RD into my car.



#!/system/bin/sh
echo 'Start Power Service...'
echo 431 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio431/direction
while true
do
    pwrctrl=$( cat /sys/class/gpio/gpio431/value )
	if [ "$pwrctrl" = 0 ]; then		
		echo 'mem' > /sys/power/state
		echo ' Set sleep...'
		
	fi
	sleep 1
done

I see the while loop there. Does it wake back up when GPIO Pin 37 goes high again?

Secondly, how are you loading and running the script? ie, Where are you putting it? Do you have it set to load automatically when the VIM3 boots? Sorry to ask so many questions. This problem has been plaguing me for a while. Thanks!

this script only guarantees deep sleep.
1 - run vim3
0 - sleep vim3.

loading code into a file “userinit”.
is described in detail in the khadas site. Launch a script at boot - #5 by Terry - Android - Khadas Community

Thank you so much for your help! Deep sleep is what we need. Are you using this same pin to wake it back up, or do you toggle the power button?

unfortunately this only works for sleep. awakening is necessary only through the button.

OK, sounds good. Are you using an Arduino or other controller to read back the power state of the VIM3? On the Khadas forums, I asked a very similar question. Someone there responded that they are reading the voltage level of the I2C ports, to see when the VIM3 was awake or asleep.

I tried reading the levels on all pins but couldn’t find a reliable source. I do not read the VIM state in any way. I just control it, and the script ensures that it sleeps deeply.

1 wire - for read VIM status (ex PIN 25 - I2C)
2 wire - for control of Sleep mode ( PIN37 )
3 wire - for control PWR BTN

for read VIM status you can send from RealDash counter 1 time per sec. If counter nor recieved, then VIM not work.

Sorry to be so daft, but I am really out of my depth. How exactly do I install your script? I have no experience doing this at all. Thanks!

  1. adb root

  2. adb shell

  3. mount -o rw,remount /

  4. vi /system/bin/preinstall.sh

  5. i

  6. busybox run-parts /system/etc/init.d/ // add this string see https://forum.khadas.com/t/launch-a-script-at-boot/600/5

  7. Esc

  8. Shift-Z, Shift-Z

  9. vi /system/etc/init.d/userinit

  10.                                                            // copy script
    
  11. Shift-Z, Shift-Z

  12. chmod 777 /system/etc/init.d/userinit

  13. reboot

Hi Max, after point #6 above can’t complete the steps and get stuck, can you please explain more easy for us :joy: