node-3dprinter-mks-wifi
This package allows to manage a 3dPrinter with MKS WIFI support using node.
Prerequisites
This package is designs for 3dPrinter using marlin derived firmware and supporting MKS WIFI featrues!
This package requires NodeJS (version 16 or later) and NPM.
Node and NPM are really easy to install.
To make sure you have them available on your machine,
try running the following command.
$ npm -v && node -v
Table of contents
Installation
BEFORE YOU INSTALL: please read the prerequisites
Via Github
Clone this repo on your local machine:
$ git clone https://github.com/alealpha07/node-3dprinter-mks-wifi
$ cd node-3dprinter-mks-wifi
Via npm
Install the npm package
$ npm install node-3dprinter-mks-wifi
Usage
To use the package you need to include the Printer
class in your index
file first
const Printer = require("node-3dprinter-mks-wifi");
create an instance of the Printer
by providing the correct IP
and PORT
const Printer = require("node-3dprinter-mks-wifi");
const IP = "192.168.1.1";
const PORT = "8080";
const printer = new Printer(IP, PORT);
now you can use the functionalities of the printer by simply using the methods listed in the API
section
Full Example
This simple example will connect, retrive the printing status and print it to the console.
const Printer = require("node-3dprinter-mks-wifi");
const IP = "192.168.1.1";
const PORT = "8080";
const printer = new Printer(IP, PORT);
printer.connect().then(()=>{
printer.getState().then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
}).finally(()=>{
printer.disconnect();
})
})
With async/await:
const Printer = require("node-3dprinter-mks-wifi");
const IP = "192.168.1.1";
const PORT = "8080";
const printer = new Printer(IP, PORT);
async function main(){
try{
await printer.connect();
let result = await printer.getState();
console.log(result);
}catch(error){
console.log(error);
}
finally{
printer.disconnect();
}
}
main();
API
constructor
constructor
new Printer(ip, port)
Supported options for the constructor
method are listed below.
Options
ip
Type | Default value | Mandatory |
---|
string | null | yes |
port
Type | Default value | Mandatory |
---|
string | null | yes |
minimumExtruderTemperature
Type | Default value | Mandatory |
---|
number | 0 | no |
maximumExtruderTemperature
Type | Default value | Mandatory |
---|
number | 280 | no |
minimumBedTemperature
Type | Default value | Mandatory |
---|
number | 0 | no |
maximumBedTemperature
Type | Default value | Mandatory |
---|
number | 100 | no |
connect
connect to the printer
printer.connect()
Supported options and possible results for the connect
method are listed below.
Returns
string
- Connected to printer at IP:PORT
if succeeded
string
- Connection error: ERROR
if failed
Options
no option is present
disconnect
disconnect from the printer
printer.disconnect()
Supported options and possible results for the disconnect
method are listed below.
Returns
string
- Disconnected from printer.
if succeeded
string
- Disconnection error: ERROR
if failed
Options
no option is present
getState
get status of the printer (printing, idle, pause)
printer.getState()
Supported options and possible results for the getState
method are listed below.
Returns
string
- STATUS STRING
if succeeded
string
- Error receiving data: ERROR
if failed
Options
no option is present
getTemperature
get temperatures of the printer
printer.getTemperature()
Supported options and possible results for the getTemperature
method are listed below.
Returns
object
if succeeded:
{
nozzleCurrent: number,
nozzleTarget: number,
bedCurrent: number,
bedTarget: number,
extruder0Current: number,
extruder0Target: number,
extruder1Current: number,
extruder1Target: number,
heaterPower: number,
bedHeaterPower: number
}
string
- Error receiving data: ERROR
if failed
Options
no option is present
getPrintingProgress
get printing progress (percentage)
printer.getPrintingProgress()
Supported options and possible results for the getPrintingProgress
method are listed below.
Returns
number
- between 0
and 100
if succeeded:
string
- Error receiving data: ERROR
if failed
Options
no option is present
getPrintingTime
get elapsed print time
printer.getPrintingTime()
Supported options and possible results for the getPrintingTime
method are listed below.
Returns
string
- hh:mm:ss
format if succeeded:
string
- Error receiving data: ERROR
if failed
Options
no option is present
getPrintingFilename
get currently in print file name
printer.getPrintingFilename()
Supported options and possible results for the getPrintingFilename
method are listed below.
Returns
string
- FILENAME.gcode
if succeeded:
string
- Error receiving data: ERROR
if failed
Options
no option is present
getFilenames
get all files in 3d printer sd card
printer.getFilenames()
Supported options and possible results for the getFilenames
method are listed below.
Returns
list: [string]
- ['file1.gcode', 'file2.gcode', ...]
if succeeded:
string
- Error receiving data: ERROR
if failed
Options
no option is present
startPrinting
start printing the selected file
printer.startPrinting(filename)
Supported options and possible results for the startPrinting
method are listed below.
Returns
string
- ok
if succeeded:
string
- Error receiving data: ERROR
if failed
Options
filename
Type | Default value | Mandatory |
---|
string | null | yes |
home
bring the hotend to the home position
printer.home()
Supported options and possible results for the home
method are listed below.
Returns
string
- ok
if succeeded:
string
- Error receiving data: ERROR
if failed
Options
no option is present
pause
pause the print
printer.pause()
Supported options and possible results for the pause
method are listed below.
Returns
string
- ok
if succeeded:
string
- Error receiving data: ERROR
if failed
Options
no option is present
resume
resume the print
printer.resume()
Supported options and possible results for the resume
method are listed below.
Returns
string
- ok
if succeeded:
string
- Error receiving data: ERROR
if failed
Options
no option is present
abort
abort the print
printer.abort()
Supported options and possible results for the abort
method are listed below.
Returns
string
- ok
if succeeded:
string
- Error receiving data: ERROR
if failed
Options
no option is present
startFan
start the fan
printer.startFan()
Supported options and possible results for the startFan
method are listed below.
Returns
string
- ok
if succeeded:
string
- Error receiving data: ERROR
if failed
Options
speed
Type | Default value | Mandatory | Minimum | Maximum |
---|
number | 255 | no | 0 | 255 |
stopFan
stop the fan
printer.stopFan()
Supported options and possible results for the stopFan
method are listed below.
Returns
string
- ok
if succeeded:
string
- Error receiving data: ERROR
if failed
setExtruderTemperature
set target extruder temperature
printer.setExtruderTemperature(temperature)
Supported options and possible results for the setExtruderTemperature
method are listed below.
Returns
string
- ok
if succeeded:
string
- Error receiving data: ERROR
if failed
Options
temperature
Type | Default value | Mandatory | Minimum | Maximum |
---|
number | null | yes | 0 | 280 |
you can set custom minmum and maximum temperature in the constructor
extruder
Type | Default value | Mandatory | Minimum | Maximum |
---|
number | 0 | no | 0 | 1 |
you can set the extruder to use (0 for the first one, 1 for the second)
setBedTemperature
set target bed temperature
printer.setBedTemperature(temperature)
Supported options and possible results for the setBedTemperature
method are listed below.
Returns
string
- ok
if succeeded:
string
- Error receiving data: ERROR
if failed
Options
temperature
Type | Default value | Mandatory | Minimum | Maximum |
---|
number | null | yes | 0 | 100 |
you can set custom minmum and maximum temperature in the constructor
Authors