This page describes the available XpressNet commands and how to implement them in your command station firmware.
| Command Name | Code (Hex) | Description | Typical Usage |
|---|---|---|---|
| Locomotive Speed | 0xE4 | Set speed and direction for a locomotive | Control train movement |
| Function Group 1 | 0xE4 | Control F0-F4 functions | Lights, sound, etc. |
| Function Group 2 | 0xE4 | Control F5-F8 functions | Extended functions |
| Accessory Control | 0x90 | Switch turnouts, signals, etc. | Control layout accessories |
| Read Feedback | 0xF2 | Query feedback modules | Detect occupancy, sensors |
| Programming on Main | 0xEF | Write CVs to decoders on main track | Decoder configuration |
| Programming Track | 0xED | Write/read CVs on programming track | Safe decoder programming |
| Request Version | 0x21 | Request command station version | Handshake, diagnostics |
| Emergency Stop | 0x80 | Stop all locomotives immediately | Safety/emergency |
Note: Actual codes and command structure may vary by implementation. Refer to the official XpressNet protocol documentation for full details.
handleLocomotiveSpeed(), handleAccessoryControl()).void handleLocomotiveSpeed(const uint8_t* data, size_t len) {
// Parse address, speed, direction from data
// Update DCC packet buffer
// Send DCC packet to track
}
You can add your own special commands to XpressNet by using unused command codes. Below are examples for switching mode and power control.
| Command Name | Code (Hex) | Payload Example | Description |
|---|---|---|---|
| Switch Mode | 0xF0 | 0x00 | Switch to Analog mode |
| 0x01 | Switch to DCC mode | ||
| 0x02 | Switch to Marklin mode | ||
| Power Track | 0xF1 | 0x00 | Power OFF |
| 0x01 | Power ON |
// Handle custom XpressNet commands
void handleCustomXpressNet(const uint8_t* data, size_t len) {
uint8_t cmd = data[0];
switch (cmd) {
case 0xF0: // Switch Mode
if (len > 1) {
uint8_t mode = data[1];
switch (mode) {
case 0x00: /* setAnalogMode(); */ break;
case 0x01: /* setDCCMode(); */ break;
case 0x02: /* setMarklinMode(); */ break;
}
}
break;
case 0xF1: // Power Track
if (len > 1) {
if (data[1] == 0x01) {
// powerOnTrack();
} else {
// powerOffTrack();
}
}
break;
// ... handle other custom commands ...
}
}
You can encapsulate XpressNet packets in WebSocket frames for remote control over IP. On the ESP8266, use a WebSocket server library (e.g., arduinoWebSockets).
#include <WebSocketsServer.h>
WebSocketsServer webSocket = WebSocketsServer(81);
void onWebSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
if (type == WStype_BIN) {
// Process XpressNet packet
handleXpressNet(payload, length);
// Optionally send response:
// webSocket.sendBIN(num, response, responseLen);
}
}
void setup() {
// ... WiFi setup ...
webSocket.begin();
webSocket.onEvent(onWebSocketEvent);
}
void loop() {
webSocket.loop();
}
These extensions allow you to add custom features and remote control to your XpressNet command station.