How to Run Maven Based Projects on a Remote Raspberry Pi Using NetBeans Part 1 of 2.

In the course of writing a series of articles entitled ‘IoT without the Breadboard’ I came across an issue that I felt could be fun to resolve. The issue is how to copy to and execute on a Raspberry Pi a compiled Java application. As a NetBeans Dream team member my IDE of choice is NetBeans.

If you are already a NetBeans user playing with Pi systems, you already know it can be done if you create a native NetBeans project. My issue derives from the fact that I use Maven rather than NetBeans or any other IDE’s internal build system.

NetBeans has the capability to use an internal ssh client to copy a file to a remote Linux based system, such as a Pi, execute the code, and display its output in the NetBeans console window. This really cool standard feature is not available if the project is using the Maven build system.

So why don’t I just ditch Maven? As a teacher I believe that it is important for students to learn how to build projects independent from the IDE. When I teach Java I want my students to submit code that is IDE agnostic. My Raspberry Pi project is personal but I felt that it would be hypocritical of me if I chose not to use Maven when I rant and whine at programmers who don’t use it.

There are two solutions to getting code from a Windows PC to a Linux PC. The solutions should work with any Linux based system and any version of Windows.

Here is the first solution. The next solution will be in the second part of this series.

Solution #1 Multiple Tools

My real interest in coding but I realized I was going to have to be a DevOp to make this work. There are three tasks to accomplish. First I have to write and compile my Java code and for this I use, of course, NetBeans. Secondly, I need to copy the jar, war or ear file to my Raspberry Pi. For this I chose Filezilla, https://filezilla-project.org/ .

The third task is to execute the Java program from the command line. Here I was excited to find a program called xrdp, http://www.xrdp.org/, that runs on the Pi and allows me to use Microsoft Remote Desktop to access the Raspbian OS desktop on my Windows machine. To install xrdp you need to open a terminal window on your Pi that I assume you have currently connected to a keyboard, mouse and display. Here is a good article on installing xrdp, https://www.maketecheasier.com/enabling-remote-desktop-access-on-raspberry-pi/ . From this point forward you should rarely need to connect a keyboard, mouse and display to your Pi, use Remote Desktop instead.

With NetBeans I created a new Maven Java Application.

NBNewProject

When the project is created by NetBeans this is what the pom.xml file should look like. If you are using an older version of Java or NetBeans it may be slightly different.

Maven_pom

In the project I created a single class that simply writes to the console “Hello Universe.” when run.

HelloCode

Running the project now will output the message “Hello Universe”.

HelloUniverse

Now you need to transfer the jar file to the Raspberry Pi. Start up Filezilla. If you are unfamiliar with Filezilla then you can use other programs such as PuTTY or WinSCP. There are probably many others that will allow you perform a secure copy from Windows to a Linux system.

Using Filezilla, locate the folder ‘target’ in the MavenWinToPi project. In this folder you should find a jar file. If there is no jar file, go back to NetBeans and perform a Clean and Build on the project.

Now connect to your Raspberry Pi. Here is the Filezilla display after locating the target folder and then configuring the connection. You will need to know the IP number of the Pi. I use my router’s control panel to see what internal (192.168.x.x) number it has been given.

filezilla

Take note of the file name of the jar file, in my case its ‘MavenWinToPi-1.0-SNAPSHOT.jar’. Click on connect and you should see your home directory on the Pi.

If this is the first time that you are using this program, you will be asked to accept the unknown ssh key from the Pi. If the IP number of your Pi changes, you will also be asked to verify the key again.

hostkey

Check off the ‘Always trust . . .’ box otherwise you will have to approve the host key every time you connect. Assuming that all has gone well you should see your Pi on the right side of the Filezilla window.

filezillaconnect

 

Now you need to transfer the jar file. Right mouse click on the file and select upload.

upload

Your jar file should be transferred to the Pi.

upload_success

 

Now its time to execute the code. On Windows run the Remote Desktop Connection and configure it to connect to your Pi. You can let windows hold the user name and password or have it ask you for them for every connection. I let Remote Desktop hold my credentials.

rdp

By default Remote Desktop will open full screen when it connects. I set the Display option to 1024 x 768 so that the Pi is running in a window I can move around. If all has gone well you should see:

xrdp_desktop

Open a terminal window on the Pi. You should now be able to execute your program at the command line by entering:

java -cp MavenWinToPi-1.0-SNAPSHOT.jar com.kenfogel.mavenwintopi.MavenWinToPi

execution

You should see Hello Universe.

This workflow for Java development for a Raspberry Pi works well and you don’t need to read any further. It is your only option if the program is interactive in the console or has a Swing or JavaFX GUI. If you are interested in automating this further so that everything happens in NetBeans, read the second article in this series.

 

 

 

IoT without the Breadboard Part 2

      No Comments on IoT without the Breadboard Part 2

In 2012 Seeed Studios of China introduced the Grove System of modules for the burgeoning IoT sector. Seeed used the classic model of simplification, Lego. In the world of Lego you just push bricks together. Seed developed the Grove System to be that easy to use. Of course nothing is quite that simple, not even Lego. None the less, the Grove system was made for breadboard impaired developers like me.

When initially introduced it was and still remains agnostic towards whatever processor you are working with. As long as your processor system, such as either an Intel Edison or a Raspberry Pi, has GPIO pins you can use the Grove. The individual devices are mounted on a circuit board with all the necessary support components. A 4-pin connector allows you to plug the module into the processor’s board.

The Grove modules fall into specific categories. These are:

  • Environmental Monitoring modules
  • Motion Sensing modules
  • User Interface modules
  • Physical Monitoring modules
  • Logic Gate modules
  • Power modules

Here are some of the modules.

IoT-Sensors-Market

Figure 1 For a complete list of what is available go to http://www.seeedstudio.com/wiki/Grove_System

The second part of the Grove system is the shield. A shield is what is properly called a daughter board. When the Arduino system was introduced they repurposed the word shield to mean daughter board. There are some unhappy engineers as a result of this because the term shield is supposed to mean “a conductive layer that prevents capacitive coupling to whatever you are trying to protect with the shield”. I also read that the Arduino folks also decided to rename programming as sketching. Here is what a basic Grove system looks like as sold by Seeed Industries.

Grove Starter Kit V3

Figure 2 From https://www.seeedstudio.com/Grove-Starter-Kit-for-Arduino-p-1855.html

You can see the shield between the LCD Display and the cables. The shield in this kit is designed for the Arduino system board. This particular kit sells for $49 USD.

In a collaborative project between Seeed Studios and the US firm Dexter Industries a shield for the Raspberry Pi was developed. The most recent version of this shield is called the GrovePi+ and it will connect to all models of the Raspberry Pi. The shield makes use of the same processor as found on an Arduino board.

grovepi2

Figure 3 GrovePi+ mounted on a Raspberry Pi

The GrovePi+ has a female pin connector that lines up with the GPIO pins on the Pi. The board even includes a slit to allow using the dedicated camera connector on the Pi that the shield is covering.

With the shield in place you can easily connect a wide range of moduleseffortlessly to your platform of choice such as the Raspberry Pi. The shield can be purchased separately or as part of a kit. Dexter and Seeed sell a kit with the shield and 12 modules.

GrovePi-Base-Kit-800x800

Figure 4 The Basic GrovePi+ Kit

Dexter began as a maker of Lego Mindstorms add-ons before they added the Raspberry Pi to their lineup. They market their products to the education field and they have a 3-month loaner program for educators. A kit containing the basic kit and a Raspberry Pi 2 is what Dexter was kind enough to loan to me under this program.

GrovePi-Starter-Kit-800x800

Figure 5 GrovePi+ Starter Kit for the Raspberry Pi.

With the hardware in place the next thing I needed was a Java library that I could use to interact with the Grove modules. The Dexter web site lists only Scratch, Python, NodeJS, Go, C and C# as supported languages. The next article will look at a mashup between Payara Micro and the GrovePi+ in Java.

Bibliography: