Skip to main content

Go

Secondary Develop Elastel Gateways by Go

Elastel gateways are built on an Open Linux system embedded computer, allowing users to create custom applications using Go. Go programs, once compiled, do not depend on system libraries of the target system, and the ARM processor architecture is backward compatible. This makes Go applications very flexible for deployment and execution on Elastel gateways.

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 Compilation Parameters

Go programs do not rely on system libraries, and the ARM processor architecture is backward compatible, meaning higher-version processors are compatible with lower-version instruction sets. Therefore, Go programs can be compiled with different parameters.

The table below summarizes the recommended Go language compilation parameters for Elastel models:

Product ModelProcessor ArchitectureRecommended Parameters
EG500/EG410/ElastBox400/EG324LARM 64-bit (ARMv8)GOOS=linux GOARCH=arm64
EG324/EC212/EC211ARM 32-bit (ARMv7)GOOS=linux GOARCH=arm GOARM=7

2. Go SDK Environment Setup (Windows System)

  1. Download and Install Go Go to the official Go download page: https://go.dev/dl/, download the Windows installer, and install it. install_go

  2. Verify Installation After installation, open PowerShell or CMD and run the following command:

    go version

    You should see output similar to this:

    go version go1.24.4 windows/amd64

3. Programming Example: LED Control (ledtest)

The following program controls the system LED blinking via /dev/led:

package main

import (
"fmt"
"os"
"time"
)

func main() {

file, err := os.OpenFile("/dev/led",os.O_RDWR,0)

if err != nil {
fmt.Println("led open error!\n")
os.Exit(1)
}

defer file.Close()

buf := make([]byte, 1)

for {
buf[0] = '0'
file.Write(buf)
time.Sleep(500 * time.Millisecond)
buf[0] = '1'
file.Write(buf)
time.Sleep(500 * time.Millisecond)
}

}

3.1. Compiling the Test Program

Create a file named ledtest.go and copy the code above into it.

Choose the appropriate compilation command based on your target device type:

  • ARM 64-bit (ARMv8) Device Compilation Command:

    $env:GOOS = "linux"
    $env:GOARCH = "arm64"
    go build -o ledtest ledtest.go
  • ARM 32-bit (ARMv7) Device Compilation Command:

    $env:GOOS = "linux"
    $env:GOARCH = "arm"
    $env:GOARM="7"
    go build -o ledtest ledtest.go

3.2. Upload and Run on the Gateway

Upload the compiled test program to the device and change its permissions. Run the program using the ./ledtest command.

Method 1: Upload via Web Terminal (Check ElastPro for more details)

  • Open browser at http://192.168.1.1 → System → Terminal → Upload Files upload_via_web

  • Move the uploaded file to persistent path:

    sudo mv /tmp/terminal/testfile /home/admin/

Method 2: Using MobaXterm / Xshell

  • Drag and drop via SFTP to the /home/admin/ path.

Run the program:

cd /home/admin
chmod +x ledtest
./ledtest

The SYS LED will blink every 0.5 seconds, indicating successful control.


  • Use built-in interfaces (e.g., serial ports, GPIO, LED) for development.
  • Configure /etc/init.d/rcS for startup services or use crontab for scheduled runs.

5. Appendix Tables

EG324 Peripheral ResourceDevice 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 1eth0
Ethernet Port 2eth1
Note

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