Assignments‎ > ‎

Assignment 2 - The Embedded Client/Server Temperature Sensor Service 2015/16

posted 17 Nov 2014, 07:30 by Derek Molloy   [ updated 17 Nov 2016, 02:08 ]

Introduction

In this assignment you are going to develop a Java client/server application that sends and receives temperature data from a PC and 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

Step 1. BeagleBone Network Configuration and Source Code

Follow the steps in this guide to place the BeagleBone Black on the Internet so that you can clone the repository of source code:

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

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.

Step 3. Installing Java on the BeagleBone

Please note that Java is installed by default on the RPi Raspbian image. To install Java 7 and to understand the steps required for Java 8, follow the guide at:

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.

Step 4. Installing Java 8 (Optional)

Figure 1. The FTP of the JDK to the BeagleBone

The next steps are described in the video, but applied to ejdk8 as follows:

root@beaglebone:~# ls ejdk*
ejdk-8u6-fcs-b23-linux-arm-vfp-hflt-12_jun_2014.gz
root@beaglebone:~# mkdir /usr/java
root@beaglebone:~# mv ejdk* /usr/java
root@beaglebone:~# cd /usr/java
root@beaglebone:/usr/java# ls
ejdk-8u6-fcs-b23-linux-arm-vfp-hflt-12_jun_2014.gz
root@beaglebone:/usr/java# tar xzf ejdk*
root@beaglebone:/usr/java# ls -l
total 119152
-rw-r--r-- 1 root root 122001608 Nov 17 16:41 ejdk-8u6-fcs-b23-linux-arm-vfp-hflt-12_jun_2014.gz
drwxr-xr-x 6 root root      4096 Nov 17 16:45 ejdk1.8.0_06

You can delete the .gz file if you need space, using rm *.gz

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

Equipment for the Assignment

Step 1. Wiring the Temperature Sensor

Do not connect this sensor to the RPi (please see the note below)

The Analog Devices TMP36 is a three-pin (TO-92 packaged) analogue sensor that measures temperature over the range of -40ºC to +125ºC, and is accurate to ±1ºC at 25ºC. It can be supplied with an input voltage using the BBB’s 3.3V, and it provides an output of 750mV at 25ºC. It has a linear output, whereby the output scale factor is 10 mV/ºC. This means that the minimum output voltage is 0.75 V - (65×0.01 V) = 0.1 V and the maximum output voltage is 0.75 V + (100×0.01 V) = 1.75 V. These voltage output levels are within the safe levels for the BBB ADC! The sensor output current will be between 0 µA and 50 µA, depending on the input impedance of the device to which it is attached. The high input impedance of the BBB ADC means that current supplied to the BBB is only a few nano amps, and therefore the sensor can be safely connected directly to the BBB AIN pins. The datasheet for the TMP35/36/37 is available at tiny.cc/ebb1001.


Figure 2. The temperature sensor and its connection to the BeagleBone Black. Please note that you should also connect the AGND pin to GND (e.g, P9_02) on the BBB.


Figure 3. The P9 header input/outputs on the BBB

A wiring configuration for the sensor to the BBB is identified in Figure 2 and the BBB P9 headers are identified in Figure 3 for your reference. 

Step 2. Using the C Source Code Example to read in the temperature

To read the current temperature on the AIN4 input use the following steps:

root@beaglebone:~# cd ~/ee402/tmp36/
root@beaglebone:~/ee402/tmp36# ls -l
total 20
-rwxr-xr-x 1 root root    35 Nov 17 16:17 build
-rwxr-xr-x 1 root root 10099 Nov 17 16:17 tmp36
-rw-r--r-- 1 root root  1305 Nov 17 16:16 tmp36.cpp
root@beaglebone:~/ee402/tmp36# ./build
root@beaglebone:~/ee402/tmp36# ./tmp36 4
Starting the TMP36 temperature sensor program
The ADC value is: 4
The temperatures is: -49.8242 degrees Celsius.

Oh oh... No, the ADC is not yet enabled on the BBB. Add the following entries to your ~/.profile file, so that they are permanently added:

    export SLOTS=/sys/devices/bone_capemgr.9/slots

root@beaglebone:~# nano ~/.profile
root@beaglebone:~# tail ~/.profile
...
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
export SLOTS=/sys/devices/bone_capemgr.9/slots

root@beaglebone:~# source ~/.profile
SIOCADDRT: File exists

Now, when you do the following, you can see the virtual capes that are present on the board:
root@beaglebone:~# cat $SLOTS
 0: 54:PF---
 1: 55:PF---
 2: 56:PF---
 3: 57:PF---
 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI

Now, to add the Analogue-Digital converter virtual cape:

root@beaglebone:~# echo BB-ADC > $SLOTS
root@beaglebone:~# cat $SLOTS
 0: 54:PF---
 1: 55:PF---
 2: 56:PF---
 3: 57:PF---
 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
 7: ff:P-O-L Override Board Name,00A0,Override Manuf,BB-ADC

The ADC virtual cape is now loaded and you can access it directly using the previous steps:

root@beaglebone:~# cd ~/ee402/tmp36/
root@beaglebone:~/ee402/tmp36# ls
build  tmp36  tmp36.cpp
root@beaglebone:~/ee402/tmp36# ./tmp36 4
Starting the TMP36 temperature sensor program
The ADC value is: 1338
The temperatures is: 8.79883 degrees Celsius.

Note on the RPi:

If you are using the RPi for this assignment then you should not try to connect this sensor to the board as the RPi has no ADC. Instead you should build your assignment to use the CPU temperature of the board. 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.

The Assignment Itself!

The  Embedded Linux Client/Server Temperature Sensor Service

In this assignment you should build a temperature sensor client/server application, where the embedded SBC reads the temperature from its analogue-to-digital converter or the CPU temperature from a sysfs entry and sends the data to a desktop computer, which displays the data in a graphical form.

The Temperature Server

In this application the embedded SBC is the server. It awaits a connection from a client application by listening to a specific port. When a desktop application connects and requests the temperature, the SBC should send it back. The Temperature Server should have the following features:

  • It should run on port (e.g. 5050), forever.
  • It should accept connections from multiple client applications, simultaneously.
  • It should read the current temperature from the BBB ADC as required.
  • The client should send back an object of a class of your own design, which describes the reading. It should include the following properties: temperature, date and time of sample, current sample number, and any other properties that you deem necessary.
  • The temperature server should display on the console each time a client connects. It should display the IP address of the client.
The Temperature Client

In this application the client application should run on the desktop machine. It should provide a graphical display of the readings it receives over time. The Temperature Client should have the following features:
  • It should have a GUI that is built using Swing.
  • It should have a pop-up dialog that allows you to set the server IP address and port number.
  • The GUI should provide a graph display of historical readings (e.g., the last 10 readings) in scrolling graphical form. Do not use 3rd party graphing APIs or source code.
  • The graphical display should illustrate a moving average temperature and a minimum and maximum temperature.
  • The GUI should request the temperature at a time step that is defined by the user. The request should be automatically sent when the time elapses (i.e., using threads). For example, the user may request sampling every 10 seconds or every 1 hr etc.
  • The time of each reading should be displayed on the graphical display.
  • Add two other features of your choice that you deem necessary. List them explicitly in your report.
Remember that multiple clients can connect to the server at the same time and that the client should also be sending/receiving objects of your user-defined class.

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 11th of December, 2015 

(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