/DEJA.js

NodeJS Rest API and WebSocket server that connects to a DCC-EX EX-Command Station via USB Serial.

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

DEJA.js

DCC-EX JavaScript Api

The Definitive, Tranformative, Innovative DCC-EX CommandStation API


This API runs on any supported device with a DCC-EX EX-CommandStation connected via USB. DEJA.js can replace JMRI as a lightweight replacement that runs in modern environments.

What is DEJA.js

  • 🧠 NodeJS application that runs on a πŸ’» Mac/PC/Linux/Raspberry Pi that is connected to a DCC-EX EX-CommandStation
  • πŸ”₯ Use πŸ›°οΈ DEJA Throttle to connect to DEJA.js and send DCC Loco commands to your track
  • 🌎 DEJA.js is written in JavaScript - the most popular programming language in the world*
  • ✨ Replace JMRI. DEJA.js is 🌟 modern, ⚑ blazing fast, it's requirements are simple 🎯, and you'll never look back πŸ‘€!

Architecture Diagram of DEJA.js

πŸš€ Getting Started

πŸ“¦ Prerequisites

πŸ“ Configure Environment

Create a .env file in this directory.

$ touch .env

Copy & Paste the values below into the.env file.

LAYOUT_ID=[your-layout-name]
VITE_MQTT_BROKER=wss://test.mosquitto.org
VITE_MQTT_PORT=8081
ENABLE_MQTT=true
ENABLE_WS=true
VITE_WS_PORT=8082
VITE_WS_ID=DEJA.js

❗❗❗ πŸ“£ πŸ“£ πŸ“£ ❗❗❗

Replace your-layout-name with a descriptive name of your layout. Only use lowercase letter, numbers, and dashed. No spaces. No special characters. No emoji.

🀌 GOOD Examples

LAYOUTID=[my-basement-empire]

LAYOUTID=[idaho-crossing]

LAYOUTID=[something-unique]

LAYOUTID=[apple-munchkin-fairy]

πŸ’© BAD Examples

LAYOUTID=[My B@sement "Empire"!]

LAYOUTID=[ID_cross]

LAYOUTID=[my-basement-empire] (already used!)

LAYOUTID=['πŸŽπŸ‘ΆπŸ§š']

🧩 Usage

  • πŸš€ Install & Run

    Clone this repository and open a terminal in the projet root.

    $ npm i -g pnpm
    $ pnpm install
    $ pnpm run start
  • πŸ›€οΈ Open a Supported Throttle and connect to the DCC-EX CommandStation via DEJA.js

Command Reference

// TODO: imporove with examples, MQTT Explorer instructions

action payload notes
connect {Object}
serial: {String}
Returns: { 'action': 'connected', payload: { path: {String}, baudRate: {String} } } example: { serial: '/devv/ttyusb2301' } ---
dcc {String} send raw DCC command (omit < and >)
getStatus {Object}
{ action: 'status', payload: { isConnected: {Boolean} }
listPorts {Object}
{ 'action': 'listPorts', [ports] }
Returns array of available USB ports
power {Integer} Toggle track power. 1 = ON, 0 = OFF
throttle {Object}
address: {Integer}
speed: {Integer}
Forward = positive speed, Reverse = negative -speed
turnout {Object}
turnoutId: {Integer}
state: {Boolean}
Toggle DCC-EX Turnout
output {Object}
pin: {Integer}
state: {Boolean}
Toggle DCC-EX Output
function {Object}
address: {Integer}
function: {Integer}
state: {Boolean}
Toggle DCC-EX Locomotive Function

Roadmap

  • Convert to TypeScript
  • Write Unit Tests
  • Support Turnouts
  • Support Outputs

πŸ› οΈ Built With

Node MQTT Arduino pnpm ESLint Prettier