Skip to main content

Python

Secondary develop Elastel Gateways by Python

Python is a powerful and easy-to-learn scripting language, well-suited for edge IoT development. All Elastel gateways come with a built-in Python 3 interpreter, allowing developers to quickly write and run Python scripts without additional setup.

Typical use cases like:

  • Serial and network communication (e.g., Modbus, MQTT, TCP/UDP)
  • Data acquisition and local processing
  • Controlling LEDs, buzzers, relays, etc.
  • Edge computing and cloud integration

1. Supported Models

The following Elastel gateways come with Python 3 pre-installed:

  • Industrial Raspberry Pi series: EG500, EG410, ElastBox400
  • ARM-based IIoT Gateway series: EG324, EG324 Lite, EC212, EC211

Python development is supported out-of-the-box across all these models.


2. "Hello World" Example

Create a basic Python script named hello.py:

# hello.py
print("Hello, Elastel Gateway!")

Step 1: Create the Script

Use any text editor to create a file called hello.py with the content above.


Step 2: Upload the Script to the Gateway

Option A: Web Terminal Upload

ElastPro has prebuilt a web terminal tool on webUI, which also support upload files via web.

  1. Access the ElastPro webUI http://192.168.1.1 (Check Getting Started for more details)
  2. Go to System -> Terminal
  3. Use Upload Files to upload hello.py upload_via_web

Files uploaded here will be stored in /tmp, which is cleared on reboot. Move to /home/admin for persistence:

sudo mv /tmp/terminal/hello.py /home/admin/
  1. Connect via SSH to the gateway
  2. Drag and drop the file into the SFTP panel to upload it to /home/admin/

Step 3: Run the Script

Log in via SSH or Terminal and execute the following:

cd /home/admin
python3 hello.py

Output:

Hello, Elastel Gateway!

python_output

3. Recommendations Practices

  • Use built-in interfaces (e.g., serial ports, GPIO, MQTT, Ethernet) for development
  • Configure /etc/init.d/rcS for startup service or use crontab for scheduled runs
  • Ensure scripts use UNIX-style line endings (LF) to avoid execution errors

4. 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.