2

I'm using Android 9 on my device, there are many times when I'm away from my phone and it is charging in a different room or someone else is using it, is there was a way to send over the battery percentage say bp over to my PC at regular intervals via the internet.

There maybe apps that can do this but I'm interested more in a script or terminal based approach

Ideas I'm thinking of are:

I have Termux installed and my device is not rooted yet how do I proceed.

  • Usually your PC is not exposed to the Internet, therefore a (temporary) storage is needed online. Typical examples are storage services like Dropbox, document services like Google Sheets or messaging systems like Signal or Wire. I am sure for a lot of services termux/Linux scripts exist that allow to store data in one of these services. – Robert Jan 13 at 18:28
  • @Robert Exactly why I was thinking of a copy pasta aka a pastebin service to broadcast my battery status to for example maybe ix.io but I'm sure the people here have something even simpler. Another issue is how I'm going to get the battery percentage in terminal without rooting. – himanshuxd Jan 13 at 18:32
1

I'm using gist by Github (which can be done using gem install gist after installing ruby package) for broadcasting my battery percentage first to a private file, tried using ix.io but pkg install ix didn't work on Android terminal the config.guess threw and error saying unable to guess system type.

Already had Termux installed on my Android with necessary packages and with pkg install termux-battery-status and installing the Playstore api app : https://play.google.com/store/apps/details?id=com.termux.api&hl=en_IN using termux-battery-status | grep percentage | grep -oP '\: (.*?)\,' | grep -Eo '[0-9]{1,3}' gave the battery percentage in terminal.

Finally I added permissions using chmod +x bp.sh and set up crontab on Android to do this every minute using crontab -e and adding the line * * * * * ~/bp.sh

EDIT

Have started to make use of jq to parse json ouput, so now the one liner for script is termux-battery-status | jq .percentage | gist -f bp -u gist_id and start the crontab using crond

PS : I've put the entire thing here : https://github.com/himanshuxd/bp-broadcast

| improve this answer | |
0

You could use Your Phone Companion from Microsoft to link Android to your PC. The battery percentage would be shown at the upper left corner near device icon.

| improve this answer | |
  • 1
    It won't work when I'm using Ubuntu or Arch plus the permission list for that app is quite taxing. – himanshuxd Jan 14 at 19:05
  • 1
    You could try Find My Device which requires GPS to be active. – Abhishek Kumar Jan 14 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.