Skip to content

GhostTypes/ff-5mp-api-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlashForge TypeScript API

TypeScript Node.js NPM Jest Axios

Stars Forks

A robust, cross-platform API for FlashForge 3D printers, created through reverse-engineering the communication between the printers and FlashForge software.

Explore the Docs »


Printer Coverage & Testing

Printer Supported Tested API
Adventurer 5X Yes Yes HTTP + TCP
Adventurer 5M / 5M Pro Yes Yes HTTP + TCP
Adventurer 3 / 4 Yes Partial TCP Only

Feature Coverage

Feature TCP Only TCP + HTTP
Get Recent & Local Files Yes Yes
Model Preview Images Yes (Slow) Yes (Fast)
Full Job Control
(Start / Stop / Pause / Resume)
Yes Yes
LED Control Yes Yes
Upload New Files No (Not planned) Yes
Printer Information Limited Yes
Job Information Very Limited Yes
Job Time & ETA Not Available Yes
Homing / Direct G&M Code Control Yes Yes

Getting Started

This section covers how to use the API with both legacy FlashForge printers and newer models such as the Adventurer 5M / 5M Pro and AD5X.


Legacy Printers (Adventurer 3 / 4)

Legacy FlashForge printers use a TCP-based protocol which provides basic job control, printer information, and status monitoring. Connecting only requires the printer’s IP address.

import { FlashForgeClient } from 'ff-api';

async function main() {
    // Replace with your printer's IP address
    const client = new FlashForgeClient('192.168.1.100');

    if (await client.initControl()) {
        console.log("Successfully connected to printer.");

        // Example: Turn on the LED
        await client.ledOn();

        // Example: Get printer info
        const info = await client.getPrinterInfo();
        if (info) {
            console.log(`Printer Type: ${info.TypeName}`);
            console.log(`Firmware: ${info.FirmwareVersion}`);
        }

        await client.dispose();
    } else {
        console.log("Failed to connect to printer.");
    }
}

main();

Adventurer 5M / 5M Pro

The Adventurer 5 series uses an improved HTTP API for fast, modern communication, while still supporting legacy TCP-based G-code control. You will need the printer’s IP address, serial number, and check code

import { FiveMClient } from 'ff-api';

async function main() {
    // Replace with your printer's details
    const client = new FiveMClient(
        '192.168.1.101',
        'SNADVA5M12345',
        '12345'
    );

    if (await client.initialize()) {
        console.log("Successfully connected to printer.");
        console.log(`Printer Name: ${client.printerName}`);
        console.log(`Firmware: ${client.firmwareVersion}`);

        // Example: Get a list of local files
        const files = await client.files.getLocalFiles();
        if (files) {
            console.log("Files on printer:", files.map(f => f.name));
        }

        // Example: Upload a file
        // await client.files.uploadFile('path/to/your/file.gcode');

        // The FiveMClient also includes the legacy TCP client for direct G-code
        await client.tcpClient.homeAxes();

        await client.dispose();
    } else {
        console.log("Failed to connect.");
    }
}

main();
 

Adventurer 5X (AD5X)

 

The AD5X uses the same powerful HTTP API as the 5M series but adds specialized support for its Intelligent Filament Station (IFS), enabling multi-color and multi-material printing. The API provides dedicated methods and data models to manage this functionality.

 

Connecting to an AD5X is identical to a standard 5M.

import { FiveMClient } from 'ff-api';

async function checkIFS() {
    const client = new FiveMClient('192.168.1.102', 'SNADVA5X12345', '54321');
    if (!await client.initialize() || !client.isAD5X) {
        console.log("Failed to connect or not an AD5X.");
        return;
    }

    const machineInfo = client.info.machineInfo;

    if (machineInfo && machineInfo.HasMatlStation && machineInfo.MatlStationInfo) {
        console.log("Intelligent Filament Station (IFS) Detected.");

        const ifs = machineInfo.MatlStationInfo;
        console.log(`- Active Slot: ${ifs.currentSlot}`);
        console.log(`- Loading Slot: ${ifs.currentLoadSlot}`);
        console.log("- Slot Details:");

        for (const slot of ifs.slotInfos) {
            if (slot.hasFilament) {
                console.log(`  - Slot ${slot.slotId}: [${slot.materialName}] - Color: ${slot.materialColor}`);
            } else {
                console.log(`  - Slot ${slot.slotId}: [Empty]`);
            }
        }
    } else {
        console.log("No Intelligent Filament Station detected.");
    }

    await client.dispose();
}

checkIFS();
 

Starting a Multi-Color Print

 

    To start a multi-color print, you need to provide materialMappings. This array links the tool ID from your G-code file to a specific slot in the material station.  

 

        - toolId: The tool index from your slicing software (0-3).        

  • slotId: The physical slot on the material station (1-4).  

import { FiveMClient, AD5XLocalJobParams, AD5XMaterialMapping } from 'ff-api';

async function startMultiColor() {
    const client = new FiveMClient('192.168.1.102', 'SNADVA5X12345', '54321');
    if (!await client.initialize() || !client.isAD5X) {
        console.log("Failed to connect or not an AD5X.");
        return;
    }

    const mappings: AD5XMaterialMapping[] = [
        { toolId: 0, slotId: 1, materialName: "PLA", toolMaterialColor: "#FF0000", slotMaterialColor: "#FF0000" },
        { toolId: 1, slotId: 2, materialName: "PLA", toolMaterialColor: "#00FF00", slotMaterialColor: "#00FF00" }
    ];

    const jobParams: AD5XLocalJobParams = {
        fileName: 'my_multi_color_print.gcode',
        levelingBeforePrint: true,
        materialMappings: mappings
    };

    if (await client.jobControl.startAD5XMultiColorJob(jobParams)) {
        console.log("Multi-color job started successfully!");
    }

    await client.dispose();
}
 

Starting a Single-Color Print

 

    For single-color prints, you can use a simpler method that doesn't require material mappings. The printer will use the currently loaded filament.  

import { FiveMClient, AD5XSingleColorJobParams } from 'ff-api';

async function startSingleColor() {
    const client = new FiveMClient('192.168.1.102', 'SNADVA5X12345', '54321');
    if (!await client.initialize() || !client.isAD5X) {
        console.log("Failed to connect or not an AD5X.");
        return;
    }

    const jobParams: AD5XSingleColorJobParams = {
        fileName: 'my_single_color_print.gcode',
        levelingBeforePrint: true
    };

    if (await client.jobControl.startAD5XSingleColorJob(jobParams)) {
        console.log("Single-color job started successfully!");
    }

    await client.dispose();
}
 

Uploading Files for AD5X

 

    You can also upload files with material mappings directly using uploadFileAD5X. The material mappings are Base64-encoded and sent in the headers automatically.  

About

Cross Platform FlashForge API in TypeScript

Resources

Stars

Watchers

Forks

Packages