Payara Micro and GrovePi+ Mashup
In this project, I have combined two other projects. These are Steve Millidge’s, of Payara, proof of concept Java EE application that highlighted the use of the Payara Micro server on the Raspberry Pi. You can see the original article at http://blog.payara.fish/piyara-payara-micro-on-raspberry-pi-demo. The other project is Eduardo Moranchel’s IoTDevices project that presents how to work with the GrovePi with Java. You can find it at https://github.com/emoranchel/IoTDevices.
The Payara project presents a simulated stock ticker where the numbers are presented on a line graph. The IoTDevices project presents code to communicate with GrovePi modules using either the JavaME dio library or the Pi4J library. The mashup I created simply replaced the random number generator in the Payara project with readings of the DHT-11 temperature sensor using the IoTDevices code.
The changes in the two projects that I made were quite minor. For the IoTDevices, I stripped away the JavaME dio code and removed the samples. For the Payara code, all I changed was a few lines to read the sensor. For both projects, I did upgrade their pom.xml files to how I expect my students to write these files.
Here is the hardware you will need to run this project:
2x Raspberry Pi version 2 or 3. Version 1 might work but I did not test it.
1x GrovePi+. This is a Raspberry Pi shield or daughter board that interfaces with the Grove modules
1x Grove Temp&Humi Sensor
1x Grove – LCD RGB Backlight v2.0
I recommend purchasing the GrovePi+ Starter Kit for Raspberry Pi that includes a number of modules including the two for this project but not a Raspberry Pi.
Raspberry Pi Software
Here is the software you will need for the Raspberry Pi.
Raspbian OS for the Pi (https://www.raspberrypi.org/downloads/raspbian/)
You only need the standard distribution, currently called Jessie, that already comes with Java 1.8. All other required libraries will be packaged in the application.
Payara Micro (http://www.payara.fish/payara_micro)
This is a single jar that you will need on each Raspberry Pi. You can download it directly on the Pi or download it to your dev system and copy it to the two Pi systems. Take note of its full name as you will need this in your WinSCP script. For simplicity, I placed this jar in my home folder on both Pi systems.
Windows Development System Software
Here is the software you will need for your development system. I use Windows but the project will work from any Linux distro or Mac OSX system.
The IoTDevices project uses Java 1.8 features such as lambdas.
While you could use pretty much any IDE, I feel strongly that NetBeans is the best choice.
This is a windows application that allows you to connect to, upload to and execute on a remote Linux system. I experimented with some other options but I found WinSCP to be the best. It will run a script that Linux or Mac users should be able to turn into a shell script for their systems.
Raspberry Pi Setup
On one of the Pi systems attach the GrovePi+ shield. To the GrovePi+ attach the Temp&Humi Sensor and the LCD RGB Backlight module. The second Pi does not use a shield.
For my code, I am using the default user and password for the Pi systems. You will need to know the IP number of each Pi. I use Ethernet rather than wireless, but that should not make any difference. I assume that you have started up and verified the operation of each Pi. Either download on the Pi or copy to it the Payara Micro jar file.
Windows Dev System Setup
Verify that you have Java 1.8, download and install WinSCP, and download and install NetBeans. Run NetBeans and use its integrated Git support to clone this project. You will be confronted with many errors but you can ignore them as they will be resolved as you build each project.
Making It Work
Clone the project from https://gitlab.com/omniprof/PayaraMicroGrovePiMashup. The four individual projects that appear in NetBeans when you clone my project are:
Before you build anything you need to edit the two WinSCP scripts. In NetBeans switch to File view and you find them in each project’s root.
TemperatureTicker is from Steve Millidge and is an EJB timer. I modified it to read from the GrovePi+ rather than generate a random number and display this value on the LCD display. The value is also sent ourt over a web socket. Its WinSCP script is called tickertopi.txt and contains:
open "scp://pi:firstname.lastname@example.org" -hostkey="*" put target\TemperatureTicker.jar call java -jar payara-micro-22.214.171.124.jar --deploy TemperatureTicker.jar close exit
Change the IP number to that of the Pi with the GrovePi+ shield. Change the username and password if necessary. Change the version number of the payara-micro jar file to match whatever you downloaded.
open "scp://pi:email@example.com" -hostkey="*" put target\TemperatureWeb.war call java -jar payara-micro-126.96.36.199.jar --deploy TemperatureWeb.war close exit
Change the IP number to that of the Pi without the GrovePi+ shield. Change the username and password if necessary. Change the version number of the payara-micro jar file to match whatever you downloaded.
All projects are Maven-based so all you need is a working Internet connection on your development PC. You do not use the Run command. The first project that you will Clean and Build is GrovePi-spec. next, Clean and Build GrovePi-pi4j. They must be built in this order as GrovePi-pi4j depends on GrovePi-spec.
At this point, both Raspberry Pi systems should be up and running. Now you can Clean and Build TemperatureTicker and TemperatureWeb. The order is not important as long as they are built after the GrovePi projects. The TemperatureTicker jar file will be large because it is packaged with all necessary libraries. This is why you don’t require a customized version of the Raspbian OS.
Seeing the Results
Assuming that the build did not generate any errors and the WinSCP scripts ran without errors you will need to open a browser on your PC.
Change the IP number to match the Pi without the GrovePi+ shield.
I held the sensor and breathed on it to change the readings. Otherwise, it was going to be 22 C constantly.
If all goes well it will look like:
Stopping the Payara Server
You will need a remote terminal for each Raspberry Pi to kill each instance of the server. I have not learned how to do this from within NetBeans.
There you have it, the Payara/GrovePi+ mashup.
This coming January 2017, Dawson College will host Montreal’s first NetBeans Day. Unlike large commercial conferences, NetBeans Day is a community organized event. It is loosely based around a central theme of NetBeans that supports a very wide range of languages, frameworks, and techniques. The event is free to attend (with refreshments) and targeted at professional software developers, students, and anyone with a general curiosity. Check it out!