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

Invoking the Python interpreter

We have installed the most updated versions of the most important libraries we required to interact with the features included in the Intel Galileo Gen 2 board. Now, we can invoke the Python interpreter by typing the classic command:

python

Now, enter the following two lines of Python code:

import mraa
mraa.getVersion()

The Python interpreter will display the following output:

'v0.9.0'

We imported the mraa library and called the mraa.getVersion method to check whether Python is able to retrieve the installed version of the mraa library. The result of calling the method displays the version we installed for the mraa library, and therefore, we know that Python is going to work with the version we expect. Note that the Python code is running on the Yocto Linux on the Intel Galileo Gen 2 board.

Now, enter the following line to check whether the mraa library has successfully detected the board type:

mraa.getPlatformName()

The Python interpreter will display the following output:

'Intel Galileo Gen 2'

We called the mraa.getPlatformName method and the result of calling the method displays our board's name: Intel Galileo Gen 2. The following screenshot shows the results of calling the previous methods:

Invoking the Python interpreter

Now, open a Web browser in any computer or device connected to your LAN and enter the board's assigned IP address. For example, in case the IP address is 192.168.1.104, enter it as the URL to browse. The following screenshot shows the content you will see on your Web browser: It works!

Invoking the Python interpreter

The board is working as a Web server and it returns the contents of the /www/pages/index.html file to the Web browser request.