Setup IDE

It should be apparent that there are 3 distinct versions of Nebula based on the Operating System (OS) of the host machine or device.

1. Java - Runs on the Linux, Windows or Mac OS platforms. It may also be referred to as the JAR version with the host referred to as a JAR device.

2. Android - Runs exclusively on any phone, tablet or device running the Android OS. It may also be referred to as the APK version with the host referred to as a APK device.

3. Arduino - Runs on any device that can be programmed using the Arduino Integrated Development Environment (IDE). It may also be referred to as the BIN version with the host referred to as a BIN device.

Nebula is intended to be used as a foundation for engineers or serious hobbyists to build their own network enabled projects. Working with Nebula requires using Intellij-Idea IDE to build the JAR package, Android Studio IDE to build the APK package and the Arduino IDE to build the BIN package. The Intellij IDE can be used for building both the JAR and APK packages but there’s not much space saving as the Android SDK has to be installed and it actually gets more confusing than working with separate IDEs. Also having separate IDEs allows simultaneous monitoring of network transactions between devices. Android Studio is made by Intellij so the look and feel is identical, however Android Studio is more Google centric so apps intended for the Google PlayStore can be more easily qualified and managed. One other recommendation is using Git for making incremental backups of your projects.

The IDEs are free and available for Linux, Windows and Mac development platforms. Each support multiple project windows so you can drag/drop Nebula classes and methods directly into your project. Obviously you only need the IDEs that support your project requirements. There’s no need to have Arduino IDE if your not building BIN devices.

For full support service Galixsys Networks recommends using Ubuntu(18.04 as of this writing) Linux as your development platform. It’s what we use and are most familiar with especially if you’re considering using Git for backup, SSH to upload code changes, VNC to monitor headless devices and other development tools. The installers for Windows and Mac use their respective locations to store the IDE and project code. Certainly, if you’re most comfortable using Windows or Mac feel free to do so.

Install the IDEs

The following guide is focused on Linux for which we’ll be using “snap install” but here is where you can download the IDEs for any development platform.

Or any Linux platform…


Or specifically for Ubuntu version 16.04 or greater with snap install…
Open Terminal and run the following commands.
sudo apt update
sudo snap install android-studio --classic
sudo snap install intellij-idea-community --classic
sudo snap install arduino

Unzip and Locate Project Files

The objective of the following instuctions is to locate the project folder named Nebula in the default location provided for by the specific IDE. The default locations are:

  • Android Studio - $HOME/AndroidStudioProjects
  • Intellij - $HOME/IdeaProjects
  • Arduino - Windows & Mac - Documents/Arduino or for Linux - $HOME/Arduino or $HOME/Sketchbook

To extract a .zip file in the same folder location as the .zip file:

  • Linux - Right-click the .zip file and select Extract Here.
  • Windows - Right-click the .zip file and select Extract All.
  • Mac - Double-click the .zip file.

If you purchased Nebula-ALL you should have downloaded a file named nebula_all.zip.

1. Starting with the nebula_all.zip in your Downloads folder, make a Desktop folder for the extraction.

mkdir $HOME/Desktop/Nebula_All

2. Move the download to the extraction folder.

mv $HOME/Downloads/nebula_all.zip $HOME/Desktop/Nebula_All/

3. Open the Desktop/Nebula_All folder and extract the nebula_all.zip file using the method above for your OS. The extracted folder is nebula_all.

4. Inside nebula_all are the folders Nebula_APK, Nebula_JAR and Nebula_BIN. Inside each of these folders is the project folder called Nebula.

5. Move the Nebula_APK project folder to AndroidStudioProjects

mv $HOME/Desktop/Nebula_All/nebula_all/Nebula_APK/Nebula $HOME/AndroidStudioProjects/

6. Move the Nebula_JAR project folder to IdeaProjects

mv $HOME/Desktop/Nebula_All/nebula_all/Nebula_JAR/Nebula $HOME/IdeaProjects/

7. For your Sketchbook location; open the Arduino IDE then select File>Preferences. Move the Nebula_BIN project folder to your Arduino Sketchbook. More details regarding Sketchbook are provided when setting up the Arduino IDE. Arduino has a specific way of locating the libraries when compiling the project.

mv $HOME/Desktop/Nebula_All/nebula_all/Nebula_BIN/Nebula <Sketchbook location>

8. You can now discard the Nebula_All extraction folder but keep the nebula_all.zip for future use. NOTE: Do not create a folder named Nebula in your home directory. Nebula itself creates a Nebula folder in your home directory for saving VPN database and file transfer directories. You can change the location and/or name of this folder later if you wish.

IDE Setup

IntelliJ IDEA for JAR Devices

IntelliJ IDEA IDE is highly configurable. If you are not familiar with Java programming there are many very good books available to walk you through application development. The following short guide uses mostly the default IDE settings to get you going quickly.

1. Open Intellij
2. Select File -> Open
3. Locate and click on the Nebula project folder then click OK
4. Use the left-side toolbar Project button to open the Project View
5. Drop-down Nebula -> src -> com.galixsys.nebula
6. See package folders. Drop-down any package folder to see files. Double-click any file to open it in the Editor View.
7. Top toolbar- click Add Configuration or Run -> Edit Configurations…
8. From the Run/Debug Configurations window, Click + (top left corner) and select Application.
8.1. Name: Nebula
8.2. Main class: com.galixsys.nebula.Main HINT: Click the dots (…) should be there.
8.3. Working directory: /your/full/path/to/Nebula
8.4. Use classpath of module: Nebula
8.5. JRE: Default (Use Java 8 to match Android). Java > 8 is OK.
../_images/IntellijConfig.png
8.6 Click Apply then OK
9. Back on main Editor - Top toolbar verify the Nebula configuration is showing then click the green arrow to build/run Nebula.
10. The JAR Nebula Installation window should open. Be sure to read about Device 1 before setting up your VPN.
11. Back on IntelliJ, drop-down out -> artifacts -> Nebula. The Nebula.jar file shown can be copied and used for any Linux, Windows or MacOS computer or SBC that has Java >= 8 installed. The Nebula.jar file will be rebuilt, with any changes made, each time you build/run Nebula.

Android Studio for APK Devices

Android Studio is highly configurable. If you are not familiar with Android Development there are several very good books available to walk you through application development. The Android Developers Guide is an invaluable resource. The following short guide uses mostly the default IDE settings to get you going quickly.

1. Open Android Studio
2. Select File -> Open
3. Locate and click on the Nebula project folder then click OK. Watch the bottom of the IDE window and wait for the project to finish building before continuing.
4. Use the left-side toolbar Project button to open the Project View if not already selected.
5. In the Project View, top toolbar left-side, drop-down and select Android if not already selected.
6. In the Project View, drop-down app -> java -> com.galixsys.nebula
7. See the package folders. Drop-down any package folder to see the enclosed files. Double-click any file to open it in the Editor View.
8. Setup Logcat. Open with View > Tool Windows > Logcat.
8.1. From the Logcat View, right-side drop-down, select Edit Filter Configuration.
8.2. Filter Name: Nebula and Log Tag: Nebula- (a dash after Nebula). Then click OK.
8.3. Limit clutter with Logcat left-side toolbar (the gear) check Show tag only. Then click OK.
8.4. Nebula logging is setup to show “Nebula-<class>: message”
9. On Android phones/pads enable Developer options -> USB debugging.
9.1. Open Settings or on Android 8.0 or higher Select System.
9.2. Scroll to and select About phone.
9.3. Scroll to and tap Build number 7 times.
9.4. Go back to Settings and find Developer options near the bottom.
9.5. Open Developer options. Scroll to and enable USB debugging. Also selecting Stay Awake is recommended during development.
9.6. The USB connection type is MTP or File Transfer or Settings > PC Connection> Internet Connection > modem.
10. Attach the device to your computer with a USB data cable. Careful some cables are for charging only and don’t support data.
11. The attached device should show on top toolbar device selector. If it does not, go back to step 9.6 and try different connection types. This is a bit of a grey area as it’s up to the device manufacturer, not Android Studio, but all known devices will connect given the required connection mode.
12. Click the green arrow to build and install Nebula on the connected device.
13. The device should open to the APK Nebula Installation window. Be sure to read about Device 1 before setting up your VPN.

Arduino IDE for BIN Devices

1. Open the Arduino IDE
2. Select File -> Preferences
3. Use the browse button to set the Sketchbook location to the BIN Nebula project folder. If you don’t want to change your Sketchbook location, you have to copy all the Nebula/libraries to your Sketchbook/libraries folder.
4. Add Additional Boards Manager URL for ESP8266. Type carefully as pasting is not allowed.
http://arduino.esp8266.com/stable/package_esp8266com_index.json then click OK.
5. File -> Sketchbook -> Nebula - The file should open in the editor.
6. Sketch -> Verify/Compile to build Nebula the first time and insure no errors and the libraries were found.
7. Attach an ESP-12E module to your computer via USB.
7.1. ESP-12E is the module used. Having a display on the module like this is supported and very helpful. The Nebula project code was developed on a project development module. Galixsys Networks hopes to soon have this available from the Nebula store. Any module that can be programmed with the Arduino IDE will work.
8. Drop-down Tools. Verify the Board, Port and Flash Size:
  • Board is NodeMCU 1.0 ESP-12E module
  • Flash Size: “4MB(FS:1MB OTA:~1019KB)”
  • Port is the serial port with CP2102 attached. If you’re not sure use Terminal command:
dmesg | grep cp210 | grep attached
8.1. After you verify that all is OK, select Serial Monitor to open a monitor window.
9. Set the Serial Monitor, bottom of window, to “No line ending” and “115200 baud”.
10. From the Arduino IDE select Sketch -> Upload
11. If after you have selected your board and the serial port, you get an error “Error opening serial port”, you have to give yourself serial port permission.
11.1. Open Terminal and run:
sudo usermod -a -G dialout $USER
11.2. You have to log out and log back in or restart your computer for the above change to take effect.
12. Install the module to get to the BIN device Installation window.

Install Git

Having a Git version control repository available is optional but recommended. Git is a built-in feature of both Android Studio and IntelliJ IDEs so it operates seamlessly. It allows you to save and backup code that works and restore previous versions for reference or use. If you are not familiar with Git here is the definitive resource. You can download the book for free. You can also download and get additional installation instructions for all platforms

To install Git on Linux…

sudo apt install git-all
  • Optionally you can install Git on a separate machine and set it up as a remote host. After installing Git on the remote proceed with the following:

Make a user typically named git. Add a password for user git.

sudo adduser git

Switch to user git.

su git

Go to /home/git

cd ~

Set-up ssh security for Git

mkdir .ssh && chmod 700 .ssh

Make the standard ssh key storage location. If you have a public ssh key on your development machine you can copy it into the authorized_keys file. If you don’t have a key we’ll step through that procedure later.

touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

Switch user to yourself. Your password

su <YourUserName>

Switch to root.

sudo su

Now as root, make the git repository location

mkdir -p /srv/git/projects/nebula

Make repositories for apk, jar and bin project files

mkdir /srv/git/projects/nebula/nebula_apk.git
mkdir /srv/git/projects/nebula/nebula_jar.git
mkdir /srv/git/projects/nebula/nebula_bin.git

Make user git the owner of all in the /srv/git directory

cd /srv && chown -R git:git git

Initialize the repos as user git. Use the password you made for user git.

su git
cd /srv/git/projects/Nebula/nebula_apk.git
git init --bare
cd ../nebula_apk.git
git init --bare
cd ../nebula_apk.git
git init --bare

From Android Studio and Intellij you can use the VCS (git) to do an initial git push. Then any changes you make to Nebula can be pushed up to your remote repository. You can add more repositories for your own projects to the remote’s /srv/git/projects/ directory by following the example above.

Setup SSH with keys

From your home directory on your development machine

mkdir .ssh && chmod 700 .ssh

Generate an RSA key pair

ssh-keygen
Reply:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/$USER/.ssh/id_rsa):

This prompt allows you to choose the location to store your RSA private key. Press ENTER to leave this as the default, which will store them in the .ssh hidden directory in your home directory.

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

The prompt allows you to enter a passphrase of an arbitrary length to secure your private key. By default, you will have to enter any passphrase you set here every time you use the private key, as an additional security measure. Feel free to press ENTER to leave this blank if you do not want a passphrase. Keep in mind though that this will allow anyone who gains control of your private key to login to your servers.

If you choose to enter a passphrase, as a security precaution nothing will be displayed as you type.

Your identification has been saved in home/$USER/.ssh/id_rsa.
Your public key has been saved in home/$USER/.ssh/id_rsa.pub.
The key fingerprint is:
8c:e9:7c:fa:bf:c4:e5:9c:c9:b8:60:1f:fe:1c:d3:8a root@here
The key’s randomart image is:
+–[ RSA 2048]—-+
Followed by the randomart image.

This procedure has generated an RSA SSH key pair, located in the .ssh hidden directory within your home directory. The files are:

  • ~/.ssh/id_rsa: The private key. DO NOT SHARE THIS FILE!
  • ~/.ssh/id_rsa.pub: The associated public key that can be shared freely without consequence.
  1. Copy the ~/.ssh/id_rsa.pub to a flash drive.
  2. Mount the flash drive on your remote Git machine.
  3. Open Terminal on remote Git machine.
  4. Elevate to root user.
sudo su

Append the id_rsa.pub file to /home/git/.ssh/authorized_keys

echo `cat /media/$USER/$FlashName/id_rsa.pub >> /home/git/.ssh/authorized_keys`

As user git you can add comments, lines beginning with #, to the authorized_keys file. This helps to remember who and what the key is for.