I am running QtScrcpy to mirror and control multiple android devices from PC (win). In the same time running Python script which remote stepper motors (turntable). What I need is to send command adb shell input keyevent 24 to android devices via Python somehow.
You can use AndroidViewClient/culebra and create a script like this (this is a minimalistic version)
#! /usr/bin/env python3
from com.dtmilano.android.viewclient import ViewClient
ViewClient.connectToDeviceOrExit()[0].press('VOLUME_UP')
Related
I'm making an rpi based terminal in python and I want to run a powershell command on my computer. How can I send a command to a usb device
You could run socat on your Windows PC to read from serial and execute whatever you receive - if you like big security holes😉 Try adding socat tag to attract the right folk if that's an option.
Or you could run a Python script that sits in a loop reading from serial and then using subprocess.run() to execute the commands it receives.
I am running a main python program on a Windows PC that is hooked to equipment that cannot be ran on an Raspberry pi. At a certain point in the main program, I want to call/execute a Rpi program to run. I need the GPIO pins from the Rpi to turn on a relay/s. Is there a way to wirelessly(or serially) open and run the program on the raspberry pi from the main program already running on the Windows PC?
Maybe I am not thinking of something, is there an easier and just as cheap solution to turn on a relay from the Windows PC program?
Any points in the right direction would be greatly appreciated.
The easiest way to do this is with Remote GPIO which is all documented at that link. However, the gist of it is pretty simple as follows.
On the Raspberry Pi, run these steps:
sudo apt install pigpio
sudo raspi-config and enable "Remote GPIO"
sudo systemctl enable pigpiod
On the Windows PC, run these steps:
pip install gpiozero pigpio
Assuming your RaspberryPi has IP address 192.168.1.3, run PIGPIO_ADDR=192.168.1.3 python3 YourScript.py
Your script on Windows PC would then look like this:
from gpiozero import LED
from time import sleep
red = LED(17)
while True:
red.on()
sleep(1)
red.off()
sleep(1)
depending on security requirements. Assuming that the Desktop PC and raspberry pi are on the same network, you could create an HTTP REST endpoint on the pi, you could use flask or fastapi for this. then call that from the app running on the desktop. for help with flask see https://flask.palletsprojects.com/en/2.0.x/ if you are familiar with python flask is fairly simple to get started with.
Initial conditions: Raspberry Pi 3B running on latest Raspbian OS
Application: Python script recording audio through a USB Microphone and lighting up LEDS on the GPIOs ports.
Currently working: We need to wait for the Raspberry Pi OS fully up and running and then we launch the Python script from the command line.
What we need: As soon as we power up the Raspberry, we would like the unit to boot up and run our Python script directly without any extra UI input.
There are quite a few ways, see here. One of the ways would be to add the program to be run at startup to the init.d directory using the following lines:
sudo cp /home/pi/sample.py /etc/init.d/
Move to the init directory and open the sample script
cd /etc/init.d
sudo nano sample.py
pigpiod is a daemon to control Remote GPIO (Raspberry Pi).
I'm trying to load it remotely from rpi#1 on rpi#2, unsuccessfuly.
Both RPi run Python 3.5 With Ubuntu 16.04.
when using on local machine- daemon's executed OK:
def runpigpiod_local():
subprocess.run(['sudo','pigpiod'])
BUT- when trying to execute it remotely- it fails
def runpigpiod(adress):
result = subprocess.run(['ssh','guy#192.168.2.112','sudo pigpiod'])
output:
guy#192.168.2.112's password:
sudo: no tty present and no askpass program specified
Question is answered in:
Configuring Remote GPIO
I have a simple python script on a Raspberry Pi connected using WiFi that activates an LED. Simple enough.
Is it possible to launch that python script from another device attached to the same network using a simple button in VB.net? Thanks in advance for your help!
You will need to use system call in VB, which run the following command in your PC:
ssh user#rpi:/path/to/command.py arg1 arg2
see this, How do I call a Windows shell command using VB6?.
You will need to run ssh server on the rpi, and possibly set passwordless ssh access using keys.
For ssh on windows, you need either cygwin or putty.