2013/11/26

A few scripts to speed up tests and deployment for the Lego Mindstorms EV3

In each script where an IP address appears, you must of course replace it by the IP address displayed in the brick info menu.

Enabling SSH

Useful to copy your files on the brick and run some commands applications remotely. You'll need expect to make it work:
#!/usr/bin/expect

#Replace with your IP address
spawn telnet 192.168.1.71
expect "login:"
send "root\r"

#dropbear enables SSH
send "dropbear\r"
send "exit\r"

interact

Connection over Telnet

Connect to your EV3 without the extra cost of the SSH protocol:
#!/usr/bin/expect

#Replace with your IP address
spawn telnet 192.168.1.71

expect "login:"
send "root\r"

interact

Copy a program

Assuming you want to copy it to /media/card/program/program
#!/bin/bash

#Replace with your IP address
EV3_IP=192.168.1.71

if ! [[ $# -eq 1 ]]
then
    echo "Missing parameter : PROJECT NAME"
else
    PROJECT_NAME=$1
    EV3_PROJECT_DIR="/media/card/$1"

    if ! [[ -d $PROJECT_NAME ]]
    then
        echo "Project doesn't exist."
    else
        #Create the project directory
        ssh root@$EV3_IP "mkdir $EV3_PROJECT_DIR"
        scp $PROJECT_NAME/$PROJECT_NAME root@$EV3_IP:$EV3_PROJECT_DIR/$PROJECT_NAME
    fi
fi

Run a program remotely

Run an application over SSH:
#!/bin/bash

#Replace with your IP address
EV3_IP=192.168.1.71

if ! [[ $# -eq 1 ]]
then
    echo "Missing parameter : PROJECT NAME"
else
    PROJECT_NAME=$1
    EV3_PROJECT_PATH="/media/card/$1/$1"

    if ! [[ -d $PROJECT_NAME ]]
    then
        echo "Project doesn't exist."
    else
        #Environment setup and program launch
        ssh root@$EV3_IP \
        "export QT_QPA_PLATFORM_PLUGIN_PATH=/media/card/lib/platforms && \
         export QT_QPA_FONTDIR=/media/card/lib/fonts && \
         $EV3_PROJECT_PATH -platform ev3linuxfb"
    fi
fi

Copy libraries, fonts and platform plugin

Useless if you have a SD card drive on your computer:
#!/bin/bash

#Replace with your IP address
EV3_IP=192.168.1.71

#Depends on your Qt version
VERSION=5
FULL_VERSION=$VERSION.1.1

#Depends on the '-prefix' configure option you choose to compile Qt
SOURCE_DIR=/home/user/Qt$FULL_VERSION

#Depends on the '-qtlibinfix' configure option you choose to compile Qt
LIB_SUFFIX=_ev3

TARGET_DIR=/media/card/lib
TARGET_PLUGIN_DIR=$TARGET_DIR/plugins/platforms

#Qt libraries
scp $SOURCE_DIR/lib/libQt5Core$LIB_SUFFIX.so.$VERSION root@$EV3_IP:$TARGET_DIR
scp $SOURCE_DIR/lib/libQt5Gui$LIB_SUFFIX.so.$VERSION root@$EV3_IP:$TARGET_DIR
scp $SOURCE_DIR/lib/libQt5Network$LIB_SUFFIX.so.$VERSION root@$EV3_IP:$TARGET_DIR

#Fonts
scp -r $SOURCE_DIR/lib/fonts root@$EV3_IP:$TARGET_DIR

#Create platform plugin directory
ssh root@$EV3_IP mkdir -p $TARGET_PLUGIN_DIR

#Copy platform plugin
scp $SOURCE_DIR/plugins/platforms/libev3linuxfb.so root@$EV3_IP:$TARGET_PLUGIN_DIR/

No comments:

Post a Comment