Skip to content

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

License

Notifications You must be signed in to change notification settings

jmcdannel/DEJA.js

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks