Assignments‎ > ‎

Assignment 2 - 2016/17

posted 17 Nov 2014, 07:30 by Derek Molloy   [ updated 15 Nov 2017, 03:25 ]

Introduction

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: 

https://loop.dcu.ie/mod/forum/view.php?id=47984

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 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: http://beagleboard.org/getting-started

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

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

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

root@beaglebone:~# /usr/sbin/ntpdate -b -s -u ie.pool.ntp.org
root@beaglebone:~# date
Mon Nov 17 16:13:37 GMT 2014

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 192.168.7.1
/usr/sbin/ntpdate -b -s -u ie.pool.ntp.org

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

root@beaglebone:~# cd ~/
root@beaglebone:~# 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.

root@beaglebone:~# cd ee402/

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

BeagleBone Step 2. Using the BeagleBone User LEDs

Follow the guide at:

https://sites.google.com/site/derekmolloyee402/home/embedded-linux/flashing-the-leds-using-c

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.

BeagleBone Step 3. Installing Java on the BeagleBone

https://sites.google.com/site/derekmolloyee402/home/embedded-linux/flashing-the-leds-using-java

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: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 

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
ejdk1.8.0_06
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
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/java/ejdk1.8.0_06/linux_arm_vfp_hflt/jre/bin
root@beaglebone:/usr/java# echo $JAVA_HOME
/usr/java/ejdk1.8.0_06/linux_arm_vfp_hflt/jre

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
  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
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!

The  Embedded Linux Client/Server Temperature Logging 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 a temperature server that is running on a port on the BBB/RPi. 

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

The PC Temperature Client should have the following features:

  • It should have a GUI that is built using Swing.
  • The Temperature Client GUI should be able to connect to multiple servers simultaneously. (Please note that you can run multiple servers on a single RPi/BBB for testing purposes).
  • The client 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 servers.)
  • 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 display an individual graph of the raw data coming from each of the sensors 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 client can connect to multiple servers at the same time so design your client/server appropriately. For example,
  • Structure your code appropriately to allow the client to hold multiple connections open.
  • 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 servers to five.
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:
  • It should run on a server socket port (e.g., 5000, 5001), forever. (Do not use a port lower than 1024 or you could have problems.)
  • 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 as command-line arguments. 
  • The server application should not have a GUI. 
  • The server application should read the CPU core temperature/frequency and send it to the client when requested. 
  • 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:

http://ee402.eeng.dcu.ie/introduction/chapter-8---threads-and-networking/8-4-a-multi-threaded-client-server-application

Marking

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.

The assignment is due for Friday the 8th of December, 2017 

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

Submit the assignment to: https://loop.dcu.ie/mod/assign/view.php?id=76090

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!

Derek.

Comments