Iec104
A modern Go client library for the IEC 60870-5-104 (IEC104) protocol, widely used in SCADA and substation automation. Supports connection management, general interrogation, measured value reading, command sending, clock synchronization, and more. Thread-safe, easy to integrate, and suitable for industrial applications.
Install / Use
/learn @eddielth/Iec104README
IEC 60870-5-104 (IEC 104) Go Library
A robust and efficient Go implementation of the IEC 60870-5-104 (IEC 104) protocol. This library provides a high-level client interface for communicating with RTUs, gateways, and other power system automation devices.
Features
- Full Client Implementation: Supports I-frames, S-frames, and U-frames (STARTDT, STOPDT, TESTFR).
- Connection Management:
- Automatic reconnection with configurable backoff.
- Heartbeat (TESTFR) mechanism to maintain connection stability.
- Thread-safe design for concurrent operations.
- Protocol Support:
- General Interrogation (GI).
- Data acquisition via polling or spontaneous reports.
- Commands: Single, Double, and Setpoint (Normalized, Scaled, Floating-point).
- Clock Synchronization.
- Flexible Data Handling: Asynchronous data reception via user-defined handlers.
- Logging: Built-in logging support for debugging and monitoring.
Installation
go get github.com/eddielth/iec104
Supported ASDU Types
The library supports a wide range of Application Service Data Unit (ASDU) types:
| Type ID | Description |
| :--- | :--- |
| 0x01 | Single point indication |
| 0x03 | Double point indication |
| 0x09 | Measured value, normalized value with quality |
| 0x0D | Measured value, short floating point with quality |
| 0x2D | Single command |
| 0x2E | Double command |
| 0x30 | Setpoint command, normalized value |
| 0x32 | Setpoint command, short floating point |
| 0x64 | General interrogation command |
| 0x67 | Clock synchronization command |
| ... | And more (see asdu.go for full list) |
Quick Start
Basic Client with Data Handler
package main
import (
"log"
"time"
"github.com/eddielth/iec104"
)
func main() {
// Create a new client
client := iec104.NewClient("127.0.0.1:2404", 5*time.Second)
// Enable logging to console
client.EnableLog()
// Set a handler for incoming ASDU data
client.SetOnDataHandler(func(asdu *iec104.ASDU) {
log.Printf("Received ASDU: Type 0x%02X, Cause %d, CommonAddr %d",
asdu.TypeID, asdu.Cause, asdu.CommonAddr)
for _, obj := range asdu.InfoObjects {
log.Printf(" Object Address: %d, Value: %v", obj.Address, obj.Value)
}
})
// Connect to the server
if err := client.Connect(); err != nil {
log.Fatalf("Failed to connect: %v", err)
}
defer client.Close()
// Perform General Interrogation
if _, err := client.GeneralInterrogation(1); err != nil {
log.Printf("GI failed: %v", err)
}
// Keep the application running
select {}
}
Sending Commands
// Send a Single Command (ON)
err := client.SendSingleCommand(1, 10001, true, false)
// Send a Setpoint Command (Short Floating Point)
err := client.SendSetpointCommand(1, 20001, 123.45)
Examples
Check the example/ directory for:
example/main.go: A basic client demonstration.example/sim_server/: A simulated IEC 104 server for testing purposes.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Disclaimer
This library is for educational and professional use. Always ensure compatibility with your specific hardware and safety protocols in production environments.
Related Skills
openhue
349.2kControl Philips Hue lights and scenes via the OpenHue CLI.
sag
349.2kElevenLabs text-to-speech with mac-style say UX.
weather
349.2kGet current weather and forecasts via wttr.in or Open-Meteo
tradingview-mcp
682Advanced TradingView MCP Server for AI-powered market analysis. Real-time crypto & stock screening, technical indicators, Bollinger Band intelligence, and candlestick patterns. Works with Claude Desktop & AI assistants. Multi-exchange support (Binance, KuCoin, Bybit+). Open source trading toolkit.
