In this article, we will use Snapcraft to create a specific and interesting application: a Webcam server. We’re going to start at zero, just until we’ve done the whole application. The end result is that we can see a new Image from the Webcam every 10 seconds on a Webserver.

The final source code for this tutorial is at github.com/liu-xiao-gu…

\

1) Hardware composition

\

For this exercise, we will use a raspberry PI 2 and a Webcam (which could be logitech’s camera). For information on how to assemble your own RaspBerry PI box, see my article “How to Install Snappy Ubuntu on RaspBerry PI”. For now, I’m going to use a creative camera. The advantage of this camera is that no driver is used in Snappy Ubuntu:

\

      \

\

We can connect our camera to a USB port on our Raspberry PI, and of course, we can buy an original Raspberry PI Webcam. So our basic hardware is matched. After we connect to our webcam, we can use the following command in my Snappy Ubuntu system to check whether our video device already exists:

$ ls /dev/video*
/dev/video0
Copy the code

If you’ve seen any of these devices on display, congratulations. Your camera has been successfully recognized by the system. Developers who have their own Beaglebone development board can also use it directly. I don’t need to go over it here.

\

\

2) Software installation

\

In this section, we want to install the tools for creating Snap on our Desktop. We can use this tool to create the SNAP packages we need. This package can be used successfully with the SNappy system in KVM. Although webcam applications cannot currently be tested in KVM (video devices are not properly recognized), we can test our installation by installing in a KVM environment. Eventually, we could package our application as an ARMHF architecture package and test it on arm-based devices such as raspberry PI. If the developer already has a Snappy Personal Desktop installed, the following steps are not required.

\

$ sudo add-apt-repository ppa:snappy-dev/tools  
$ sudo apt-get update  
$ sudo apt-get install snappy-tools bzr snapcraft  
Copy the code

\

With this command, we can install the package we need to develop Snappy.

In order for the tutorial to be packaged in a Desktop environment, we must install the following Golang package:

\

$ sudo apt-get install golang-go
Copy the code

\

\

3) Set up a Webserver

\

\

The Golang language has its own standard WebServer in its library. In this case, we will use directly. I’ll create my own WebServer with just a few words:

\

package main
import "net/http"
func main() {
    panic(http.ListenAndServe(":8080", http.FileServer(http.Dir("."))))
}
Copy the code

This Webserver is built on port 8080 and displays all the contents of the current directory. If there is an index. HTML file in the current directory, it will be displayed. Otherwise, it will simply display all files in the current directory. The source code can be found at golang-static-http. In this tutorial, we can use github code directly in our snapcraft. Yaml, so we don’t have to build this file ourselves.

\

\

\

4) Webcam application

\

In the Ubuntu Archive, there is an application called FSWebcam. It has many functions. In fact, we can install it on our desktop as follows:

\

$ sudo apt-get install fswebcam
Copy the code

We can also get a frame image file from webcam in the following way:

\

$ fswebcam output.jpg
Copy the code

The whole project source in FSWebcam. Its user manual can be found at the address. In our Webcam application, the method described in Snapcraft. Yaml will be automatically downloaded into the project for us and packaged into our final Snap package. Here we just want to show how FSWebCam is used in the Desktop environment.

\

\

5) How to use Snapcraft

\

In this section, we will show you how to use Snapcraft to combine the above application (webServer + FSWebcam) and finally produce the Snap installation file we need. Snapcraft reads only one file. The file is called snapcraft. Yaml. With it, we can combine all the code we need. In this file, it defines a list of parts, or a piece of code, and the metadata information that is ultimately used to produce the SNAP package. Let’s not worry about metadata for a second.

\

Initialize the project

We can create a basic template using Snapcraft. Let’s first create a file directory called webcam-webui:

\

$ mkdir webcam-webui
$ cd webcam-webui
$ snapcraft init
Copy the code

\

Then we open the snapcraft. Yaml file we created and modify the information inside:

\

name: webcam-webui # the name of the snap
version: 1 # the version of the snap
vendor:  XiaoGuo Liu <[email protected]>
summary: Webcam web UI
description: Expose your webcam over a Web UI
icon: icon.png
Copy the code

\

We can copy icon. PNG to the current directory as follows:

\

$ cp /usr/share/icons/hicolor/64/mimetypes/text-x-apport.png ./icon.png
Copy the code

\

Of course, developers can design their own application ICONS according to their own needs.

If we run Snapcraft now, you’ll see something like this:

\

liuxg@liuxg:~/snappy/exercise/webcam-webui$ snapcraft
Issues while validating snapcraft.yaml: 'parts' is a required property
Copy the code

\

Apparently, it’s complaining that there are no parts in this file. In the following sections, we will show how to add the corresponding parts.

\

webserver part

Let’s first add a WebServer part. Open our snapcraft. Yaml file and add below the icon line:

\

parts:
  cam:
    plugin: go
    source: git://github.com/mikix/golang-static-http
Copy the code

We just defined a part called CAM. It is located under Parts. In fact, the name of this CAM can be any name you like. Under a part, there are two options:

  • Plugin: This tells Snapcraft how to interpret parts. In our case, it’s the Golang project
  • Source: This tells Snapcraft where to download the source code. In our case, the code is located at github.com/mikix/golan…

Now we can build and stage our project. Stage means that we put different parts into a common directory that snap needs. They share a common file architecture. It allows us to see that everything that goes into building a SNAP is there.

\

liuxg@liuxg:~/snappy/exercise/webcam-webui$ snapcraft stage
Pulling cam 
env GOPATH=/home/liuxg/snappy/exercise/webcam-webui/parts/cam/build go get -t -d github.com/mikix/golang-static-http
Building cam 
env GOPATH=/home/liuxg/snappy/exercise/webcam-webui/parts/cam/build go build github.com/mikix/golang-static-http
env GOPATH=/home/liuxg/snappy/exercise/webcam-webui/parts/cam/build go install github.com/mikix/golang-static-http
env GOPATH=/home/liuxg/snappy/exercise/webcam-webui/parts/cam/build cp -a /home/liuxg/snappy/exercise/webcam-webui/parts/cam/build/bin /home/liuxg/snappy/exercise/webcam-webui/parts/cam/install
Staging cam 
Copy the code

\

Above we can see the steps that Snapcraft does: pull/build/stage. The current directory structure of the entire project is as follows:

\

liuxg@liuxg:~/snappy/exercise/webcam-webui$tree – 1. ├── parts │ ├─ build │ ├─ bin │ ├─ 2 └ ─ ─ golang – static – HTTP │ │ ├ ─ ─ golang – static – HTTP │ │ └ ─ ─ the SRC │ │ └ ─ ─ github.com │ ├ ─ ─ the install │ │ └ ─ ─ bin │ │ └ ─ ─ Golang – static – HTTP │ ├ ─ ─ the SRC │ ├ ─ ─ the state │ └ ─ ─ ubuntu ├ ─ ─ the snap ├ ─ ─ snapcraft. Yaml └ ─ ─ stage └ ─ ─ bin └ ─ ─ golang-static-http \

Snapcraft downloads the go project’s source code and compiles it to its own bin directory in Part CAM. In the stage directory, it collects the bin files and so on for each part.

\

\

Add dependence to part for Ubuntu projects

In this section, we join the FSWebCAM project for our SNAP. Edit our snapcraft. Yaml file and make it look like this:

\

parts:
  cam:
    plugin: go
    source: git://github.com/mikix/golang-static-http
    stage-packages:
      - fswebcam
Copy the code

\

We added a new property called stage-Packages for our CAM Part above. It contains a yamL list. The packages in this list will serve our final SNAP package. In our case, it contains a package called FSWebcam, which is a Debian-based package.

Next, let’s stage our project again:

\

$ snapcraft stage --force
Copy the code

Or, let’s do one first:

\

$ snapcraft clean
$ snapcraft
Copy the code


liuxg@liuxg:~/snappy/exercise/webcam-webui$ tree -L 4

. ├ ─ ─ icon. PNG ├ ─ ─ parts │ └ ─ ─ CAM │ ├ ─ ─ build │ │ ├ ─ ─ bin │ │ ├ ─ ─ golang – static – HTTP │ │ └ ─ ─ the SRC │ ├ ─ ─ the install │ │ ├ ─ ─ Bin │ │ ├ ─ ─ etc │ │ ├ ─ ─ lib │ │ ├ ─ ─ usr │ │ └ ─ ─ var │ ├ ─ ─ the SRC │ ├ ─ ─ the state │ └ ─ ─ ubuntu │ ├ ─ ─ the download │ ├ ─ ─ etc │ └ ─ ─ Var ├ ─ ─ the snap ├ ─ ─ snapcraft. Yaml └ ─ ─ stage ├ ─ ─ bin │ └ ─ ─ golang – static – HTTP ├ ─ ─ etc │ ├ ─ ─ fonts │ │ ├ ─ ─ the conf. Avail │ │ ├ ─ ─ the conf. D. │ │ └ ─ ─ fonts. Conf │ └ ─ ─ ucf. Conf ├ ─ ─ lib │ └ ─ ─ x86_64 – Linux – gnu │ ├ ─ ─ libexpat. So. 1 – > libexpat. So the 1.6.0 │ ├ ─ ─ libexpat. So. 1.6.0 │ ├ ─ ─ libpng12. So. 0 – > libpng12. So the 0.51.0 │ └ ─ ─ libpng12. So the 0.51.0 ├ ─ ─ usr │ ├ ─ ─ bin │ │ ├ ─ ─ Fswebcam │ │ ├ ─ ─ LCF │ │ ├ ─ ─ ucf │ │ ├ ─ ─ ucfq │ │ └ ─ ─ ucfr │ ├ ─ ─ lib │ │ └ ─ ─ x86_64 – Linux – gnu │ └ ─ ─ share │ ├ ─ ─ doc │ ├ ─ ─ doc – base │ ├ ─ ─ fonts │ ├ ─ ─ lintian │ ├ ─ ─ man │ └ ─ ─ X11 └ ─ ─ var └ ─ ─ lib └ ─ ─ ucf \

Or a more detailed map can be found at the address. As you can see above, the FSWebCAM application appears in the /usr/bin directory in stages. Snapcraft downloaded all the fsWebcam-related packages into the project. These packages are required to run FSWebcam. If we look at the directory stage, we can see something like this:

$ ls stage
bin  etc  lib  usr  var
Copy the code


\

Copy part

\

We now have two executable projects in our project (Golang project and FSWebCAM). So how do we connect them?

Let’s create a script called webcam-webui. It reads as follows:

\

#! /bin/sh set -e cd "$SNAP_APP_DATA_PATH" golang-static-http & while :; do fswebcam shot.jpeg sleep 10 doneCopy the code

In this script, we first go to the directory SNAP_APP_DATA_PATH. For the contents of SNAP_APP_DATA_PATH, try installing the Hello-world application from snappy Store and running hello-world.env to get the hello-world path. The same is true for this application. It is in a path similar to the following:

\

/var/lib/apps/webcam-webui.sideload/IEcPTcTMdHOG$ 
Copy the code

\

The following number here “IEcPTcTMdHOG” represents a temporary version number assigned. This number was finally taken from the version number defined in Snapcraft after it was passed on to the Snappy store. For details on this path, see the article “Snappy Ubuntu Getting Started”. In the above script, it starts the Web Server after going to the SNAP_APP_DATA_PATH directory, and then, every 10 seconds, grabs a photo and stores it in a file called shot.jpeg.

Let’s change the above script to an executable file:

\

$ chmod a+x webcam-webui
Copy the code

\

Let’s put the script in our snapcraft. Yaml as well:

\

parts:
  cam:
    plugin: go
    source: git://github.com/mikix/golang-static-http
    stage-packages:
      - fswebcam
  glue:
    plugin: copy
    files:
      webcam-webui: bin/webcam-webui
Copy the code

Copy Plugin Copies files from the files list to the specified directory. In our case, it copies the script file we created, webcam-webui, to the bin directory.

If we rerun our Snapcraft now, we can easily find the Webcam-webui script in the bin directory.

\

$ snapcraft stage
Copy the code

What we display in stage/bin:

\

liuxg@liuxg:~/snappy/exercise/webcam-webui$ls stage/bin -al total 5660 DRWXRWXR -x 2 liuxg liuxg 4096 11月 16 17:13. Drwxrwxr-x 7 Liuxg LIUxG 4096 11月 16 16:35.. -rwxr-xr-x 2 liuxg liuxg 5781856 11月 16 16:35 golang static-rwxr-x 2 liuxg liuxg 119 11月 16 17:12 webcam-webuiCopy the code

\

Filesets

In the stage directory, some files are used to build other dependent parts at the staging stage, and some are packaged into the final SNAP package. In the Stage, there are many production files, but not all of them are the ones we will eventually need to produce our SNAP files. In our case, we need to use Filesets to extract the files we need. Let’s edit our snapcraft. Yaml:

\

parts:
  cam:
    plugin: go
    source: git://github.com/mikix/golang-static-http
    stage-packages:
      - fswebcam
    filesets:
      fswebcam:
        - usr/bin/fswebcam
        - lib
        - usr/lib
      go-server:
        - bin/golang-*
    snap:
      - $fswebcam
      - $go-server
  glue:
    plugin: copy
    files:
      webcam-webui: bin/webcam-webui
Copy the code

On top, we added two filesets: FSwebCA and Go-Server. We need to add $to reference them in the SNAP item. In our case, they are $FSWebcam and $GO-Server. You can use * to include all files or directories (if the first letter of the file is *, you need to reference it, such as ‘*’).

\

\

Extend metadata

\

The items defined in snapcraft. Yaml will eventually be used to produce package-related files in the meta files directory. You can find more information in the “Format of this Metadata” link. The template created with Snapcraft above does not contain any information about our parts, nor does it contain the services or binaries we need. They tell us how to launch our application. Let’s reopen our snapcraft. Yaml and edit it as follows:

\

name: webcam-webui # the name of the snap
version: 1 # the version of the snap
vendor:  XiaoGuo Liu <[email protected]>
summary: Webcam web UI
description: Expose your webcam over a Web UI
icon: icon.png

services:
  webcam-webui:
    start: bin/webcam-webui

parts:
  cam:
    plugin: go
    source: git://github.com/mikix/golang-static-http
    stage-packages:
      - fswebcam
    filesets:
      fswebcam:
        - usr/bin/fswebcam
        - lib
        - usr/lib
      go-server:
        - bin/golang-*
    snap:
      - $fswebcam
      - $go-server
  glue:
    plugin: copy
    files:
      webcam-webui: bin/webcam-webui
Copy the code

On top of that, we’ve added the “services” part. Indicates that the application is a service. It will run automatically during installation or system startup. We use the following command to generate our final.snap file.

\

$ snapcraft
Copy the code

We can see the production file webcam-webui_1_amd64.snap in our directory.

\

\

\

6) Derived armHF Snap pack for raspberries

\

\

We can push our code to Github. I have put the final complete code on github.com/liu-xiao-gu… . Can we set up an environment in Raspberry PI and produce the corresponding.snap package by referring to the article “How to Compile and package Snap (2) for Our Snappy Ubuntu Application”

\

$ git clone https://github.com/liu-xiao-guo/webcam-webui  
Copy the code

\

ubuntu@a5ceb8ea0825:~/work$ git clone https://github.com/liu-xiao-guo/webcam-webui
Cloning into 'webcam-webui'...
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 5 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.
Checking connectivity... done.
ubuntu@a5ceb8ea0825:~/work$ source /home/ubuntu/.gvm/scripts/gvm  
ubuntu@a5ceb8ea0825:~/work$ cd webcam-webui/
ubuntu@a5ceb8ea0825:~/work/webcam-webui$ ls
icon.png  snapcraft.yaml  webcam-webui
ubuntu@a5ceb8ea0825:~/work/webcam-webui$ snapcraft
Pulling cam 
Get:1 http://ports.ubuntu.com wily InRelease [218 kB]                                             
Get:2 http://ports.ubuntu.com wily-updates InRelease [64.4 kB]                                    
Get:3 http://ports.ubuntu.com wily-security InRelease [64.4 kB]                                   
Get:4 http://ports.ubuntu.com wily/main armhf Packages [1793 kB]                                  
Get:5 http://ports.ubuntu.com wily/restricted armhf Packages [12.4 kB]                            
Get:6 http://ports.ubuntu.com wily/universe armhf Packages [8507 kB]                              
Get:7 http://ports.ubuntu.com wily/multiverse armhf Packages [150 kB]                             
Get:8 http://ports.ubuntu.com wily-updates/main armhf Packages [56.6 kB]                          
Get:9 http://ports.ubuntu.com wily-updates/restricted armhf Packages [40 B]                       
Get:10 http://ports.ubuntu.com wily-updates/universe armhf Packages [25.6 kB]                     
Get:11 http://ports.ubuntu.com wily-updates/multiverse armhf Packages [40 B]                      
Get:12 http://ports.ubuntu.com wily-security/main armhf Packages [45.5 kB]                        
Get:13 http://ports.ubuntu.com wily-security/restricted armhf Packages [40 B]                     
Get:14 http://ports.ubuntu.com wily-security/universe armhf Packages [21.6 kB]                    
Get:15 http://ports.ubuntu.com wily-security/multiverse armhf Packages [40 B]                     
Fetched 11.0 MB in 6s (73.0 kB/s)                                                                 
Skipping blacklisted from manifest packages: ['adduser', 'apt', 'apt-utils', 'base-files', 'base-passwd', 'bash', 'bsdutils', 'coreutils', 'dash', 'debconf', 'debconf-i18n', 'debianutils', 'diffutils', 'dmsetup', 'dpkg', 'e2fslibs', 'e2fsprogs', 'file', 'findutils', 'gcc-4.9-base', 'gcc-5-base', 'gnupg', 'gpgv', 'grep', 'gzip', 'hostname', 'init', 'initscripts', 'insserv', 'libacl1', 'libapparmor1', 'libattr1', 'libaudit-common', 'libaudit1', 'libblkid1', 'libbz2-1.0', 'libc-bin', 'libc6', 'libcap2', 'libcap2-bin', 'libcomerr2', 'libcryptsetup4', 'libdb5.3', 'libdebconfclient0', 'libdevmapper1.02.1', 'libgcc1', 'libgcrypt20', 'libgpg-error0', 'libgpm2', 'libkmod2', 'liblocale-gettext-perl', 'liblzma5', 'libmagic1', 'libmount1', 'libncurses5', 'libncursesw5', 'libpam-modules', 'libpam-modules-bin', 'libpam-runtime', 'libpam0g', 'libpcre3', 'libprocps3', 'libreadline6', 'libselinux1', 'libsemanage-common', 'libsemanage1', 'libsepol1', 'libslang2', 'libsmartcols1', 'libss2', 'libstdc++6', 'libsystemd0', 'libtext-charwidth-perl', 'libtext-iconv-perl', 'libtext-wrapi18n-perl', 'libtinfo5', 'libudev1', 'libusb-0.1-4', 'libustr-1.0-1', 'libuuid1', 'locales', 'login', 'lsb-base', 'makedev', 'manpages', 'manpages-dev', 'mawk', 'mount', 'multiarch-support', 'ncurses-base', 'ncurses-bin', 'passwd', 'perl-base', 'procps', 'readline-common', 'sed', 'sensible-utils', 'systemd', 'systemd-sysv', 'sysv-rc', 'sysvinit-utils', 'tar', 'tzdata', 'ubuntu-keyring', 'udev', 'util-linux', 'zlib1g']
Get:1 http://ports.ubuntu.com/ubuntu-ports/ wily/main libpng12-0 armhf 1.2.51-0ubuntu3 [108 kB]   
Get:2 http://ports.ubuntu.com/ubuntu-ports/ wily/main libxau6 armhf 1:1.0.8-1 [7324 B]            
Get:3 http://ports.ubuntu.com/ubuntu-ports/ wily/main libxdmcp6 armhf 1:1.1.2-1 [9804 B]          
Get:4 http://ports.ubuntu.com/ubuntu-ports/ wily/main fonts-dejavu-core all 2.35-1 [1039 kB]      
Get:5 http://ports.ubuntu.com/ubuntu-ports/ wily/main ucf all 3.0030 [55.5 kB]                    
Get:6 http://ports.ubuntu.com/ubuntu-ports/ wily/main fontconfig-config all 2.11.1-0ubuntu6 [48.7 kB]
Get:7 http://ports.ubuntu.com/ubuntu-ports/ wily/main libexpat1 armhf 2.1.0-7 [52.4 kB]           
Get:8 http://ports.ubuntu.com/ubuntu-ports/ wily/main libfreetype6 armhf 2.5.2-4ubuntu2 [265 kB]  
Get:9 http://ports.ubuntu.com/ubuntu-ports/ wily/main libfontconfig1 armhf 2.11.1-0ubuntu6 [110 kB]
Get:10 http://ports.ubuntu.com/ubuntu-ports/ wily/main libjpeg-turbo8 armhf 1.3.0-0ubuntu2 [85.2 kB]
Get:11 http://ports.ubuntu.com/ubuntu-ports/ wily/main libjbig0 armhf 2.1-3.1 [24.3 kB]           
Get:12 http://ports.ubuntu.com/ubuntu-ports/ wily/main libjpeg8 armhf 8c-2ubuntu8 [2202 B]        
Get:13 http://ports.ubuntu.com/ubuntu-ports/ wily/main libtiff5 armhf 4.0.3-12.3ubuntu2 [129 kB]  
Get:14 http://ports.ubuntu.com/ubuntu-ports/ wily/main libxcb1 armhf 1.11-0ubuntu1 [36.6 kB]      
Get:15 http://ports.ubuntu.com/ubuntu-ports/ wily/main libx11-data all 2:1.6.3-1ubuntu2 [113 kB]  
Get:16 http://ports.ubuntu.com/ubuntu-ports/ wily/main libx11-6 armhf 2:1.6.3-1ubuntu2 [514 kB]   
Get:17 http://ports.ubuntu.com/ubuntu-ports/ wily/main libxpm4 armhf 1:3.5.11-1 [28.6 kB]         
Get:18 http://ports.ubuntu.com/ubuntu-ports/ wily/main libapt-pkg4.16 armhf 1.0.10.2ubuntu1 [585 kB]
Get:19 http://ports.ubuntu.com/ubuntu-ports/ wily/main libapt-inst1.7 armhf 1.0.10.2ubuntu1 [55.2 kB]
Get:20 http://ports.ubuntu.com/ubuntu-ports/ wily/main libvpx2 armhf 1.4.0-4 [925 kB]             
Get:21 http://ports.ubuntu.com/ubuntu-ports/ wily/main libgd3 armhf 2.1.1-4build1 [106 kB]        
Get:22 http://ports.ubuntu.com/ubuntu-ports/ wily/universe fswebcam armhf 20140113-1 [40.8 kB]    
Fetched 4341 kB in 6s (30.7 kB/s)                                                                 
env GOPATH=/home/ubuntu/work/webcam-webui/parts/cam/build go get -t -d github.com/mikix/golang-static-http
Building cam 
env GOPATH=/home/ubuntu/work/webcam-webui/parts/cam/build go build github.com/mikix/golang-static-http
env GOPATH=/home/ubuntu/work/webcam-webui/parts/cam/build go install github.com/mikix/golang-static-http
env GOPATH=/home/ubuntu/work/webcam-webui/parts/cam/build cp -a /home/ubuntu/work/webcam-webui/parts/cam/build/bin /home/ubuntu/work/webcam-webui/parts/cam/install
Staging cam 
Snapping cam 
Pulling glue 
Building glue 
cp --preserve=all -R webcam-webui /home/ubuntu/work/webcam-webui/parts/glue/install/bin/webcam-webui
Staging glue 
Snapping glue 
2015/11/17 01:13:26.323310 main.go:42: WARNING: can not create syslog logger
Generated 'webcam-webui_1.0_armhf.snap' snap
ubuntu@a5ceb8ea0825:~/work/webcam-webui$ ls 
icon.png  parts  snap  snapcraft.yaml  stage  webcam-webui  webcam-webui_1.0_armhf.snap
Copy the code

We can see from above that we have produced snap packs for our raspberry PI ARMHF. We can install it on our raspberry pie.

\

ubuntu@a5ceb8ea0825:~/work/webcam-webui$ exit logout (RaspberryPi2)ubuntu@localhost:~$ cd Apps/docker / 1.6.2.004 / work/webcam - webui/(RaspberryPi2) ubuntu @ localhost: ~ / apps/docker 1.6.2.004 / work/webcam - webui $ls PNG parts Snap snapcraft. Yaml stage Webcam-webui webcam-webui_1.0_armhF.snap (RaspberryPi2) ubuntu @ localhost: ~ / apps/docker / 1.6.2.004 / work/webcam - webui $sudo snappy install - allow unauthenticated Snap Installing webCAM-WeBUi_0_armHF. Snap 2015/11/17 01:16:59.252451 verify.go:85: Signature check failed, but installing anyway as requested Name Date Version Developer ubuntu-core 2015-09-25 2 ubuntu docker 2015-11-13 1.6.2.005 Sideload GlowAPI 2015-10-31 0.1.2 VTuson Hello world 2015-11-12 1.0.18 Canonical MQtt-piglow 2015-11-02 IEWUKJCENbWA Sideload MQTTTestClient 2015-11-12 IFOTYdKLCaGB Sideload SNappy -debug 2015-11-14 0.6 Canonical Webcam-demo IFUgCESTPcKT Sideload WebDM 2015-10-29 0.9.4 Sideload PI2 2015-09-25 0.16 CanonicalCopy the code

As you can see from the above, we have successfully deployed webcam-webui to our Raspberry PI. Next, we can give our application access to our hardware device /dev/video0 by using the following command.

\

$ sudo snappy hw-assign webcam-webui.sideload /dev/video0

\

(RaspberryPi2) ubuntu @ localhost: ~ / apps/docker / 1.6.2.004 / work/webcam - CD (RaspberryPi2) ubuntu webui $@ localhost: $ls ~ /dev/video0 /dev/video0 (RaspberryPi2)ubuntu@localhost:~$ sudo snappy hw-assign webcam-webui.sideload /dev/video0 'webcam-webui.sideload' is now allowed to access '/dev/video0' (RaspberryPi2)ubuntu@localhost:~$ sudo snappy service status Snap Service State docker docker-daemon ; not-found; inactive (dead) docker docker-daemon enabled; loaded; active (running) glowapi glowapi enabled; loaded; active (running) mqtt-piglow mqtt-piglow enabled; loaded; active (running) webcam-demo webcam-demo enabled; loaded; active (running) webcam-webui webcam-webui enabled; loaded; active (running) webcam webcam enabled; loaded; active (running) webdm snappyd ; not-found; inactive (dead) webdm snappyd enabled; loaded; active (running)Copy the code

\

If we cancel the application’s access to the hardware, we can use the following command:

\

$ sudo snappy hw-unassign webcam-webui.sideload /dev/video0
Copy the code

\

You can run the following command to view the hardware access status of the current application:

\

$ sudo snappy hw-info webcam-webui.sideload
Copy the code

\

We can check if it works by:

\

\

\

\


\

Note that the IP address above needs to be changed to your own raspberry PI IP address. At this point, we have successfully completed the deployment and testing of our application. I hope you have also completed this exercise!

\

\

\

7) More learning materials

\

We have now successfully created our SNAP file. We can download snapcraft source code:

\

git clone https://github.com/ubuntu-core/snapcraft
cd snapcraft/examples
Copy the code

\

More examples are available under its examples directory.

\