Skip to content

TCP Protocol

GhostTypes edited this page Feb 22, 2026 · 2 revisions

TCP Protocol Reference

The FlashForge TCP protocol is the primary control interface for legacy printers (Adventurer 3 / 4 Pro) and serves as a low-level fallback for modern printers (5M / AD5X). It operates on port 8899.

Connection Model

Property Value
Port 8899
Protocol Raw TCP (text-based)
Concurrency Multi-threaded server (up to 10 concurrent connections)
Authentication None (local network only)
Keep-Alive Recommended; connections may timeout after inactivity

Connection Handshake

  1. Establish Connection: Connect to the printer's TCP socket on port 8899.

  2. Request Control (M601): Send the M601 command to request control of the printer.

    Successful Response:

    CMD M601 Received.
    Control Success V2.1.
    ok
    

    Failure Response: If you receive "Control Failed", the previous TCP connection was not properly closed (using M602), or another application is currently connected.

  3. Release Control (M602): Before disconnecting, send the M602 command to release control.

    Response:

    CMD M602 Received.
    Control Release.
    ok
    

Keep-Alive

The printer may automatically close the TCP connection if no commands are received for a certain period. To maintain the connection, send a command periodically (every few seconds). The M27 (Print Status) command is suitable for this purpose.

Command Format

All commands MUST be prefixed with a tilde ~.

Component Format Example
Prefix ~ ~M115
Command G or M code ~G28
Parameters Space-separated ~G1 X10 Y10 F3000
Terminator \r\n (implicit)

Examples:

~M115
~G28
~G1 X10 Y10 Z0.3 F3000
~M104 S210

Response Format

Responses are text-based and typically end with ok or an error message.

Type Format
Success CMD <Command> Received.\r\n...data...\r\nok\r\n
Ack ack: ok\r\n
Error Error: <reason>\r\n

Protocol Differences by Family

Feature Legacy (A3 / A4) Modern (5M / AD5X)
Primary Use Full Control (Motion, File, Status) Fallback / Raw Motion
M27 Status Returns text SD printing byte... Returns text (parsed for state)
File Upload Binary M28/M29 sequence HTTP POST preferred
Authentication None None

Information Commands

M115 - Get Printer Information

Retrieves detailed information about the printer.

Command: ~M115

Response Example:

CMD M115 Received.
Machine Type: Flashforge Adventurer 5M Pro
Machine Name: Adventurer 5M Pro
Firmware: v3.1.5
SN: SNXXXXXXX1234
X: 220 Y: 220 Z: 220
Tool Count: 1
Mac Address:XX:XX:XX:XX:XX:XX
ok

M27 - Get Print Status

Returns basic information about the current print job's progress.

Command: ~M27

Response Example:

CMD M27 Received.
SD printing byte 0/100
Layer: 0/0
ok

M105 - Get Temperatures

Returns current and target temperatures for the extruder(s) and heated bed.

Command: ~M105

Response (New Format):

CMD M105 Received.
T0:17.9/0.0 T1:0.0/0.0 B:18.5/0.0
ok

Response (Old Format):

CMD M105 Received.
T0:22 /0 B:11/0
ok
Field Description
T0 Primary extruder (Current/Target)
T1 Secondary extruder (Current/Target)
B Heated bed (Current/Target)

M119 - Get Endstop and Printer Status

Returns endstop states, machine status, movement mode, LED status, and current filename.

Command: ~M119

Response Example:

CMD M119 Received.
Endstop: X-max: 110 Y-max: 110 Z-min: 0
MachineStatus: READY
MoveMode: READY
Status: S:1 L:0 J:0 F:0
LED: 1
CurrentFile:
ok
Field Description
Endstop X, Y, Z endstop states
MachineStatus Overall printer state (see table below)
MoveMode Movement state (MOVING, PAUSED, READY, WAIT_ON_TOOL, HOMING)
Status Condensed status (S: System, L: LED, J: Job, F: Fan)
LED LED status (1 = ON, 0 = OFF)
CurrentFile Name of file being printed

MachineStatus Values:

Status Description
READY Printer idle and ready
BUILDING_FROM_SD Printing from storage
BUILDING_COMPLETED Print finished
PAUSED Print paused
BUSY Performing non-printing operation

M114 - Get Current Position

Retrieves the current X, Y, Z coordinates and extruder positions.

Command: ~M114

Response Example:

CMD M114 Received.
X:110.050 Y:110.050 Z:200.000 A:0.000 B:0
ok

M661 - Get Local File List

Returns a list of all files stored on the printer's local storage.

Command: ~M661

Important: The primary data is sent after the initial ok confirmation.

Response Example:

CMD M661 Received.
ok
D::/data/File1.3mf::/data/File2.gcode::/data/File3.gx

The data following ok contains file paths delimited by special characters.

M662 - Get Local File Preview

Retrieves a PNG thumbnail image for the specified file.

Command: ~M662 <file_path>

Example: ~M662 /data/MyModel.gcode

Important: The binary PNG data is sent after the initial ok confirmation.

Response Example:

CMD M662 Received.
ok
[Raw PNG binary data...]

Control Commands

Motion Commands

G28 - Home Axes

Initiates the homing sequence for specified axes.

Command: ~G28 [X] [Y] [Z]

Parameter Description
(none) Home all axes (X, Y, Z)
X Y Home X and Y only
Z Home Z only

Response:

CMD G28 Received.
ok

G1 - Linear Move

Move the print head to specified coordinates.

Command: ~G1 [X<pos>] [Y<pos>] [Z<pos>] [E<pos>] [F<feedrate>]

Parameter Description
X Target X position (mm)
Y Target Y position (mm)
Z Target Z position (mm)
E Extruder position (mm)
F Feedrate (mm/min)

Implementation Quirk: If the E parameter is included, the firmware automatically injects a G92 E0 command before the move to prevent extruder position accumulation errors.

Blocking: Motion commands are ignored if a print job is active.

Response:

CMD G1 Received.
ok

G90 - Absolute Positioning

Set all axes to use absolute coordinates.

Command: ~G90

G91 - Relative Positioning

Set all axes to use relative coordinates.

Command: ~G91

G92 - Set Position

Reset the coordinate system without moving.

Command: ~G92 [X<pos>] [Y<pos>] [Z<pos>] [E<pos>]

Job Control Commands

M23 - Start Print Job

Starts printing a specified file from local storage.

Command: ~M23 0:<file_path>

Example: ~M23 0:/user/Benchy.gcode

Path Formats:

  • /user/file_name.gcode
  • /data/model.3mf

Response:

CMD M23 Received.
ok

M24 - Resume Print

Resumes a paused print job.

Command: ~M24

M25 - Pause Print

Pauses the current print job.

Command: ~M25

M26 - Stop Print

Stops the current print job immediately.

Command: ~M26

Important: After stopping via TCP, the printer will not be controllable until the cancelled job dialog is manually cleared from the printer's screen.

Temperature Commands

M104 - Set Extruder Temperature

Sets the target temperature for the primary extruder (asynchronous).

Command: ~M104 S<temperature>

Value Description
S0 Disable extruder heating
S210 Set to 210C

Examples:

~M104 S210
~M104 S0

M140 - Set Bed Temperature

Sets the target temperature for the heated bed (asynchronous).

Command: ~M140 S<temperature>

Value Description
S0 Disable bed heating
S60 Set to 60C

Examples:

~M140 S60
~M140 S0

LED Control Commands

M146 - LED Control (Preferred)

Controls the printer's internal LED lights.

Command: ~M146 r<red> g<green> b<blue> F0

Parameter Range Description
r 0-255 Red intensity
g 0-255 Green intensity
b 0-255 Blue intensity
F 0 Control flag (typically 0)

Examples:

~M146 r255 g255 b255 F0    (White, ON)
~M146 r0 g0 b0 F0          (OFF)

Note: Use M146 instead of M144/M145 to avoid EEPROM wear.

Fan Control Commands

M106 - Fan On

Turns the cooling fan on.

Command: ~M106 [S<speed>]

Model Speed Support
Adventurer 3 On/Off only
5M Series Variable speed (S0-255)

M107 - Fan Off

Turns the cooling fan off.

Command: ~M107

Safety Commands

M112 - Emergency Stop

Immediately halts all printer activity.

Command: ~M112

Warning: This command causes an immediate halt. On some printers, axes are homed and heaters are turned off. The print job cannot be recovered after M112.

Session Commands

M601 - Request Control

Requests control of the printer. Required before sending most commands.

Command: ~M601

M602 - Release Control

Releases control of the printer. Required before disconnecting.

Command: ~M602

M610 - Rename Printer

Renames the printer.

Command: ~M610 <new_name>

Warning: Triggers a network service restart, which may briefly drop the connection.

Binary File Upload (Legacy)

For Adventurer 3/4 Pro printers, files can be uploaded via TCP using the M28/M29 sequence. Modern printers (5M/AD5X) should use HTTP /uploadGcode instead.

M28 - Start Upload

Command: ~M28 <filesize> 0:/user/<filename>

Requirements:

  • Path MUST start with 0:/user/
  • Filesize must match the exact byte count

Response:

CMD M28 Received.
ok

Error: Error: Not enough space

Data Stream

After receiving ok, send the raw binary file content:

  • Do NOT prefix with ~
  • Do NOT escape characters
  • Send exactly <filesize> bytes

M29 - End Upload

Command: ~M29

Behavior:

  • If bytes match expected size: Saves file, returns ack: "ok"
  • If mismatch: Deletes temp file, returns Error: File Is Not Available

Clone this wiki locally