The idea of this project is the creation of a web interface that allows, for example, monitoring of the CPU temperature.
To do this, we will use technologies such as HTML5 and nodejs. We will also have utilities available on the Raspberry Pi, such as vcgencmd.
In this project, we will use technical aspects, such as:
Websocket
Justgage
Nodejs
The idea here is not to explain these technologies, but to learn that they can be used in the Yocto Project.
The main project contains several files. To best present things, we'll only concentrate on two files:
server.js
: This is the file that will create our web server and send data to the HTML web page
index.html
: This is the page that will open the web browser to display the data received
The server.js
file creates a server on the listening port 3344
and will be responsible for creating a socket (rpi_temperature
) that contains the CPU temperature of Raspberry Pi. The socket function uses, among others, the vcgencmd
command (
https://github.com/raspberrypi/firmware/blob/master/opt/vc/bin/vcgencmd
), permitting us to monitor the CPU temperature, as shown here:
setInterval(function() { child = exec("vcgencmd measure_temp | awk -F:", function (error, stdout, stderr) { if (error !== null) { console.log('exec error: ' + error); } else { var date = new Date().getTime(); ...
Now that we have developed the main application, what remains for us is to integrate it with our Yocto RPI environment.
The first step consists of integrating the nodejs
package (located at meta-openembedded/meta-oe/recipes-devtools/nodejs
) with the Raspberry Pi environment. For this, we have to add the following line to raspberry-pack-image
:
# Base this image on core-image-minimal include recipes-core/images/core-image-minimal.bb DESCRIPTION = "Image for raspberry-pi" IMAGE_FEATURES += "ssh-server-dropbear splash" # Include modules in rootfs IMAGE_INSTALL += " \ kernel-modules \ gpio-packt \ i2c-tools \ spitools \ nunchuck \ v4l-utils \ nodejs \ "
We have now integrated nodejs
with our Poky distro.
Now that we have a functional application (webserver-packt
), we can add it to our custom image, raspberry-pack-image
:
# Base this image on core-image-minimal include recipes-core/images/core-image-minimal.bb DESCRIPTION = "Image for raspberry-pi" IMAGE_FEATURES += "ssh-server-dropbear splash" # Include modules in rootfs IMAGE_INSTALL += " \ kernel-modules \ gpio-packt \ i2c-tools \ spitools \ nunchuck \ v4l-utils \ nodejs \ webserver-packt \ "
After doing this, we can start creating our image and then mount it on an SD card:
$ bitbake raspberry-packt-image
We looked at the basic idea of a server, and you should be able to improve it in order to make it as industrial as possible. One can easily imagine the following applications:
Monitoring the ADCs, present on a motherboard
Sending serial commands to a device via an HTML page (node-serial)
Monitor a CAN-bus devices ( https://github.com/sebi2k1/node-can )
The final project might look something like this:
In this chapter, we learned how to create a web interface, how to integrate it within an existing environment, and how to deploy it on the Raspberry Pi.
In the next chapter we will learn some basics about the Linux kernel and how to configure the kernel to support various LCD touchscreens. Further on the chapter explains how to setup a Yocto project to run graphical applications or a window system, on a Raspberry Pi using a LCD touchscreen.