Skip to content

Commit

Permalink
The OctoPrint server is simulated. See -octoprint
Browse files Browse the repository at this point in the history
  • Loading branch information
macdylan committed Apr 17, 2023
1 parent 6d93264 commit f5ae9f1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A command-line tool for send the gcode file to Snapmaker Printers via WiFi conne
## Features:
- Support Snapmaker 2 A150/250/350, J1, Artisan
- Auto discover machines (UDP broadcast)
- Simulated a OctoPrint server, so that it can be in any slicing software such as Cura/PrusaSlicer/SuperSlicer/ideaMaker send gcode to the printer
- No need to click Yes button on the touch screen every time for authorization connect
- Support for multiple platforms including win/macOS/Linux/RaspberryPi

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

```
## Discover mode
$ sm2uploader /path/to/code-file1 /path/to/code-file2
Discovering ...
Use the arrow keys to navigate: ↓ ↑ → ←
? Found 2 machines:
? Found 3 machines:
▸ A350-3DP@192.168.1.20 - Snapmaker A350
A250-CNC@192.168.1.18 - Snapmaker A250
J1V19@192.168.1.19 - Snapmaker-J1
Printer IP: 192.168.1.20
Printer IP: 192.168.1.19
Printer Model: Snapmaker J1
Uploading file 'code-file1' [1.2 MB]...
- SACP sending 100%
Upload finished.
## Directly mode
$ sm2uploader -host 192.168.1.19 /path/to/code-file1 /path/to/code-file2
Printer IP: 192.168.1.19
Printer Model: Snapmaker J1
Uploading file 'code-file1' [1.2 MB]...
- SACP sending 100%
Upload finished.
## use printer id
$ sm2uploader -host J1V19 /path/to/code-file1 /path/to/code-file2
Discovering ...
Printer IP: 192.168.1.19
Printer Model: Snapmaker J1
Uploading file 'code-file1' [1.2 MB]...
- SACP sending 100%
Upload finished.
## OctoPrint server (CTRL-C to stop)
$ sm2uploader -octoprint :8844 -host A350
Printer IP: 192.168.1.20
Printer Model: Snapmaker 2 Model A350
Starting OctoPrint server on :8844 ...
Server started, now you can upload files to http://localhost:8844
Request GET /api/version completed in 6.334µs
- HTTP sending 100.0%
Upload finished: model.gcode [382.2 KB]
Request POST /api/files/local completed in 951.080458ms
...
```

If UDP Discover can not work, use `sm2uploader -host 192.168.1.20 /file.gcode` to directly upload to printer.
Expand Down
43 changes: 37 additions & 6 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Luban 和 Cura with SnapmakerPlugin 对于新手很友好,但是我的大部
## 功能
- 支持 Snapmaker 2 A/J1/Artisan 全系列打印机
- 自动发现局域网内所有的 Snapmaker 打印机(和 Luban 相同的协议,使用 UDP 广播)
- 模拟 OctoPrint Server,这样就可以在各种切片软件,比如 Cura/PrusaSlicer/SuperSlicer/ideaMaker 中向 Snapmaker 打印机发送文件
- Snapmaker 2 A-Series 第一次连接时需要授权,之后可以直接一步上传
- 支持 macOS/Windows/Linux/RaspberryPi 多个平台

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

```
## 自动查找模式
$ sm2uploader /path/to/code-file1 /path/to/code-file2
Discovering ...
Use the arrow keys to navigate: ↓ ↑ → ←
? Found 2 machines:
▸ A350-3DP@192.168.1.20 - Snapmaker 2 Model A350
A250-CNC@192.168.1.18 - Snapmaker 2 Model A250
J1V19@192.168.1.19 - Snapmaker J1
Printer IP: 192.168.1.20
? Found 3 machines:
▸ A350-3DP@192.168.1.20 - Snapmaker A350
A250-CNC@192.168.1.18 - Snapmaker A250
J1V19@192.168.1.19 - Snapmaker-J1
Printer IP: 192.168.1.19
Printer Model: Snapmaker J1
Uploading file 'code-file1' [1.2 MB]...
- SACP sending 100%
Upload finished.
## 指定 IP 连接模式
$ sm2uploader -host 192.168.1.19 /path/to/code-file1 /path/to/code-file2
Printer IP: 192.168.1.19
Printer Model: Snapmaker J1
Uploading file 'code-file1' [1.2 MB]...
- SACP sending 100%
Upload finished.
## 指定打印机名字进行连接
$ sm2uploader -host J1V19 /path/to/code-file1 /path/to/code-file2
Discovering ...
Printer IP: 192.168.1.19
Printer Model: Snapmaker J1
Uploading file 'code-file1' [1.2 MB]...
- SACP sending 100%
Upload finished.
## 模拟 OctoPrint (CTRL-C 终止运行)
$ sm2uploader -octoprint :8844 -host A350
Printer IP: 192.168.1.20
Printer Model: Snapmaker 2 Model A350
Starting OctoPrint server on :8844 ...
Server started, now you can upload files to http://localhost:8844
Request GET /api/version completed in 6.334µs
- HTTP sending 100.0%
Upload finished: model.gcode [382.2 KB]
Request POST /api/files/local completed in 951.080458ms
...
```

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

也可以直接在终端执行 `xattr -d com.apple.quarantine sm2uploader-darwin`
也可以直接在终端执行 `xattr -d com.apple.quarantine sm2uploader-darwin`
8 changes: 7 additions & 1 deletion octoprint.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"fmt"
"io"
"log"
"net"
"net/http"
"strings"
"time"
)

Expand Down Expand Up @@ -63,7 +65,11 @@ func startOctoPrintServer(listenAddr string, printer *Printer) error {
return err
}

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

// Start the server
return http.Serve(listener, handler)
Expand Down

0 comments on commit f5ae9f1

Please sign in to comment.