- Complete MPU-MCU communication setup - LED Matrix text display with configurable parameters - Configuration management with personal data protection - Git template with .gitignore for sensitive data - Automated build and deployment scripts - SSH key management and service scripts
96 lines
3.1 KiB
Bash
Executable File
96 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Upload script for Arduino UNO Q
|
|
# Uses configuration from config.json
|
|
|
|
set -e
|
|
|
|
# Add lib directory to Python path
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
PYTHONPATH="$PROJECT_ROOT/lib:$PYTHONPATH"
|
|
|
|
# Load configuration
|
|
python3 -c "
|
|
import sys
|
|
sys.path.insert(0, '$PROJECT_ROOT/lib')
|
|
from config_loader import config
|
|
|
|
arduino_config = config.get_arduino_config()
|
|
paths = config.get_paths()
|
|
|
|
print(f'UNOQ_HOST={arduino_config[\"hostname\"]}')
|
|
print(f'UNOQ_USER={arduino_config[\"user\"]}')
|
|
print(f'SSH_KEY={arduino_config[\"ssh_key\"]}')
|
|
print(f'PYTHON_SCRIPT={paths[\"python_script\"]}')
|
|
print(f'MCU_BINARY={paths[\"mcu_binary\"]}')
|
|
" > /tmp/upload_config.sh
|
|
|
|
source /tmp/upload_config.sh
|
|
|
|
echo "Uploading to Arduino UNO Q..."
|
|
|
|
# Check SSH connection
|
|
if ! ssh -i "$SSH_KEY" -o ConnectTimeout=5 "$UNOQ_USER@$UNOQ_HOST" "echo 'Connection OK'" &> /dev/null; then
|
|
echo "Cannot connect to Arduino UNO Q at $UNOQ_HOST"
|
|
echo "Run ./setup_ssh.sh first to configure SSH"
|
|
exit 1
|
|
fi
|
|
|
|
# Upload Python script to MPU
|
|
echo "Uploading Python script to MPU..."
|
|
scp -i "$SSH_KEY" "$PYTHON_SCRIPT" "$UNOQ_USER@$UNOQ_HOST:/home/arduino/main.py"
|
|
|
|
# Make Python script executable
|
|
ssh -i "$SSH_KEY" "$UNOQ_USER@$UNOQ_HOST" "chmod +x /home/arduino/main.py"
|
|
|
|
# Upload compiled sketch to MCU
|
|
echo "Uploading compiled sketch to MCU..."
|
|
if [ -f "$MCU_BINARY" ]; then
|
|
scp -i "$SSH_KEY" "$MCU_BINARY" "$UNOQ_USER@$UNOQ_HOST:/tmp/sketch.bin"
|
|
|
|
# Use Arduino CLI on the device to flash the MCU
|
|
ssh -i "$SSH_KEY" "$UNOQ_USER@$UNOQ_HOST" "arduino-cli upload --fqbn arduino:zephyr:unoq --input-file /tmp/sketch.bin /dev/ttyACM0" || {
|
|
echo "MCU upload may require manual intervention"
|
|
echo "Try pressing the reset button during upload"
|
|
}
|
|
else
|
|
echo "MCU binary not found at $MCU_BINARY"
|
|
echo "Run ./build.sh first to compile the sketch"
|
|
fi
|
|
|
|
# Start the Python application
|
|
echo "Starting Python application on MPU..."
|
|
ssh -i "$SSH_KEY" "$UNOQ_USER@$UNOQ_HOST" "nohup python3 /home/arduino/main.py > /tmp/main.log 2>&1 &"
|
|
|
|
# Create systemd user service for auto-start
|
|
echo "Creating systemd user service for auto-start..."
|
|
ssh -i "$SSH_KEY" "$UNOQ_USER@$UNOQ_HOST" "mkdir -p ~/.config/systemd/user"
|
|
ssh -i "$SSH_KEY" "$UNOQ_USER@$UNOQ_HOST" "cat > ~/.config/systemd/user/arduino-unoq.service << 'EOF'
|
|
[Unit]
|
|
Description=Arduino UNO Q Main Application
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
WorkingDirectory=%h
|
|
ExecStart=/usr/bin/python3 %h/main.py
|
|
Restart=always
|
|
RestartSec=10
|
|
|
|
[Install]
|
|
WantedBy=default.target
|
|
EOF"
|
|
|
|
# Enable and start user service
|
|
ssh -i "$SSH_KEY" "$UNOQ_USER@$UNOQ_HOST" "systemctl --user daemon-reload"
|
|
ssh -i "$SSH_KEY" "$UNOQ_USER@$UNOQ_HOST" "systemctl --user enable arduino-unoq.service"
|
|
ssh -i "$SSH_KEY" "$UNOQ_USER@$UNOQ_HOST" "systemctl --user start arduino-unoq.service"
|
|
|
|
echo "Upload complete!"
|
|
echo "Python application running on MPU"
|
|
echo "Check status: ssh -i $SSH_KEY $UNOQ_USER@$UNOQ_HOST 'systemctl --user status arduino-unoq'"
|
|
echo "View logs: ssh -i $SSH_KEY $UNOQ_USER@$UNOQ_HOST 'journalctl --user -u arduino-unoq -f'"
|
|
|
|
# Cleanup
|
|
rm -f /tmp/upload_config.sh |