Skip to content

Commit f5ae9f1

Browse files
committed
The OctoPrint server is simulated. See -octoprint
1 parent 6d93264 commit f5ae9f1

File tree

3 files changed

+77
-9
lines changed

3 files changed

+77
-9
lines changed

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ A command-line tool for send the gcode file to Snapmaker Printers via WiFi conne
66
## Features:
77
- Support Snapmaker 2 A150/250/350, J1, Artisan
88
- Auto discover machines (UDP broadcast)
9+
- Simulated a OctoPrint server, so that it can be in any slicing software such as Cura/PrusaSlicer/SuperSlicer/ideaMaker send gcode to the printer
910
- No need to click Yes button on the touch screen every time for authorization connect
1011
- Support for multiple platforms including win/macOS/Linux/RaspberryPi
1112

@@ -14,18 +15,48 @@ Download [sm2uploader](https://github.com/macdylan/sm2uploader/releases)
1415
- Linux/macOS: `chmod +x sm2uploader`
1516

1617
```
18+
## Discover mode
1719
$ sm2uploader /path/to/code-file1 /path/to/code-file2
1820
Discovering ...
1921
Use the arrow keys to navigate: ↓ ↑ → ←
20-
? Found 2 machines:
22+
? Found 3 machines:
2123
▸ A350-3DP@192.168.1.20 - Snapmaker A350
2224
A250-CNC@192.168.1.18 - Snapmaker A250
2325
J1V19@192.168.1.19 - Snapmaker-J1
24-
Printer IP: 192.168.1.20
26+
Printer IP: 192.168.1.19
27+
Printer Model: Snapmaker J1
28+
Uploading file 'code-file1' [1.2 MB]...
29+
- SACP sending 100%
30+
Upload finished.
31+
32+
## Directly mode
33+
$ sm2uploader -host 192.168.1.19 /path/to/code-file1 /path/to/code-file2
34+
Printer IP: 192.168.1.19
35+
Printer Model: Snapmaker J1
36+
Uploading file 'code-file1' [1.2 MB]...
37+
- SACP sending 100%
38+
Upload finished.
39+
40+
## use printer id
41+
$ sm2uploader -host J1V19 /path/to/code-file1 /path/to/code-file2
42+
Discovering ...
43+
Printer IP: 192.168.1.19
2544
Printer Model: Snapmaker J1
2645
Uploading file 'code-file1' [1.2 MB]...
2746
- SACP sending 100%
2847
Upload finished.
48+
49+
## OctoPrint server (CTRL-C to stop)
50+
$ sm2uploader -octoprint :8844 -host A350
51+
Printer IP: 192.168.1.20
52+
Printer Model: Snapmaker 2 Model A350
53+
Starting OctoPrint server on :8844 ...
54+
Server started, now you can upload files to http://localhost:8844
55+
Request GET /api/version completed in 6.334µs
56+
- HTTP sending 100.0%
57+
Upload finished: model.gcode [382.2 KB]
58+
Request POST /api/files/local completed in 951.080458ms
59+
...
2960
```
3061

3162
If UDP Discover can not work, use `sm2uploader -host 192.168.1.20 /file.gcode` to directly upload to printer.

README.zh-cn.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Luban 和 Cura with SnapmakerPlugin 对于新手很友好,但是我的大部
77
## 功能
88
- 支持 Snapmaker 2 A/J1/Artisan 全系列打印机
99
- 自动发现局域网内所有的 Snapmaker 打印机(和 Luban 相同的协议,使用 UDP 广播)
10+
- 模拟 OctoPrint Server,这样就可以在各种切片软件,比如 Cura/PrusaSlicer/SuperSlicer/ideaMaker 中向 Snapmaker 打印机发送文件
1011
- Snapmaker 2 A-Series 第一次连接时需要授权,之后可以直接一步上传
1112
- 支持 macOS/Windows/Linux/RaspberryPi 多个平台
1213

@@ -15,18 +16,48 @@ Luban 和 Cura with SnapmakerPlugin 对于新手很友好,但是我的大部
1516
- Linux/macOS 下,可能需要赋予可执行权限 `chmod +x sm2uploader`
1617

1718
```
19+
## 自动查找模式
1820
$ sm2uploader /path/to/code-file1 /path/to/code-file2
1921
Discovering ...
2022
Use the arrow keys to navigate: ↓ ↑ → ←
21-
? Found 2 machines:
22-
▸ A350-3DP@192.168.1.20 - Snapmaker 2 Model A350
23-
A250-CNC@192.168.1.18 - Snapmaker 2 Model A250
24-
J1V19@192.168.1.19 - Snapmaker J1
25-
Printer IP: 192.168.1.20
23+
? Found 3 machines:
24+
▸ A350-3DP@192.168.1.20 - Snapmaker A350
25+
A250-CNC@192.168.1.18 - Snapmaker A250
26+
J1V19@192.168.1.19 - Snapmaker-J1
27+
Printer IP: 192.168.1.19
28+
Printer Model: Snapmaker J1
29+
Uploading file 'code-file1' [1.2 MB]...
30+
- SACP sending 100%
31+
Upload finished.
32+
33+
## 指定 IP 连接模式
34+
$ sm2uploader -host 192.168.1.19 /path/to/code-file1 /path/to/code-file2
35+
Printer IP: 192.168.1.19
36+
Printer Model: Snapmaker J1
37+
Uploading file 'code-file1' [1.2 MB]...
38+
- SACP sending 100%
39+
Upload finished.
40+
41+
## 指定打印机名字进行连接
42+
$ sm2uploader -host J1V19 /path/to/code-file1 /path/to/code-file2
43+
Discovering ...
44+
Printer IP: 192.168.1.19
2645
Printer Model: Snapmaker J1
2746
Uploading file 'code-file1' [1.2 MB]...
2847
- SACP sending 100%
2948
Upload finished.
49+
50+
## 模拟 OctoPrint (CTRL-C 终止运行)
51+
$ sm2uploader -octoprint :8844 -host A350
52+
Printer IP: 192.168.1.20
53+
Printer Model: Snapmaker 2 Model A350
54+
Starting OctoPrint server on :8844 ...
55+
Server started, now you can upload files to http://localhost:8844
56+
Request GET /api/version completed in 6.334µs
57+
- HTTP sending 100.0%
58+
Upload finished: model.gcode [382.2 KB]
59+
Request POST /api/files/local completed in 951.080458ms
60+
...
3061
```
3162

3263
打印机的 UDP 应答服务有时会挂掉,通常需要重启打印机来解决。或者你可以直接指定目标IP: `sm2uploader -host 192.168.1.20 /file.gcode`
@@ -38,4 +69,4 @@ Upload finished.
3869
## 在 macOS 系统提示文件无法打开的解决方法
3970
macOS 不允许直接打开未经数字签名的程序,参考解决方案: https://osxdaily.com/2012/07/27/app-cant-be-opened-because-it-is-from-an-unidentified-developer/
4071

41-
也可以直接在终端执行 `xattr -d com.apple.quarantine sm2uploader-darwin`
72+
也可以直接在终端执行 `xattr -d com.apple.quarantine sm2uploader-darwin`

octoprint.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package main
22

33
import (
4+
"fmt"
45
"io"
56
"log"
67
"net"
78
"net/http"
9+
"strings"
810
"time"
911
)
1012

@@ -63,7 +65,11 @@ func startOctoPrintServer(listenAddr string, printer *Printer) error {
6365
return err
6466
}
6567

66-
log.Printf("Server started, now you can upload files to http://localhost:%s", listenAddr)
68+
endpoint := "http://" + listenAddr
69+
if strings.Index(listenAddr, ":") == 0 {
70+
endpoint = fmt.Sprintf("http://localhost%s", listenAddr)
71+
}
72+
log.Printf("Server started, now you can upload files to %s", endpoint)
6773

6874
// Start the server
6975
return http.Serve(listener, handler)

0 commit comments

Comments
 (0)