Enabling Running Remote Projects in NetBeans As Root User
By default the root account is disabled in Raspbian, but for an application to access the IO pins it needs root user privileges. There are ways to configure the IO to get round this but its not all that easy and for development its often just easier to have full root access so the permissions don't get in your way (you can disable it later before releasing your RPi into the wild if the security issue is a concern). When running from the command line you can do this simply using the sudo command, but when remotely running from NetBeans you need a way for it to be able to run the application as root user if you are using the IO pins. There doesn't seem to be a configuration option in NetBeans for this currently so enabling the root user account and letting NetBeans use it is a simple work around. Use this command:
sudo passwd root
Now you can log into your pi as the root user so give NetBeans the username 'root' and the password you set.
Now check the ssh config
sudo nano /etc/ssh/sshd_config
Search for PermitRootLogin and change it to yes (the default "without-password" won't work – change it to "yes").
Use CTRL+X to exit and then reboot.
To undo logging in as root later, use this command
sudo passwd -l root
Creating A New NetBeans Project
Menu > File > New Project > Select 'C/C++ Application'
Set the projects name and location
Select C or C++ from the drop down
Leave the default options for 'Build host' and 'Tool collection'.
Select the 'Services' tab in the left window.
Ensure the Raspberry Pi is powered up and connected to the network.
Right click 'C/C++ Build Hosts' > Add New Host
Enter the IP address of the Raspberry Pi
Press Next > Enter the login user name ('pi' (or 'root' – see above))
Press next and NetBeans will attempt to connect and then prompt for the password.
Select the 'Projects' tab in the left window.
Right click the projects name > Properties
Build > Build Host > Select the build host name you just created.
Run > Console Type > Standard Output
Apply and Close
If you are using the bcm2835 library for the IO pins etc, ensure you've installed it by following the guide here, add the bcm2835.h file to your project and do this:
Right click the project > Properties > Build > Linker > In the 'Libraries' section press the '…' button > Add Option… > Other Option > Enter: -lbcm2835
Right click the project > Build
Change of IP Address
You can't assign a new IP address to an existing build host. You have to re-create.
Select the 'Services' tab in the left window. Under 'C/C++ Build Hosts' right click the old [email protected] build host > Remove Host
Then follow the steps above in 'Creating A New Project'.
Troubleshooting Remote Host Connections
Manual RPi Network settings?
Do you have the RPi configured with manual network settings (IP address, subnet etc)? If so make sure they are correct and in particular the gateway IP address – we've found if the gateway is wrong / invalid on the RPi NetBeans will hang before prompting for the password when adding a new connection and be unable to connect for existing connections (even though SSH connections work fine using another SSH client). A quick fix is to set it to use DHCP and see if NetBeans can connect correctly then.
1 network path
Ensure your PC doesn't have 2 network paths to the RPi. For example if you have both WiFi and Ethernet connected and both are on the same subnet this has caused NetBEANS to hang for us after entering the username and waiting for the password prompt.
Can you connect at all
If the network connection good – can you SSH into the RPi using the same login from a SSH client OK?