Internet of Things with Python
上QQ阅读APP看书,第一时间看更新

Installing and upgrading the necessary libraries to interact with the board

Now, we will run many commands in the SSH client. Make sure that your SSH client is connected to the Yocto Linux SSH server running on the board as explained in the preceding section before running the commands. Specially, if you are working with either OS X or Linux, you have to make sure that you don't run the commands on your computer instead of doing this on the remote shell. Its simple, just make sure you always see the prompt root@galileo:~# before running any command.

Tip

Your board should be connected to a LAN with Internet access because we will download content from the Internet.

We will use the opkg utility to download and install the updated version of both the mraa and upm libraries. The mraa library, also known as libmraa, is a low level C/C++ library with bindings to Python that allows us to interface with the I/O features on the Intel Galileo Gen 2 board and other supported platforms. The upm library provides high-level interfaces for sensors and actuators that we can plug to the platforms supported by the mraa library. The upm library simplifies working with sensors and actuators and includes bindings to Python. We will be working with both libraries in the forthcoming chapters, and therefore, we want to have their latest versions installed.

The opkg utility is a lightweight package manager that allows us to easily download and install OpenWrt packages. OpenWrt is a Linux distribution for embedded devices. First, we will check both the mraa and upm installed versions by using the opkg utility.

Run the following command to check the installed mraa version:

opkg info mraa

The following lines show the output with the version and dependencies for the mraa package. In this case, the output shows that the installed version for mraa is 0.7.2-r0.

Package: mraa
Version: 0.7.2-r0
Depends: libgcc1 (>= 4.9.1), python-core, libpython2.7-1.0 (>= 2.7.3), libstdc++6 (>= 4.9.1), libc6 (>= 2.20)
Status: install user installed
Architecture: i586
Installed-Time: 1434860546

Run the following command to check the installed upm version:

opkg info upm

The following lines show the output with the version and dependencies for the upm package. In this case, the output shows that the installed version for upm is 0.3.1-r0.

Package: upm
Version: 0.3.1-r0
Depends: libgcc1 (>= 4.9.1), libpython2.7-1.0 (>= 2.7.3), libc6 (>= 2.20), python-core, libstdc++6 (>= 4.9.1), mraa (>= 0.7.2)
Status: install user installed
Architecture: i586
Installed-Time: 1434860596

Run the following command to check the repository configuration for both the mraa and upm libraries.

cat /etc/opkg/mraa-upm.conf

If you see the following line as a response, it means that the repository is configured to work with the 1.5 version and we need to change its configuration to make it possible to update both the mraa and upm libraries to their latest versions.

src mraa-upm http://iotdk.intel.com/repos/1.5/intelgalactic

Run the following command to configure the repository for both the mraa and upm libraries to work with version 2.0 instead of 1.5:

echo "src mraa-upm http://iotdk.intel.com/repos/2.0/intelgalactic" > /etc/opkg/mraa-upm.conf

Now, run the following command to check the repository configuration for both the mraa and upm libraries and you will notice that 1.5 has been replaced by 2.0 in the output.

cat /etc/opkg/mraa-upm.conf

You should see the results shown in the next line:

src mraa-upm http://iotdk.intel.com/repos/2.0/intelgalactic

We will use the opkg utility to update packages from the previously configured repository located on the Internet. Run the following command to make the opkg utility update the list of available packages after we changed the configuration of the repositories for both the mraa and upm libraries.

opkg update

The previous command will generate the following output that indicates the list of available packages that have been updated. Notice that the last lines of the output indicate that the command has been downloaded from http://iotdk.intel.com/repos/2.0/intelgalactic/Packages and saved the available packages in /var/lib/opkg/mraa-upm.

Downloading http://iotdk.intel.com/repos/1.5/iotdk/all/Packages.
Updated list of available packages in /var/lib/opkg/iotdk-all.
Downloading http://iotdk.intel.com/repos/1.5/iotdk/i586/Packages.
Updated list of available packages in /var/lib/opkg/iotdk-i586.
Downloading http://iotdk.intel.com/repos/1.5/iotdk/quark/Packages.
Updated list of available packages in /var/lib/opkg/iotdk-quark.
Downloading http://iotdk.intel.com/repos/1.5/iotdk/x86/Packages.
Updated list of available packages in /var/lib/opkg/iotdk-x86.
Downloading http://iotdk.intel.com/repos/2.0/intelgalactic/Packages.
Updated list of available packages in /var/lib/opkg/mraa-upm.

Run the following command to check the versions for both the mraa and upm libraries stored in /var/lib/opkg/mraa-upm.

cat /var/lib/opkg/mraa-upm

The following lines show the results. Notice that the version numbers might vary because both the mraa and upm libraries are very active projects and they are frequently updated. Thus, the version numbers might be higher when you run the previous command.

Package: mraa
Version: 0.9.0
Provides: mraa-dev, mraa-dbg, mraa-doc
Replaces: mraa-dev, mraa-dbg, mraa-doc, libmraa, libmraa-dev, libmraa-doc
Conflicts: mraa-dev, mraa-dbg, mraa-doc
Section: libs
Architecture: i586
Maintainer: Intel IoT-Devkit
MD5Sum: b92167f26a0dc0dba4d485b7bedcfb47
Size: 442236
Filename: mraa_0.9.0_i586.ipk
Source: https://github.com/intel-iot-devkit/mraa
Description:  mraa built using CMake
Priority: optional


Package: upm
Version: 0.4.1
Depends: mraa (>= 0.8.0)
Provides: upm-dev, upm-dbg, upm-doc
Replaces: upm-dev, upm-dbg, upm-doc
Conflicts: upm-dev, upm-dbg, upm-doc
Section: libs
Architecture: i586
Maintainer: Intel IoT-Devkit
MD5Sum: 13a0782e478f2ed1e65b33249be41424
Size: 16487850
Filename: upm_0.4.1_i586.ipk
Source: https://github.com/intel-iot-devkit/upm
Description:  upm built using CMake
Priority: optional

In this case, we have mraa version 0.9.0 and upm version 0.4.1. The version numbers are higher than the initially installed ones. We definitely want to upgrade mraa 0.7.2-r0 to 0.9.0 and upm 0.3.1-r0 to 0.4.1. As shown in the preceding lines, upm depends on mraa version 0.8.0 or greater, and therefore, we will upgrade mraa first.

Run the following command to install the latest available version of the mraa library:

opkg install mraa

The following lines show the results:

Upgrading mraa from 0.7.2-r0 to 0.9.0 on root.
Downloading http://iotdk.intel.com/repos/2.0/intelgalactic/mraa_0.9.0_i586.ipk.
Removing package mraa-dev from root...
Removing package mraa-doc from root...
Removing obsolete file /usr/lib/libmraa.so.0.7.2.
Removing obsolete file /usr/bin/mraa-gpio.
Configuring mraa.

Run the following command to install the latest available version of the upm library:

opkg install upm

The following lines show some lines with the results and the final line. Note that the package installation removes an important number of obsolete files:

Upgrading upm from 0.3.1-r0 to 0.4.1 on root.
Downloading http://iotdk.intel.com/repos/2.0/intelgalactic/upm_0.4.1_i586.ipk.
Removing package upm-dev from root...
Removing obsolete file /usr/lib/libupm-wt5001.so.0.3.1.
Removing obsolete file /usr/lib/libupm-adc121c021.so.0.3.1.
Removing obsolete file /usr/lib/libupm-joystick12.so.0.3.1.
Removing obsolete file /usr/lib/libupm-grove.so.0.3.1.
Removing obsolete file /usr/lib/libupm-tm1637.so.0.3.1.
…
Removing obsolete file /usr/lib/libupm-groveloudness.so.0.3.1.
Configuring upm.

Now, run the following command to check the installed mraa version:

opkg info mraa

The following lines show the output with the version and dependencies for the mraa package. The first lines show that mraa version 0.7.2-r0 is not installed anymore and the highlighted lines show that mraa version 0.9.0 is installed.

Package: mraa
Version: 0.7.2-r0
Depends: libgcc1 (>= 4.9.1), python-core, libpython2.7-1.0 (>= 2.7.3), libstdc++6 (>= 4.9.1), libc6 (>= 2.20)
Status: unknown ok not-installed
Section: libs
Architecture: i586
Maintainer: Intel IoT Devkit team <meta-intel@yoctoproject.org>
MD5Sum: b877585652e4bc34c5d8b0497de04c4f
Size: 462242
Filename: mraa_0.7.2-r0_i586.ipk
Source: git://github.com/intel-iot-devkit/mraa.git;protocol=git;rev=299bf5ab27191e60ea0280627da2161525fc8990
Description: Low Level Skeleton Library for Communication on Intel platforms  Low
 Level Skeleton Library for Communication on Intel platforms.

Package: mraa
Version: 0.9.0
Provides: mraa-dev, mraa-dbg, mraa-doc
Replaces: mraa-dev, mraa-dbg, mraa-doc, libmraa, libmraa-dev, libmraa-doc
Conflicts: mraa-dev, mraa-dbg, mraa-doc
Status: install user installed
Section: libs
Architecture: i586
Maintainer: Intel IoT-Devkit
MD5Sum: b92167f26a0dc0dba4d485b7bedcfb47
Size: 442236
Filename: mraa_0.9.0_i586.ipk
Source: https://github.com/intel-iot-devkit/mraa
Description: mraa built using CMake
Installed-Time: 1452800349

Run the following command to check the installed upm version:

opkg info upm

The following lines give the output with the version and dependencies for the upm package. The first lines display that upm version 0.3.1-r0 is not installed anymore and the highlighted lines show that upm version 0.4.1 is installed.

Package: upm
Version: 0.3.1-r0
Depends: libgcc1 (>= 4.9.1), libpython2.7-1.0 (>= 2.7.3), libc6 (>= 2.20), python-core, libstdc++6 (>= 4.9.1), mraa (>= 0.7.2)
Status: unknown ok not-installed
Section: libs
Architecture: i586
Maintainer: Intel IoT Devkit team <meta-intel@yoctoproject.org>
MD5Sum: 9c38c6a23db13fbeb8c687336d473200
Size: 10344826
Filename: upm_0.3.1-r0_i586.ipk
Source: git://github.com/intel-iot-devkit/upm.git;protocol=git;rev=3d453811fb7760e14da1a3461e05bfba1893c2bd file://0001-adafruitms1438-CMakeLists.txt-stop-RPATH-being-added.patch
Description: Sensor/Actuator repository for Mraa  Sensor/Actuator repository for Mraa.

Package: upm
Version: 0.4.1
Depends: mraa (>= 0.8.0)
Provides: upm-dev, upm-dbg, upm-doc
Replaces: upm-dev, upm-dbg, upm-doc
Conflicts: upm-dev, upm-dbg, upm-doc
Status: install user installed
Section: libs
Architecture: i586
Maintainer: Intel IoT-Devkit
MD5Sum: 13a0782e478f2ed1e65b33249be41424
Size: 16487850
Filename: upm_0.4.1_i586.ipk
Source: https://github.com/intel-iot-devkit/upm
Description: upm built using CMake
Installed-Time: 1452800568

Now, we have the latest versions of both the mraa and upm libraries installed and we will be able to use them from any Python program.