Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing 5M communication to new Rest-Api #7642

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

iherbak
Copy link
Contributor

@iherbak iherbak commented Dec 2, 2024

Description

The communication is changed from serial to http based.
Two new user inputs ares added to the printer config dialog.
Those are required for proper calls.

image

Serial number (Sorozatszám) and Printer ID (Nyomtató ID) are thw two fields in question.

Ran the same github actions on my fork to build the changes. Also using this version myself since i created it.

@SoftFever
Copy link
Owner

@iherbak
Thanks for the PR.
Can you please provide more information of this PR(and why)?
What impact does the proposed change have as I noticed you have changed other printer's profiles

@iherbak
Copy link
Contributor Author

iherbak commented Dec 12, 2024

@SoftFever Hi, the new API added to the Flashforge 5M series using a Printer Id and an Activation key pair to guarantee the request is for the specified machine. For this purpose i added new UI elements for the user, and also added the Translations for the new "Printer ID". The previous version was a serial based and the new one is eliminates the large file transferring issues.

It was not clear to me how the profiles are used in code and added the fields for all the configs to avoid parsing errors.
If these only neccessary to be added to the Flashforge profile i could revert those changes.

Please advise,
iherbak

@Klohto
Copy link

Klohto commented Dec 13, 2024

Unfortunately, while this would be great addition, the current implementation isn't functional for most users.

I'm not sure why, but most 5M (Pro) have open port 8899. I have yet so see 8898 (like you have) in the wild. It might be due to FW differences, but I'm unsure. The original FlashForge DLL implements fnet::ScanLanDev::scanDev() which mitigates this and returns printers on LAN with corresponding ports.


Anyway, there is still additional barrier before the auth goes through.
I'm on 2.7.5 (latest) on my 5M Pro and the printer doesn't let the auth through.

Compiled your changes, but replaced the port with 8899 and

Could not connect to Flashforge: curl:Server returned nothing (no headers, no data):
Empty reply from server
[Error 52]

TCP dump

Host: 192.168.1.105:8899
User-Agent: OrcaSlicer/2.3.0-dev
X-BBL-Client-Name: OrcaSlicer
X-BBL-Client-Type: slicer
X-BBL-Client-Version: 01.09.05.51
X-BBL-Device-ID: ff4cf716-c754-4776-80b9-0cac8f12fb6c
X-BBL-Language: en-US
X-BBL-OS-Type: macos
X-BBL-OS-Version: 15.1.1
Accept: application/json
Content-Length: 55
Content-Type: application/x-www-form-urlencoded

{"serialNumber":"SNMOMREDACTED","checkCode":"REDACTED"}
15:36:04.309748 IP 192.168.1.105.8899 > 192.168.1.104.64518: Flags [.], ack 456, win 4045, options [nop,nop,TS val 189153467 ecr 1748916250], length 0
E..4.{@.@..&...i...h"...S....B.
...........
[email protected]>X.

As you can see, the server ACKs the request, but won't do anything else.

Basic curl CLI that should replicates Orca's behavior doesn't change the outcome, it's still without response.

curl -vvv -X POST \
  -H "Accept: application/json" -H "Content-Type: application/json" \
  -d '{"serialNumber":"REDACTED","checkCode":"REDACTED"}' \
  http://192.168.1.105:8899/product

I'm curious what FW version are you running?

@iherbak
Copy link
Contributor Author

iherbak commented Dec 13, 2024

I'm on the latest 2.7.6.
Your Printer should be in Lan only mode.
8899 is the port used to communicate with Serial TCP connection.
8898 is where the REST api listens. Yes it is new and added lately, and Orca-Flashforge uses it to communicate with the printer. In fact they are using IGMPv3 and you should join to 225.0.0.9 group and send a message. In turn you will get replies with serial number and ip address from all the machines available on your local network.
To be able to communicate with the printer(s) the user should input the Printer Id of the machine(s).

Unfortunatelly i don't know which firmware version is the first that started the support of the new communication way.

@Klohto
Copy link

Klohto commented Dec 13, 2024

Indeed, 2.7.6 is latest, sorry for the typo.

Switched to LAN only mode to test it out and yep it works!
nmap after LAN switch:

Not shown: 65532 closed tcp ports (conn-refused)
PORT     STATE SERVICE
8080/tcp open  http-proxy
8898/tcp open  unknown
8899/tcp open  ospf-lite

Curl response is also success

curl -X POST \
  -H "Accept: application/json" -H "Content-Type: application/json" \
  -d '{"serialNumber":"REDACTED","checkCode":"REDCATED"}' \
  http://192.168.1.105:8898/product
  
{"code":0,"message":"Success","product":{"chamberTempCtrlState":0,"externalFanCtrlState":1,"internalFanCtrlState":1,"lightCtrlState":1,"nozzleTempCtrlState":1,"platformTempCtrlState":1}}

Couldn't get the IGMP working, but I can see the device joining 225.0.0.9 group. It just ignores my messages.


So far, I managed to salvage these URLs:

  • /checkCode
  • /product
  • /detail
  • /control - couldn't find the expected JSON structure, but light, temperature, fan, print and job should all be supported
  • /uploadGcode - expects multipart
  • /gcodeList
  • /gcodeThumb
  • /printGcode
  • /getThum

And earliest FW supporting Rest API is 2.6.6-2.2.3-20240428


I think it would make sense to keep both behaviors in Orca, because it requires switching the printer to LAN mode only. Previous approach allows both LAN and external connections. All the user has to do is input the printer IP and click on print.

@Klohto
Copy link

Klohto commented Dec 13, 2024

Nevermind! @CopeTypes is already doing the reversing on https://github.com/CopeTypes/ff-5mp-api

@iherbak
Copy link
Contributor Author

iherbak commented Dec 13, 2024

Ok i see it. I also reverse engineered and added the bare minimum to make it work. I have no time and enough know-how in c++ to add a full UI integrated into Orca, however i saw all the api endpoints as well. I have A POC that capable of using the IGMP group written in c++ in case anybody interested.

@Y0uwin
Copy link

Y0uwin commented Dec 15, 2024

Hello iherbak, i preapologize as i am very new to both github and flashforge printing

using the orca Slicer 2.2 and addint my device i was able to connect to my printer
however using the 2.3 dev im unable to
image
im unsure as to what i might be messing up so any additional information would be greatly appreciated

ive tried removing the serial number and adding it to the printer ID
have the serial number for both serial and printer ID
ive had them blank
Ive tried manually adding the port8898 and still wont connect

image

UPDATE*****
image
duh lol thank you

@iherbak
Copy link
Contributor Author

iherbak commented Dec 15, 2024 via email

@Y0uwin
Copy link

Y0uwin commented Dec 15, 2024

again sorry if im being a bother but for the device tab and refusing to connect would i need to install a fork to be able to view the camera through here or is it in the works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants