48 lines
3.7 KiB
Markdown
48 lines
3.7 KiB
Markdown
# 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_
|
|
1. Select _Actions_ --> _Build project_
|
|
1. Click on _Add_ button and select _Skip Tests_
|
|
1. Click _OK_ - (this forces Netbeans to generate the file _nbactions.xml_ in the project folder)
|
|
1. Open the file _nbactions.xml_ and _nbactions-template.xml_
|
|
1. 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_ |