Before starting, make sure that the RPi is powered up and connected to the network. You also need to figure out its IP address (e.g $ ifconfig on the RPi). Install NetBeans for C/C++On your computer, install the correct download bundle found here: https://netbeans.org/downloads/ Enable Remote Root LoginThe easiest way to let NetBeans run an application that needs access the IO pins is to let it log in remotely as root. There are ways to get around this by configuring the IO, but during development it is much easier to have full root access. By default the root account is disabled in Raspbian, so first we have to enable this by setting a password. On the RPi, use the following command: Code Block |
---|
language | bash |
---|
title | Set root password |
---|
| $ sudo passwd root |
You can now log on as "root" with the password you set. Now, edit the SSH configuration: Code Block |
---|
language | bash |
---|
title | Edit ssh config |
---|
| $ sudo nano /etc/ssh/sshd_config |
Search for PermitRootLogin and change it to yes (the default without-password does not work). Code Block |
---|
language | text |
---|
firstline | 13 |
---|
title | /etc/ssh/sshd_config |
---|
linenumbers | true |
---|
| # Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes |
Save and exit, before rebooting the RPi for the changes to take effect. Create ProjectAssuming that you have downloaded the libraries to your computer in one of the ways specified in the Download section, you can either set up the NetBeans project directly from the library structure or move the necessary folders to a project directory of your liking. NetBeans uses a concept of logical folders, and the only thing that changes is where you locate the files and libraries in the steps below, as NetBeans will take care of the necessary compilation and linking: - Menu > File > New Project, select C/C++ Application and pressNext.
- Set project name and location to your liking, as per above.
- Make sure to leave Create Main File unchecked, leave the Build Host and Tool Collection to their default values for now and press Finish.
Add Raspberry Pi as Build Host- Select the Services tab in the left window.
- Right click C/C++ Build Hosts > Add New Host.
- Hostname: Enter the IP address of the Raspberry
Port: 22 Click Next. - Enter the login user name (root) and press Next.
- NetBeans will now attempt to connect and prompt for the password you previously set.
Press OK.
- When the automatic configuration to completes, you should see a summary where NetBeans has found and set the GNU tool collection as default.
Click Finish. - Select theProjects tab in the left window.
- Right click your project > Properties.
- Build > Build Host: Select the build host you just created.
- Run > Console Type: Standard Output.
- Press Apply.
Tip |
---|
You can not assign a new IP address to an existing build host; you have to re-create it if the RPi's IP changes. Hence, it might be worth setting a static IP. |
Add QSL and C Library to Include DirectoriesWhile still inside project properties: - Build > C Compiler > Include Directories: Add the two library directories (sm_qsl and sm_clib/sm_clib/ if you add them from the repository).
- Click Apply.
Expandpanel |
---|
title | Click here if you're using If you use Raspbian Wheezy... |
---|
| panel | Add librt to Libraries in LinkerRaspbian Wheezy comes with an older version of glibc, where one of the functions used in dn_time.c is not part of the main C library. Instead, we have to add the "Real Time" library to the linker. While still inside project properties: - Build > Linker > Libraries: Press the ... button
- Press Add Option... and select Other Option.
- Enter -lrt and press OK.
|
Add Posix Threads to Libraries in LinkerWhile still inside project properties: - Build > Linker > Libraries: Press the ... button
- Press Add Standard Library... and select Posix Threads.
- PressOK until you exit the project properties.
Info |
---|
The example uses phtread to create a daemon that listens for incoming serial data, as interrupts are not supposed to be handled in user space on Linux. |
Add source and header filesThe last thing that remains is to add all the source and header files to the project, i.e those originally placed in the repository as: - examples/rpi/SimplePublish/
- sm_qsl/
- sm_clib/sm_clib/
- Exceptions:
- ports/: This contains examples for another platform, and NetBeans will complain when trying to find its dependants if you add it to the project.
- dn_whmt.c/.h: API for the Wireless Heart Mote that we do not need.
- dn_serial_mg.c/.h: API for the SmartMesh Manager that we do not need.
Note |
---|
Note that it is the sm_clib/sm_clib/ directory we want, not the whole sm_clib/ directory! |
Option 1: The Clean WayNetBeans will already have created a standard set of logical folders for you, so the cleanest way is to add the different files where they belong (skip ahead for a quicker solution): - Header files:
- Right click the folder Header Files > Add Existing Item...
- Navigate to each of the directories mentioned above (wherever you have chosen to place them) and select all the header files (except those noted as exceptions).
- Source files:
- Right click the folder Source Files > Add Existing Item...
- Navigate to each of the directories mentioned above (wherever you have chosen to place them) and select all the source files (except those noted as exceptions).
Tip |
---|
Using Add File to create new files in a project will place them in their respective logical folder |
Option 2: The Quick Way- Right click your project > Add Existing Items from Folders...
- Click Add Folder... and navigate to each of the directiories mentioned above (wherever you have chosen to place them).
This will add the folders you specify as new logical folder, along with all their contents, files and subfolders alike. Thus, if you have organized the library directories inside the folder containg the example code, you only need to add the latter. - Because we add everything in these folders, you have to remove those noted as exceptions above:
- For folders: Right click > Remove
For files: Right click > Remove from Project Warning |
---|
Remove will only remove the files from the project. Using Delete orthe Delete key will also delete them from disk! |
Build and RunMake sure to set your project as main: Right click your project > Set as Main Project You can now build your project by pressing the large hammer button (or F11 by default). This will open a new tab in the lower Output window showing the progress as NetBeans makes sure to transfer the necessary files to the Pi, and perform the necessary commands to build the project remotely. If the build succeeds, you can now run the project remotely by pressing the green play button (or F6 by default). A second new tab will open in the lower Output window to display the console output from the remotely running application. Tip |
---|
NetBeans also supports full on-remote debugging! |
Build Files and ExecutableBy default, NetBeans will synchronise the project files to the RPi with a directory structure identical to that on your computer, placed inside a root folder: /root/.netbeans/remote/<RPi IP-address>/<computer name>-<operating system>/<original path> Within this structure, build files are placed in a build/ directory inside your project folder, while the executable is placed in a similar dist/ folder. Say, for example, that your RPi has an IP address of 192.168.100.1, your computer is running 64 bit Windows and has the name defaultuser. If your project folder is located at C:\SimplePublishProject on your computer, the dist/ directory containing the executable can be found at: /root/.netbeans/remote/192.168.100.1/defaultuser-Windows-x86_64/C/SimplePublishProject/dist/Debug/GNU-Linux/ Note |
---|
You need to be logged in as root to access the above directories. |
|