Outils pour utilisateurs

Outils du site


issue116:tuto2

Ceci est une ancienne révision du document !


In this series of articles, I will be building a text-based application with Free Pascal, using its text-based interface for user interaction. This will be combined with other, more modern, technologies such as database access using SQL and Web access with HTTP. The final aim of the project is to demonstrate how Pascal can be used to build a modern application, while avoiding the overhead associated with a graphical interface that uses a widget set such as GTK or Qt. In the previous part of this series, we put our complete application together using Free Vision for the user interface, Sqlite to create a local database, and CURL and XML to retrieve fresh data from an RSS feed from the Web to update our database. In this part, we will see various ways in which our application can run on a Raspberry Pi.

Dans cette série d'articles, je construirai une application en mode texte avec Free Pascal, en utilisant son interface en mode texte pour l'interaction avec l'utilisateur. Ceci sera combiné avec d'autres technologies, plus modernes, telles que l'accès à une base de données en utilisant SQL et l'accès au Web avec HTTP. Le but final du projet est de démontrer comment Pascal peut être utilisé pour construire une application moderne, tout en évitant le surpoids associé à une interface graphique qui utilise un jeu de gadgets comme GTK ou Qt.

Dans l'article précédent de la série, nous avons assemblé un application complète en utilisant Fre Vision pour l'interface utilisateur, QSLite pour créer une base de données locale, et CURL et XML pour rafraîchir les données à partir d'un lien RSS sur le Web et mettre à jour notre base de données. Dans ce numéro, nous verront plusieurs façons de faire tourner notre application sur un Raspberry Pi.

The Raspberry Pi family and Ubuntu The Raspberry Pi family of single-board computers is gaining popularity as an inexpensive means of learning more about computers, about electronics, and how to interface these two worlds together. However, they are actually complete computers in their own right, and with processors starting at a 32-bit, and running at a clock speed of 600 MHz upwards, they can arguably outperform any type of Personal Computer sold up to and including a 1997 Intel Pentium II. So, while having substantially less computational power than a modern desktop, they are still well capable of running an interface such as Free Vision – that was originally designed for computers equipped with the Intel 8086 and 80386 processors. The Raspberry Pi family is actually based on two different series of processors: the RPi versions A, B, and B+ have a Broadcom System-on-a-Chip (SOC) based on the ARMv6 architecture, while the RPi 2 and RPi 3 models are based on the ARMv7 architecture. This has implications for the operating system, since Ubuntu is available only for the ARMv7 architecture. So, for models RPi 2 and 3, we can download an Ubuntu 16.04 Server image from the official downloads section http://cdimage.ubuntu.com/releases/16.04/release/; at the time of writing the latest version was file ubuntu-16.04.1-preinstalled-server-armhf+raspi2.img.xz. This will give us access to the apt command and repositories, and we can install the latest Free Pascal version 3.0 packages as described for a normal desktop or laptop computer.

On the other hand, for the earlier ARMv6 versions of the RPi, we will need to get a Debian (Raspbian) image. Raspbian is a very acceptable alternative for Ubuntu Server, with only two major differences. The first one is the default user (login name: pi / password: raspberry) instead of Ubuntu’s (ubuntu/ubuntu). The second is that Debian’s repositories provide a slightly older version 2.6 of Free Pascal, which may present a few changes compared to version 3.0 - though nothing of consequence unless we use the graphical programming environment known as Lazarus. However, for both versions, we find clues to indicate that the main target of the Free Pascal project is, indeed, the Intel 32-bit architecture. A few of the libraries do not seem to have been carried over correctly to the ARM build. For our project, the only one of note is the XMLReader unit, so we will not be able to implement the RSS reader, while the other libraries (Free Vision, Database and CURL) seem to work correctly. This would no doubt be a minor inconvenience, but one to take into account and check – if the RPi is important for the reader’s plans.

In any case, it may be worth noting that programs compiled for the Intel 32- or 64-bit architectures will not work directly on an RPi, since the processor architecture is different and the machine language instruction sets are not compatible. This means a re-compile will be required. There are two techniques to do so. • The first is to install the Free Pascal compiler on the target RPi, then simply transfer our Pascal source code files over. They are recompiled on the RPi itself. Once done, the binary files (executable programs) may be copied over to and used directly on further RPis, since they are now binary-compatible with the ARM processor. • A second technique may be of interest when compiling applications for a very low-powered platform. Known as cross-compiling, the application is compiled on a more powerful computer such as a desktop, but specifying that output must be in the machine language of the second, low-powered architecture. This is often the case when designing apps destined for mobile phones and tablets. It is also possible to use our desktop to compile for the RPi, however the process is rather involved and documentation is scarce. Since the RPi has sufficient power to compile its own programs on-board without being too slow about it, I would suggest readers go this route and avoid delving into cross-compiling.

Using the Raspberry Pi directly All generations of the RPi have an output to connect a screen, analog composite video (yellow RCA jack) for versions A and B, and HDMI for all. There is also at least one USB port to connect an external keyboard, so nothing more is needed to use an RPi as a terminal to run a Free Vision program. The advantage of starting out from Ubuntu Server or an equivalent version of Debian is that the RPi comes up directly in text mode. The user simply logs in at the console, and starts up the application from the command line. Applications are quite responsive, even on an earlier B model. The RPi’s 512 MBytes of RAM should not be overtaxed, though this will depend on the actual data usage of our program - here, I was getting by on less than 90 MBytes for the operating system and the application altogether. On the other hand, the screen image over an analog feed, while working, is not too satisfactory. HDMI should be preferred if at all possible, even if we are working just with a text console. Depending on the foreseen use of the device, a user could even be automatically logged into the console, and the Free Vision application launched immediately upon login.

The Raspberry as an application server One of the nicer characteristics of Free Vision applications is that they work well over an SSH connection. Since our RPi already comes with an SSH server (both in Ubuntu Server and in Raspbian), it can immediately become an application server by simply installing our application’s binary file in the user’s home directory. One can then SSH over from one’s preferred computing device such as a computer or a tablet, and access the application. The low network overhead also helps application responsivity. The Raspberry Pi 3 allows us to go one step further, and avoid the need for a physical network connection through the use of the inbuilt WiFi adaptor. To set this up from the command line, we cannot depend on Network Manager that may be familiar to Ubuntu desktop users. Instead, we will need to install wpa-supplicant by hand - since we are all using WPA encryption by default on our networks, are we not? So: apt install wpasupplicant

Now, we need to create a hash of our WiFi’s WPA key: wpa_passphrase essid key where “essid” should be replaced with our network’s identification, and “key” with the WPA key. This command should reply with the required hash code: # wpa_passphrase myessid 12345678 network={ ssid=“myessid” #psk=“12345678” psk=407c7d4b572bf701afc06ddd6886cf33ce4f4f2e924d7f12cebe54628d74013e } We can now edit file /etc/network/interfaces to make the WiFi connection come up automatically, each time the RPi is started up. Add lines: auto wlan0 iface wlan0 inet dhcp wpa-ssid myessid wpa-psk 407c7d4b572bf701afc06ddd6886cf33ce4f4f2e924d7f12cebe54628d74013e naturally, replacing these values with your own as appropriate.

The final installation is rather minimal, consisting just of the RPi 3 itself, micro-SD card and a telephone charger for power. It can be placed in a suitable location, but please do make sure it has sufficient ventilation since the more powerful processor on this model can have issues with overheating. Such a setup would be sufficient for light database work, such as entering a sale or a bill of lading in a business, or data entry on the move for a scientific application. The data entered can then be transferred periodically to a larger computer and be integrated into its database. If large data handling capacities are needed, the RPi can still work as a front end, but the data repository will need to be moved to a separate database system and accessed over the network. In this part of our series on using Free Pascal with Ubuntu, we saw various ways in which our application can run on a Raspberry Pi, turning it either into a lightweight terminal or an equally lightweight application server. In the next part, we will focus on what makes the Raspberry Pi unique, and will build a Free Vision interface to make use of the General Purpose I/O ports on this small board computer.

issue116/tuto2.1484209760.txt.gz · Dernière modification : 2017/01/12 09:29 de d52fr