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 at:

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 Step 2. Using the BeagleBone User LEDs

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

Finished

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.

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.

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):

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

fi

fi

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 192.168.7.1

/usr/sbin/ntpdate -b -s -u ie.pool.ntp.org

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)

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

BasicLEDExample.class

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

RPi 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) 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 192.168.1.1) 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 see the lecture video in 2017/18 Week 10 as this is the way that I connect to the RPi.

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 https://github.com/derekmolloy/ee402.git

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 README.md scripts testjava

...

RPi 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 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:

/sys/class/thermal/thermal_zone0/temp

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

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

35780

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:

/sys/class/hwmon/hwmon0/device/temp1_input

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

The Assignment Itself!

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 Server

In this application the desktop PC is the graphical temperature server. It runs on a server port on the PC and the BBB/RPi boards connect to it.

When a client application executes on the BBB/RPi it will connect to the server that is running on the PC and transfer temperature data (or CPU utilization data) to the server. The Server will then display the data in a Graphical User Interface (GUI).

The PC Temperature Server should have the following features:

It should have a GUI that is built using Swing.

The Temperature Server GUI should be able to connect to multiple clients simultaneously. (Please note that you can run multiple clients on a single RPi/BBB for testing purposes).

The server application controls the sampling rate, and the GUI should allow the user to change this rate. (You can use a single rate for all connected clients.)

The GUI should provide a graph display of historical readings (the last 20 readings) in scrolling graphical form. Donotuse 3rd party graphing APIs or source code.

The graphical display should display an individual graph of the raw data coming from each of the clients on the same plot. You should be able to turn on/off each individual plot.

The graphical display should include a moving average temperature and should plot a line against the minimum and maximum temperature (i.e., a single moving average and min and max of all sensor values)

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,

The client/server pair should send and receive object of a class of your own design, which describes the reading. It should include the following properties: temperature, device identifier, date and time of sample, current sample number, and any other properties that you deem necessary.

For the purpose of GUI design, you can limit the max number of clients to five.

The RPi/BBB Embedded Linux Temperature Client

In this application the client application should run on the embedded device (Beaglebone/RPi etc.) The client should have the following features:

On execution it should connect to the server socket port (e.g., 5000, 5001) on the PC, which is listening forever for connections.

The client 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 IP address, port number and client name as command-line arguments.

The client application should not have a GUI.

The client application should read the CPU core temperature/frequency and send it to the server when requested.

The client should flash an onboard LED each time it sends a reading to a server. 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 Moodle.