Java
Secondary Develop Elastel Gateways by Java
Elastel gateways are built on an Open Linux system embedded computer, allowing users to create custom applications using Java. By installing the Java Development Kit (JDK) on the Elastel embedded computer, you can develop and run your own Java applications.
Typical use cases include:
- High-performance data processing and device control
- Serial, network, and protocol communication (e.g., Modbus RTU/TCP, MQTT, TCP/UDP)
- Real-time control and edge logic processing
- Integration with low-level device drivers or GPIO access
1. Supported Models and JDK Installation
Due to different Elastel model using various version of ARM processors, corresponding JDK version software packages need to be downloaded.
Product | ARM Processor | Supported JDK Version |
---|---|---|
EG500/EG410/ElastBox400/EG324L | ARM64 | Latest Version (e.g., JDK24) |
EG324 | ARM32 | Up to JDK11 |
EC212/EC211 | ARM32 | Not Supported (due to limited storage) |
1.1. JDK Download and Configuration
-
EG500/EG410/ElastBox400/EG324L (ARM64)
These models support the latest JDK versions, here using JDK24 as an example. Open
https://www.oracle.com/java/technologies/downloads
to download the ARM64 compressed package.On the Elastel embedded computer, download the file using the
curl
command and decompress it to the/usr/local/java
directory:sudo mkdir -p /usr/local/java && curl -SL https://download.oracle.com/java/24/latest/jdk-24_linux-aarch64_bin.tar.gz | sudo tar -xz -C /usr/local/java
Navigate to the decompressed JDK directory and set the system environment variables (different JDK versions require setting actual paths):
cd /usr/local/java/jdk-24.0.1
export JAVA_HOME=$(pwd)
export PATH=$JAVA_HOME/bin:$PATHVerify the installation:
java -version
javac -version -
EG324 (ARM32)
EG324 runs Ubuntu 20.04 OS supporting up to JDK11, which can be installed via
apt
:sudo apt update
sudo apt install openjdk-11-jdk -yVerify the installation:
java -version
javac -version
2. Programming Example: LED Control (ledtest)
The following program controls the system LED blinking via /dev/led
:
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class ledtest {
public static void main(String[] args) {
FileOutputStream led = null;
try {
led = new FileOutputStream("/dev/led");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while(true) {
try {
led.write('1'); //led on
Thread.sleep(500);
led.write('0'); //led off
Thread.sleep(500);
} catch (IOException e) {
e.printStackTrace();
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
//led.close();
}
}
2.1. Compiling the Program (On the Elastel Gateway)
-
Create Java Source File Create a
ledtest.java
file and copy the code above into it, or upload it via SFTP. -
Compile the Program
javac ledtest.java
2.2. Running the Program (On the Elastel Gateway)
cd /home/admin
java ledtest
The LED will blink every 0.5 seconds, indicating successful control.
This section only provide example of how to compile and run Java test programs on the Elastel ARM device. For Java program development on a PC, please refer to relevant documentation.
3. Recommended Practices
- Deploy programs to persistent paths like
/home/admin
to avoid temporary directories. - Use built-in interfaces (e.g., serial ports, GPIO, LED) for development.
- Configure
/etc/init.d/rcS
for startup services or usecrontab
for scheduled runs.
4. Appendix Tables
EG324 Peripheral Resource | Device Interface Name |
---|---|
COM1 | /dev/ttyAMA0 |
COM2 | /dev/ttyAMA1 |
COM3 | /dev/ttyAMA2 |
COM4 | /dev/ttyAMA3 |
SYS LED Indicator | /dev/led |
SYS2 LED Indicator | /dev/led2 |
Buzzer | /dev/buzzer |
Ethernet Port 1 | eth0 |
Ethernet Port 2 | eth1 |
For other models, please contact Elastel support or refer to models hardware manuals for Peripheral Interface tables.
- Official Website:
https://www.elastel.com
- Support Email:
support@elastel.com