Sending AT commands from Powershell script to Android phone via adb - android

I have a little script that I run in adb shell of Android phone (/system/etc directory), which enables to communicate with the modem by sending/receiving a single AT command.
The script itself, if run in adb shell, works OK. That's what it looks like:
cat /dev/pts/7 &
echo -e $1\\r > /dev/pts/7
Here's the output in adb shell:
# ./sendATCommand "at+cops?"
./sendATCommand "at+cops?"
#
+COPS: 0,0,"AT&T",6
OK
/dev/pts/7: invalid length
(need to press ENTER to return control to adb shell)
#
Now I want to invoke this script from a powershell script running on my PC, thus eventually controlling modem via AT commands, but nothing happens.
For example, the below powershell script will send the command at+cops? to check the operator to which mobile is registered to:
$adb = [IO.Path]::Combine([IO.Path]::Combine($Env:ANDROID, "platform-tools"), "adb.exe")
& $adb remount
$atCommand = "at+cops?"
& $adb shell /system/etc/sendATCommand $atCommand
The output may looks sometimes like +ATCMD (any residual [proprietary]AT command sitting in device buffer after bootup), or at+cops?(echo), or nothing at all, but
never +COPS: 0,0,"AT&T",6 which I expect. Could you help me figure out what's going on and how to possibly fix it? Ideally
I want to be able to execute at command, return control to powershell, and have output available for further processing.
I am also open to other solutions to implement same thing.
Would greatly appreciate your help. Thanks!

Not sure to answer your question, my phone is not an Android, but when I connect it via buetooth or USB to my computer a COM port is created. So I build an assembly tool on the top of .NET SerialPort class that allow, for example, to send SMS using the phone Modem.
I think it's usable in your case.

Related

shell command to create files

I want to create files with different sizes on an Android device.
The one approach I have already tried was to create dummy files using fsutil and push it to devices.
Is there any way to achieve similar result with a command inside adb shell?
Yes, you can do it using dd command. I am not pretty sure it's available in your device. It works fine in my device, you can give a try.
In your host which connects with your Android device, with adb debug turn on, using the following command to create dummy file.
adb shell 'dd if=/dev/zero of=/data/local/tmp/test.img bs=4k count=800'
# check the result
adb shell ls -l /data/local/tmp/test.img
-rw------- shell shell 3276800 2017-06-21 17:33 test.img
The command above will get data from /dev/zero and output to /data/local/tmp/test.img (a public writable directory for Android device), adjust bs and count value in your situation.

Device recognized in ADB but not in shell

When I use ADB, my phone is recognized. However, once I enter the shell, the phone mysteriously disappears. This is weird especially because the shell lists "root#nozomi", as "nozomi" is the phone's code name.
And because it is not recognized, I can't, for example, push files:
The adb command is available both on your phone and your host/development machine. However, it is not much useful on your phone from the shell.
adb shell opens a unix command shell on your phone. Commands you enter here are executed on your phone.
When you execute adb devices in the adb shell, you ask your phone if it has any other phones connected to it via the android debugging interface. And clearly your phone tells you, that this is not the case.
Same thing holds for adb push you are asking your phone to push a file to another phone via adb. Since none are connected, you get the error message.
Try exiting the adb shell again and execute commands on the host machine instead.

Execute a script using adb that disables the adb connection

I'm creating my own custom backup program that works through ADB in recovery mode. I've got a Nexus 4 using TeamWin Recovery Project (TWRP). My backup program uses reverse tethering and it's working great; however, it's a manual process to get the phone initially configured correctly, so now I'd like to automate the setup process.
First thing I did was push a quick reverse-tethering.sh startup script to the phone.
reverse-tethering.sh
#!/sbin/sh
echo 0 > /sys/devices/virtual/android_usb/android0/enable <--disables adb
... commands to enable reverse-tethering here ...
echo 1 > /sys/devices/virtual/android_usb/android0/enable <--enables adb
Here's where I'm running into problems. I'm trying to execute the reverse-tethering.sh script using the command:
adb shell /reverse-tethering.sh
My adb connection gets cut off and the remaining lines of the script are not executed after 0 is echoed to the file. :( Is there a way call a script through ADB and ensure that all of its lines get executed? I understand I will lose my ADB connection. I just want the script to continue executing even when I lose my connection.
As a side note, when I execute each line of the script individually through TWRP's command terminal, everything works fine.

Pull special files with ADB

I have a rooted Android device and I need to pull everything to pc.
First try in DDMS File explorer did not work out, it hangs and has to be force closed.
Trying again in powershell with
adb pull /
skips "special files"
is there a way to pull everything including special files?
EDIT: I have tried booting in Engineer mode and Meta mode and I have tried to copy from shell
No success
2 things:
Try booting the phone into FastBoot and then do adb pull. Some of the files might be in use while the phone is running and causing them to be skipped.
I haven't done this personally, but I would try to use adb to get to shell on the phone and copy the files that were skipped.
adb shell

Send AT Commands to Android Phone

I want to Send AT Command to Android phone.
I know SDK does not support this.
but there are two solution :
change the code of Kernel and release your new Android (it seems it is so hard!)
LoopBack on USB.(i think Bluetooth is same)
About second solution , when you connect your phone to PC with USB cable , you will see a GSM modem on Device Manager that help you to send AT Command to GSM Modem.
If we find a solution to loop back on mobile phone , we can send AT commands to GSM Modem.
Question is : HOW to loop back and what tty file on kernel will help us?
first you have to root the phone then
in adb shell
su
echo -e "AT\r" > /dev/smd0
if you want to see answer use
cat /dev/smd0
i've test this command in samsung mini,cooper,s+ and it works.
if you use htc (htc rhyme tested) try to adb shell and type this command "radiooptions 13 AT"
if you want to see answer type "logcat -b radio"
try echo to /dev/smd0 for other devices
*you can use this command in sdk java code by using Runtime.exec (require su)

Categories

Resources