Application deployment

Now that your application have been generated thanks to redpesk CI or the rp-cli, let’s see how to install it on a board. Since redpesk support cross-compilation, we can use either a x86_64 or aarch64 board to get your package installed in.

During this part, two cases will be studied: Emulated x86_64 board: qemu-x86_64 and Real aarch64 board: m3ulcb.

Getting the redpesk image

According to your board architecture, download the image. See here for more details.

Create a directory for downloading image:

mkdir ~/redpeskimage
cd ~/redpeskimage

qemu-x86_64

wget -r -nd -nc --no-parent -A "redpesk*smack*" 'https://download.redpesk.bzh/redpesk-lts/arz-1.0/images/smack/minimal/x86_64/generic/latest'

m3ulcb

wget -r -nd -nc --no-parent -A "redpesk*smack*" 'https://download.redpesk.bzh/redpesk-lts/arz-1.0/images/smack/minimal/aarch64/m3/latest'

Notes: Login: root / password: root

Running a redpesk image

Here we are, you are about to run the redpesk image. This section will deal with both types of image: x86_64 & aarch64.

qemu-x86_64

For more details see here.

First of all unzip the archive you have just downloaded to retrieve the redpesk image.

xz -d --verbose redpesk*.raw.xz

Then download the qemu-kvm package. For example, Ubuntu user can run:

sudo apt install qemu-kvm

Then, simply run the redpesk image by doing:

export TCP_PORT=3333
qemu-system-x86_64 \
        -hda ${PATH_TO_REDPESK_IMAGE} \
        -enable-kvm \
        -bios /usr/share/qemu/OVMF.fd \
        -machine q35 \
        -m 2048 \
        -cpu kvm64 \
        -cpu qemu64,+ssse3,+sse4.1,+sse4.2,+popcnt \
        -net nic \
        -net user,hostfwd=tcp::${TCP_PORT}-:22 \
        -nographic \
        -snapshot

Notes: You may have noticed that in the previous command we allow the user to connect to the emulated board by establishing a ssh connection through the port ${TCP_PORT}. You can access your emulated board with the following command:

ssh root@localhost -p ${TCP_PORT}

m3ulcb

For more details see here.

Then insert your SDCard and retrieve its device name:

lsblk -dli -o NAME,TYPE,HOTPLUG | grep "disk.*1$"

Then export it into the environment variable DEVICE

export DEVICE="/dev/sdb"

Notes: If the SDCard is mounted, umount it.

sudo unmount ${DEVICE}

Write the image onto the SDCard.

sudo dd if=redpesk*.raw of=${DEVICE} bs=4M status=progress

Since then, your SDCard is bootable. You can access it by using the ssh command:

export YOUR_BOARD_IP=192.168.1.X
ssh root@${YOUR_BOARD_IP}

Installing your package

There are no difference in the command related to your package installation, neither in a x86_64, nor in an aarch64 redpesk distribution. Once you get in your redpesk image, you can proceed to the package installation.

As a reminder, the helloworld-binding gathered two sub-package the helloworld-binding and the helloworld-binding-test. To install the widget sub-package, you can simply run

[root@localhost ~] dnf install helloworld-binding

If you correctly set your project name and version as explained in the Build part, you should have the following output during the package installation

[root@localhost ~] dnf install helloworld-binding
NOTICE: -- Install redpesk widget from /var/local/lib/afm/applications/helloworld-binding --

Start the service by running:

[root@localhost ~] afm-util start helloworld-binding
8628

This implies that your widget has been installed correctly. Check if your widget id is helloworld-binding.

[root@localhost ~] afm-util list --all
[
  {
    "description":"Provide an Helloworld Binding",
    "name":"helloworld-binding",
    "shortname":"",
    "id":"helloworld-binding",
    "version":"1.0",
    "author":"Iot-Team <frederic.marec@iot.bzh>",
    "author-email":"",
    "width":"",
    "height":"",
    "icon":"/var/local/lib/afm/applications/helloworld-binding/icon.png",
    "http-port":30001
  }
]

You can then start the service by running:

[root@localhost ~] afm-util start helloworld-binding
8628

For example, you can access to its verb ping which belong to its api helloworld thanks to a HTTP or websocket request sent to the port $PORT such as follow

  • HTTP request
PORT=30001
# Need jq
curl -H "Content-Type: application/json" http://localhost:${PORT}/api/helloworld/ping | jq
  • Websocket request
PORT=30001
afb-client -H ws://localhost:${PORT}/api?token=x\&uuid=magic helloworld ping

For both requests you should get the following answer from the first request

ON-REPLY 1:helloworld/ping: OK
{
  "response":0,
  "jtype":"afb-reply",
  "request":{
    "status":"success",
    "info":"Ping count = 0"
  }
}

Once again, if you correctly set your project name and version as explained in the Build part, to correctly stop your service

[root@localhost ~] afm-util kill helloworld-binding
true

And to remove your widget, simply run

[root@localhost ~] dnf remove helloworld-binding