Assignments‎ > ‎

Assignment 2 - 2019/20

posted 17 Nov 2014, 07:30 by Derek Molloy   [ updated 25 Nov 2019, 01:38 ]


In this assignment you are going to develop a Java client/server application that sends and receives temperature data to/from a PC and an embedded Linux device such as the BeagleBone Black (BBB) or Raspberry Pi (RPi). 

This assignment requires a fair amount of configuration before you begin the assignment. Please send questions on problems that you are having to the mailing list on the module Loop page.

The assignment is worth 15% of your overall mark in the module and therefore represents a significant body of work. The assignment begins with steps to set up your BBB/RPi to access the Internet, to flash the user LEDs using C, to install Java and finally to flash the user LEDs using Java. 

Good luck! Derek.

Background Setup and Configuration (BBB and RPi)

Follow the steps in this guide to place the BeagleBone Black (BBB) or Raspberry Pi (RPi) on the Internet so that you can clone the repository of source code on the Github site. Please note that access to the Internet from your board is useful, but it is not vital -- you can transfer files from your PC to the boards if necessary.

BeagleBone Steps (See below for RPi steps)

BeagleBone Only Step 1. BeagleBone Network Configuration and Source Code

For the BBB, please read: 

Please note that for Windows 10 you will have to download the BeagleBone drivers from:

If you have completed this guide successfully, you should be able to perform the following tasks:

root@beaglebone:~# ping
PING ( 56(84) bytes of data.
64 bytes from icmp_req=1 ttl=50 time=14.0 ms
64 bytes from icmp_req=2 ttl=50 time=13.8 ms

root@beaglebone:~# ping
PING ( 56(84) bytes of data.
64 bytes from ( icmp_req=1 ttl=51 time=58.2 ms
64 bytes from ( icmp_req=2 ttl=51 time=58.2 ms

NOTE: If you are using Internet-over-USB often on the BBB then you can edit your ~/.profile file using nano and add the following lines to the bottom of the file:
/sbin/route add default gw
/usr/sbin/ntpdate -b -s -u

Next, you should clone the EE402 source code repository, as follows:

root@beaglebone:~# cd ~/
root@beaglebone:~# git clone
Cloning into 'ee402'...
remote: Counting objects: 276, done.
remote: Total 276 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (276/276), 726.80 KiB | 248 KiB/s, done.
Resolving deltas: 100% (96/96), done.

root@beaglebone:~# cd ee402/

root@beaglebone:~/ee402# ls
LEDcpp   LICENSE    notes_examples  testcpp   tmp36
LEDjava  scripts         testjava

BeagleBone Only Step 2. Using the BeagleBone User LEDs

Follow the guide at:

You can access the code for this guide in the ee402 repository directory as follows:

root@beaglebone:~# cd ~/ee402
root@beaglebone:~/ee402# cd LEDcpp/
root@beaglebone:~/ee402/LEDcpp# ls -al
total 32
drwxr-xr-x  2 root root  4096 Nov 17 15:58 .
drwxr-xr-x 10 root root  4096 Nov 17 15:59 ..
-rwxr-xr-x  1 root root   124 Nov 17 15:58 build
-rwxr-xr-x  1 root root 13955 Nov 17 15:58 makeLED
-rw-r--r--  1 root root  1834 Nov 17 15:58 makeLED.cpp
root@beaglebone:~/ee402/LEDcpp# ./build
EE402 - Building the Test LED program on the Beaglebone Black
root@beaglebone:~/ee402/LEDcpp# ./makeLED flash
Starting the LED flash program
The LED Path is: /sys/class/leds/beaglebone:green:usr0
Finished the LED flash program
root@beaglebone:~/ee402/LEDcpp# ./makeLED off
Starting the LED flash program
The LED Path is: /sys/class/leds/beaglebone:green:usr0
Finished the LED flash program

There is a Java version of this code in ~/ee402/LEDjava but leave it alone for the moment. Please note that to control the RPi LEDs use the path /sys/class/leds/ and then the name of the led that you wish to control.

BeagleBone Only Step 3. Installing Java on the BeagleBone

Use the same steps in this video and download the Java SE 8 version for Linux ARM 32 Hard Float ABI, which is available at the link: 

Transfer the downloaded gz file to the BBB using the steps in the video to install Java 7 and the steps below this describe the settings required for Java 8.

Installing Java on the BeagleBone

Figure 1 illustrates my FTP screen for the latest version of Java and the commands I used to transfer the file to the BBB using psftp. The installation of PuTTY that is described in the video is the reason that I have a psftp command.

Now, test that the version of Java is working correctly:
root@beaglebone:/usr/java# ls
root@beaglebone:/usr/java# cd ejdk1.8.0_06/
root@beaglebone:/usr/java/ejdk1.8.0_06# cd linux_arm_vfp_hflt/
root@beaglebone:/usr/java/ejdk1.8.0_06/linux_arm_vfp_hflt# cd jre/bin
root@beaglebone:/usr/java/ejdk1.8.0_06/linux_arm_vfp_hflt/jre/bin# ls
java  keytool  pack200     rmid         servertool  unpack200
jjs   orbd     policytool  rmiregistry  tnameserv
root@beaglebone:/usr/java/ejdk1.8.0_06/linux_arm_vfp_hflt/jre/bin# ./java -version
java version "1.8.0_06"
Java(TM) SE Embedded Runtime Environment (build 1.8.0_06-b23)
Java HotSpot(TM) Embedded Client VM (build 25.6-b23, mixed mode)

Next, you need to add two environment variables so that the JRE can be found in your PATH and so that the JRE will be able to find the location of its installation files, JAVA_HOME, which contains the runtime libraries (note: you can use the Tab key to auto-complete):

root@beaglebone:# export PATH=$PATH:/usr/java/ejdk1.8.0_06/linux_arm_vfp_hflt/jre/bin
root@beaglebone:# export JAVA_HOME=/usr/java/ejdk1.8.0_06/linux_arm_vfp_hflt/jre
root@beaglebone:/usr/java# echo $PATH
root@beaglebone:/usr/java# echo $JAVA_HOME

root@beaglebone:/usr/java# java -version
java version "1.8.0_06"
Java(TM) SE Embedded Runtime Environment (build 1.8.0_06-b23)
Java HotSpot(TM) Embedded Client VM (build 25.6-b23, mixed mode)

Now, Java works from any point on your BBB using these environment variables. Add the lines:

export PATH=$PATH:/usr/java/ejdk1.8.0_06/linux_arm_vfp_hflt/jre/bin
export JAVA_HOME=/usr/java/ejdk1.8.0_06/linux_arm_vfp_hflt/jre

to your ~/.profile file by using nano. My ~/.profile file now looks like this (The source command allows you to reload the profile without having to log out and back in again):

root@beaglebone:~# cd ~/
root@beaglebone:~# nano .profile
root@beaglebone:~# more .profile
# ~/.profile: executed by Bourne-compatible login shells.
if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
mesg n
export PATH=$PATH:/usr/java/ejdk1.8.0_06/linux_arm_vfp_hflt/jre/bin
export JAVA_HOME=/usr/java/ejdk1.8.0_06/linux_arm_vfp_hflt/jre
/sbin/route add default gw
/usr/sbin/ntpdate -b -s -u

root@beaglebone:~# source ~/.profile
SIOCADDRT: File exists
root@beaglebone:~# java -version
java version "1.8.0_06"
Java(TM) SE Embedded Runtime Environment (build 1.8.0_06-b23)
Java HotSpot(TM) Embedded Client VM (build 25.6-b23, mixed mode)

BeagleBone Only Step 5. Testing the Java LED code on the BBB

If everything is working correctly, the Java LED example should now work from the code repository using the following steps (Please adapt the path for the RPi code):

root@beaglebone:~# cd ~/ee402/
root@beaglebone:~/ee402# cd LEDjava
root@beaglebone:~/ee402/LEDjava# ls
README  bin  src
root@beaglebone:~/ee402/LEDjava# cd bin
root@beaglebone:~/ee402/LEDjava/bin# cd ee402/
root@beaglebone:~/ee402/LEDjava/bin/ee402# ls
root@beaglebone:~/ee402/LEDjava/bin/ee402# cd ..
root@beaglebone:~/ee402/LEDjava/bin# java ee402.BasicLEDExample On
root@beaglebone:~/ee402/LEDjava/bin# java ee402.BasicLEDExample Off

Raspberry Pi Steps

RPi Only Step 1: Network Configuration and Source Code

You need a network patch cable in order to complete these steps and one of the following configurations:
  • A regular Ethernet switch (e.g., from Vodafone/Eir/Virgin) in your house. You can connect the RPi to the network port and then communicate to it using PuTTy. To identify the address use your network configuration interface (often at or use Zenmap ( to scan your network.
  • A laptop with two network adapters (typically laptops have wired and wireless adapters) and a network cable for data and a USB cable for power. 
Please note that if everything goes wrong, you can connect the RPi to a monitor and keyboard and boot it as a regular PC. You can then change the network settings using the GUI tools.

In the second case you need to share your wireless network adapter. Use START->Network and Sharing Center->Change Adapter Settings->Right-Click your Wi-Fi adapter -> Properties then click on the Sharing tab and check the two boxes "Allow other network users to connect..." and "Allow other network users to control...". Reboot the RPi.

At this point you should be able to:

pi@raspberrypi: $ sudo apt install git

pi@raspberrypi: $ cd ~/
pi@raspberrypi: $ git clone
Cloning into 'ee402'...
remote: Counting objects: 276, done.
remote: Total 276 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (276/276), 726.80 KiB | 248 KiB/s, done.
Resolving deltas: 100% (96/96), done.

pi@raspberrypi: $ cd ee402/

pi@raspberrypi: /ee402$ ls
LEDcpp   LICENSE    notes_examples  testcpp   tmp36
LEDjava  scripts         testjava

RPi Only Step 2. Using the User LED

You can access the code for this guide in the ee402 repository directory to see how the same thing is achieved on the BeagleBone (as above). Everything is the same except that the path is different. The path is /sys/class/leds/led0.

RPi Only Step 3. Installing Java

Java is installed on the default Raspbian image as standard.

Equipment for the Assignment.

No external sensors or wiring required. You can use the CPU temperature as the sensor input for this assignment. 

On the RPi the CPU temperature of the board is available at the location:


For example, to measure the CPU temperature you can read the value as follows:

pi@erpi ~ $ cat /sys/class/thermal/thermal_zone0/temp


The temperature is in degrees Celsius in milli-degrees. So, the temperature displayed here is 35.78 degrees Celsius. This temperature will change if you place or remove your finger from the CPU on the board.

On the BeagleBone the CPU temperature is available at: 


If this file entry is not available on your BeagleBone (this will happen if you have installed the latest image) then please use the CPU utilization instead of the CPU temperature for your assignment. You can do this by reading the first line of the file /proc/stat, which will look something like:
root@beaglebone:/sys# more /proc/stat
cpu 3270 0 2974 46877 268 0 68 0 0 0
You do have to do a small amount of coding to get the CPU utilization:
  • Discard the text cpu
  • sum all of the values on this line to get the total time
  • divide the fourth column, which is the idle time, by the total time to get the total idle time
  • 1 - idle time = busy time, which you can multiply by 100 to get it as a percentage
So, in my example above, the cpu utilization is: 12.31% (i.e., 100 x (1 - (46877 / (3270 + 2974 + 46877 + 268 + 68))))

The Assignment Itself! (BBB and RPi)

The  Embedded Linux Client/Server Temperature Graphing Service

In this assignment you should build a temperature sensor client/server application, where the embedded SBC reads the CPU core temperature from a file system entry and sends the data to a desktop computer client, which displays the data in a graphical form.

The PC Temperature Graphical Client

In this application the desktop PC is the graphical temperature client. It connects to the server port on the BBB/RPi boards. 

The server application executes on the BBB/RPi (as below) and it will provide temperature data (or CPU utilization data) to the client on the PC. The client will then display the data in a full-featured Graphical User Interface (GUI).

The PC Temperature client should have the following features:

  • It should have a GUI that is built using Swing.
  • The client application controls the sampling rate, and the GUI should allow the user to change this rate. Once set, the client should continue to obtain readings at this rate.
  • The GUI should provide a graph display of historical readings (the last 20 readings) in scrolling graphical form. Do not use 3rd party graphing APIs or source code.
  • The graphical display should include a moving average temperature and should plot a line against the minimum and maximum temperature.
  • Add two other features of your choice that you deem necessary. List them explicitly in your report.
Remember that the server can connect to multiple clients at the same time so design your client/server appropriately. For example,
  • Structure your code appropriately to allow the server to hold multiple connections open.
  • The client/server pair should send and receive objects of a class of your own design, which describes the reading. It should include the following properties: temperature, server device name, date and time of sample, current sample number, and any other properties that you deem necessary.
The RPi/BBB Embedded Linux Temperature Server

In this application the server application should run on the embedded device (Beaglebone/RPi etc.) The server should have the following features:
  • On execution it should open a server socket and wait for connections (e.g., 5000, 5001).
  • The server application should be executed manually at the Linux shell prompt and should run until killed by the user (i.e., keep it simple). You should specify the server port number and server name (any name is fine) as command-line arguments. 
  • The server application should not have a GUI. 
  • The server should be able to accept multiple connections (e.g., from multiple clients).
  • The server application should read the CPU core temperature/frequency when requested to do so by a client connection
  • The server should flash an onboard LED each time it sends a reading to a client. It should also display a message on the terminal window, which should include the current time and temperature/frequency value.

Code Provided!

I have provided you with template code and it MUST BE USED AS THE BASIS OF YOUR SOLUTION. Do *not* use RMI or any other Java Messaging Protocols, only use the template code provided for network communication. This code is available on the web page:


You will receive marks for implementing the features above. You will gain marks for making the server threaded, using Swing, for sending suitable messaging objects and for a working solution. You will gain marks for novel/extra features as outlined in the specification.

The assignment is worth 15% of your final result. The marks will be broken down into Design, Implementation/Coding and Documentation:

  • Design - the overall design and features of your system.
  • Implementation/Coding - is the implementation of your design and the quality of your code for both the interface/client and server. Most of the marks are allocated for this component.
  • Documentation - refers to the final report and the commented code. The final report should describe your design, features, interesting code segments, your messaging format etc. It should include screen grabs of your client/server in action (use ALT-PrtScr to grab a window view).

Submission Instructions

  • Submit an electronic report on your project, which should be in Word for Windows (.doc) or PDF (.pdf) format.
  • Your code should also be submitted with your assignment and it should be functional (comment out features that are crashing your application). Please provide instructions for the tutors on how to run your assignment. 
  • The report and code should be placed in one 7zip ( or rar format file and uploaded to the EE402 Assignment 2 Submission in Loop.

The assignment is due for Friday the 13th of December, 2019 

(i.e., the end of Week 12)

Submit the assignment to:

I will discuss the assignment in more detail over the next few weeks. But please start working through the Java notes, particularly in relation to the user interfaces sections.

Yes, it likely sounds difficult but you will get through it. I will be giving out additional hints and tips on how to complete this assignment during the coming lectures.

Good luck!