I am working on a vagrant / python script that will download micro controllers The vagrant script loads the below VM:
pi5.vm.box = "debian/buster64"
Then I also load these as stand-ins for microcontrollers:
config.vm.define "pico_w#{i}" do |pico|
pico.vm.box = "generic/alpine316"
pico.disksize.size = '4MB'
pico.vm.provider "virtualbox" do |vb|
vb.memory = "256"
vb.cpus = 2
end
I can spin up these no problem. The problem comes when I try to download the core RPI_PICO2-20241129-v1.24.1.uf2 and upload to the VM so I can get a more accurate system with which to develop an install script for my localized application.
GOAL: I want to solve easy communication such that I can upload micropython to stand-in microcontrollers.
import subprocess
# Constants for VM and firmware details
VM_IP = "x.x.x.x"
SSH_USER = "root"
SSH_PASSWORD = "vagrant"
MICROPYTHON_URL = "https://micropython.org/resources/firmware"
MICROPYTHON_FILE = "RPI_PICO2-20241129-v1.24.1.uf2"
MICROPYTHON_PATH = f"~/path/to/{MICROPYTHON_FILE}"
def download_firmware(url, file_path):
try:
subprocess.run(f"wget {url}/{file_path} -O {MICROPYTHON_PATH}", shell=True, check=True, capture_output=True)
print(f"Firmware downloaded to {MICROPYTHON_PATH}")
except subprocess.CalledProcessError as e:
print(f"Download failed: {e}")
exit(1)
def upload_firmware(firmware_path, ip, user, password):
try:
# Copy firmware to VM
subprocess.run(f"sshpass -p '{password}' scp -o StrictHostKeyChecking=no {firmware_path} {user}@{ip}:/tmp/", shell=True, check=True, capture_output=True)
# Simulate flashing by moving the file
subprocess.run(f"sshpass -p '{password}' ssh -o StrictHostKeyChecking=no {user}@{ip} 'sudo mv /tmp/{MICROPYTHON_FILE} /mnt/'", shell=True, check=True, capture_output=True)
print("Firmware uploaded to VM.")
except subprocess.CalledProcessError as e:
print(f"Upload failed: {e}")
exit(1)
# Main execution
download_firmware(MICROPYTHON_URL, MICROPYTHON_FILE)
upload_firmware(MICROPYTHON_PATH, VM_IP, SSH_USER, SSH_PASSWORD)
print("Firmware process completed!")
Simplified summary: I want to develop an install script that loads micropython into micro-controllers such that I can download a script into a pi then that pi can push the needed code to the microcontrollers and local system. I am making a virtual stand-in for this, and have made the above progress, but run into authentication errors. Can you correct my current approach and code such that I achieve the digital twin that I can can tear down and retest as needed for the download script? Thank you!