Skip to content

savageautomate/pi4j-remote-test

Repository files navigation

This is a PI4J v.2 maven project generated by the raspi-maven archetype.

You can freely modify it, adding your code. This project skeleton allows you to write the source code of your RPI programs using a destop computer (Linux or Windows) and your preferred IDE as development station, uploading the executable code to a remote RPI board, running and also debugging your code remotely.

  • The development station must be connected to your local network
  • A target RPI board must also be connected to the same network
  • You must configure the target RPI for a Headless connection with the development computer, i.e. the ssh server must be enabled in your RPI board and you must be able to connect with a ssh terminal.

The configuration data about the target RPI remote board is stored in the file platform/raspberry.properties. Actually the folder platform can contain as many target_name.properties as the RPI boards you may want to connect to. The maven property target.platform.name, defined in the pom.xml file, points to the right file in the platform folder. The default configuration file is platform/raspberry.properties and the target.platform.name = raspberry Each xxxx.properties file in the platform must be edited to describe the configuration data of a specific RPI board, as follow:

  • the target RPI IP address, the ssh connection port, the username and password
  • instead of using a password, if your RPI is configured to accept a ssh key, you can specify your ssh key.
  • the location of the java JRE / JDK on remote target, the folder where the program executables must be uploaded
  • ... other details described in the raspberry.properties

The project declares in the pom.xml the following maven/ant goals that you can execute with the command shown :

  • mvn clean : delete all compiled files from local and remote project
  • mvn install : builds the project, uploads the required jars to the remote target RPI board
  • mvn antrun:run@exec : runs the program on the remote target
  • mvn antrun:run@debug : runs a remote debugging session on the target RPI.

All the modern IDE programs have a mechanism to configure new GUI commands linked to a specific maven goal. See below for an example of such a GUI configuration of the Netbeans IDE.

To start a debugging session:

  • run the command mvn antrun:run@debug, the program on the remote target starts with JVM in debug mode, waiting for a debugger connection on the port configured for the target
  • in your IDE start the debugger setting the host IP = target IP and port = port configured in raspberry.properties You should be able to set remote breakpoints, execute step by step, examine variables on your remote program.

The pom.xml file adds the pi4j v.2.0 jar dependencies to the project classpath. You may want to update to the last version

If Netbeans is your preferred IDE you can use the file nbactions-template.xml to add to the Netbeans GUI the two actions "Remote run" and "Remote debug". Follow these simple steps:

  1. Right click the project in the NBs Projects window and select Properties
  2. Select Actions --> Build project
  3. Click on Add button and select Skip Tests
  4. Click OK - (this forces Netbeans to generate the file nbactions.xml in the project folder)
  5. Open the file nbactions.xml and nbactions-template.xml
  6. Select the two Action XML elements with name CUSTOM-Remote run and CUSTOM-Remote debug and copy them to the nbactions.xml. - Pay attention to preserve the correct XML syntax of file nbactions.xml, and save it.

Now right click the project in the NBs Projects window and select Run Maven: you should see the two new goals Remote run and Remote debug

When done, you can safely delete nbactions-template.xml

About

pi4j-remote-test

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages