Can I run and develop a python program from another computer? - python

So, I want to be able to write Python code in my Visual Studio Code on my Windows PC. On my network is a raspberry pi 4, which I would like to execute said code on and receive any errors or output from.
Is it possible for me to write some python code on my Windows PC, "run" it on the Raspberry pi, and receive any outputs of the program on my Windows PC?
The reason I wish to do this is that Visual Studio Code generally helps me write any code, and it is more time consuming for me to use other IDE's, and my code uses PyBluez, something I can't just test on my Windows PC (which has no Bluetooth module)
I hope my question is in the right format and such! This is my first time posting! Any comments appreciated!

Yes you can do that, but it might not be very straight forward. In order to achieve this, you need your Raspberry Pi to be on the same network as your Windows PC (i.e. on the same WiFi network or connected via Ethernet). Then you need to get the IP address of your Raspberry Pi through the following command:-
ifconfig -a
The IP address will be of the following format: W.X.Y.Z
Now from your Windows PC, you can send your python script/scripts through the following command from cmd:-
scp script.py pi#W.X.Y.Z:/home/
And then you can access your Raspberry Pi and run the program by sshing into it through the following commands from cmd:-
ssh pi#W.X.Y.Z
You'll need to enter the Raspberry Pi's password for both commands above, but after that you should have your script on your Pi and you should be able to run it there from your Windows PC.
The links below have more verbose explanation:-
https://www.raspberrypi.org/documentation/remote-access/ip-address.md
https://www.raspberrypi.org/documentation/remote-access/ssh/scp.md
https://www.raspberrypi.org/documentation/remote-access/ssh/
I hope this helps.

It seems that my answer was to use the Remote Development pack on Visual Studio Code (it's an extension) to ssh into my raspberry pi. It's worked well for me for the past few days, and I highly recommend it. It allowed me to access the entire sd card and access any files I need to, while also giving me an SSH terminal and run the program ON the other machine.
For anyone who does this; set up the whole ssh key thing, to stop having to give the password to the pi so often.
The scp command would also work, I think, but is more complex than what I want to do.
Thank you so much for the answer, JL Peyret!

Related

unable to flash micropython to esp 32: open serial error

issue: unable to flash micropython to esp 32: open serial error, please try again. hope to connect internet and try again.
pretty new to micropython - want to flash micropython to esp 32 ( resp 8266) board.
cf this docs: https://maker.pro/esp8266/tutorial/using-micropython-on-an-esp8266-with-upycraft
getting this errors all the time.
open serial error, please try again.
hope to connect internet and try again.
current version only open py txt json ini file.
hope to connect internet and try again.
hope to connect internet and try again.
i run Win 7
the hardware:
a. Joy-IT-Node MCU ESP8266
.. and besides that i also tried it with the following
b. ESP32-T Development Board CP2102 with Espressif ESP-WROOM-32 IoT WLAN & BLE Modul
yes: i have installed the > CP210x_Universal_Windows_Driver.zip
by the way: i could try to do all that on a linux machine. - on a MX-Linux-Sytem
any idea;
many thanks for any and all help in advance.
As of my opinion, You don't necessarily depend on the uPyCraft IDE. So there are several other ways to develop scripts and uploading them to Your board.
Some days ago I was facing problems with Python on the NodeMcu as well. Since I didn't like the tutorials around the web, I've set up one on GitHub, covering the end-to-end process (required software, drivers, firmware images, developing, flashing, uploading, etc.): python2nodemcu.
It depends on Mac and the NodeMcu board, but some of the topics may apply to other operating systems and boards as well.
And I think it covers the most relevant parts of the whole process, using the easiest tools around the web. Please have a look at it, but all in all it goes like this (short version of the linked documentation above):
Install Python 3
Verify with python --version
Or python3 --version
Install the correct SiLabs driver to enable serial USB-to-UART communication
See here
Find the device file (representing the interface to the physical device)
Try it using ls -la /dev/tty.*
Download the recent MicroPython firmware
You need the right one for Your board
Install the two Python-based libraries EspTool and PySerial
Try to erase the flash of Your device
Run python3 esptool.py --port /dev/tty.{device-file} erase_flash
Try to flash the original image or the MicroPython firmware to the board
Run python3 esptool.py --port /dev/tty.{device-file} write_flash 0x00000 {micropython-image-or-original-firmware}.bin
Try to connect to the board via the REPL prompt
Run screen /dev/tty.{device-file} 115200
You maybe need to try different baud rates (depending on Your driver, cable, etc.)
Connect to the board using Ampy
For example, try to list the files on Your device executing python3 ampy/cli.py --port /dev/tty.{device-file} --baud 115200 ls
Again, try other baud rates
Anyway, I've noticed that You do not necessarily need to push the physical flash button on the device.

How do I make rsync work over the serial port?

I am using a Raspberry Pi zero that runs on Rasbpian, and am connecting it with a computer, through a transceiver. I use minicom on the Raspberry Pi and Putty on the laptop to second documents.
I wrote some code that automatically generates files in a folder, and want to send those files through serial to my laptop the moment they are generated. I've heard that I can use rsync for this, but only read about people using it with SSH. One friend advised using piping, but I am new to this, so did not understand how to use piping with rsync.

Monitor CPU usage on different machine

As my title goes, I tried to look for something can help me to write the script to get CPU usage from another machine which will be running Virtual Machine(VM), yes I want to get the CPU usage of the VM which runs ubuntu and runs as FTP server. The thing is, I'm still trying to write the script in Python which will be run on Raspberry Pi 2.
I found a few solution that needs me to use bash scripting, but I need to compile with my script of sending ICMP request to the other machine. The thing is I need to write the script instead of using another software. Thank you in advance.
You could maybe try it with VNC but that won't give you a script that will just give you a window into the other machine.

How to execute python script based on the server of an ssh connection?

I'm connected to a Raspberry Pi via ssh. I'm trying to run a script on the RPi but rather than using a nano editor on the terminal I want to execute a python script based on my mac (the server of the SSH).
However when typing
'sudo python /Users/User/Pythonscript.py'
terminal returns
'python: can't open file '/Users/User/Pythonscript.py': [Errno 2] No such file or directory'
And yet this file does exist under that directory.
Any ideas?
Ok, if I have properly understood, you have script on your client and want to execute it on Pi from ssh.
scp /path/to/script.py user#hostname:/path/to/
then add your rsa key to your server. This perfect guide tells you how.
Then just write .sh, which get access to your server ssh user#hostname, then cd /path/to and, finally python script.py
You have a file on your Mac and want to execute it on your Pi. Two things need to be done: First, get the file to the Pi. Second log in to the Pi and run it. Apparently, you managed step two, so I'll address step 1.
The simple solution: scp, e.g. scp /Users/User/Pythonscript.py <user>#<ip_of_pi>:<target_dir>
The solution that might be longer-term more feasible, if you want to develop locally: sshfs. It's available via Homebrew. You mount a directory locally, and anything you change will automatically be reflected on the respective directory on the Pi. Here's a tutorial how to install and use sshfs. On first glance, it seems reasonable.
No matter how you get your script to the Pi, you need to find it on the Pi and execute it there.

Activating Python Script on Raspberry Pi from VB.net Application on PC

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.

Categories