1.8 KiB
1.8 KiB
Farm Control Server
A Node.js application that bridges communication between external websocket clients and a Moonraker-controlled 3D printer.
Features
- Connects to Moonraker API via websocket
- Provides a websocket server for external clients
- Relays JSON-RPC commands between clients and the printer
- Broadcasts printer status updates to all connected clients
- Handles reconnection if the Moonraker connection is lost
Installation
- Clone this repository
- Install dependencies:
npm install - Edit the
config.jsonfile to match your Moonraker setup - Start the server:
npm start
Configuration
The config.json file contains the following options:
{
"moonraker": {
"host": "localhost",
"port": 7125,
"protocol": "ws",
"apiKey": null,
"identity": {
"name": "printer-bridge",
"version": "0.1.0",
"type": "external"
}
},
"server": {
"port": 8080
}
}
moonraker.host: The hostname or IP address of your Moonraker instancemoonraker.port: The port number of your Moonraker instancemoonraker.protocol: The protocol to use (wsorwss)moonraker.apiKey: Your Moonraker API key (if required)server.port: The port number for the websocket server
Usage
Connect to the websocket server at ws://[host]:[port] and send JSON-RPC formatted messages to control the printer.
Example client-side code:
const ws = new WebSocket('ws://localhost:8080');
ws.onopen = () => {
console.log('Connected to printer bridge');
// Send a command to get printer info
ws.send(JSON.stringify({
jsonrpc: "2.0",
method: "printer.info",
id: 1
}));
};
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
console.log('Received:', message);
};
License
MIT