Compare commits

..

1 Commits

Author SHA1 Message Date
Thomas Klaehn
ec727efc13 Add camera control
Signed-off-by: Thomas Klaehn <thomas.klaehn@perinet.io>
2025-09-11 08:42:57 +02:00
3 changed files with 28 additions and 19 deletions

View File

@@ -112,9 +112,21 @@ func handle_patch_printerstate(w http.ResponseWriter, r *http.Request) {
return
}
if state.State == StateOn {
octoprint.ReStart()
err = octoprint.ReStart()
if err != nil {
logger.Print(err)
w.WriteHeader(http.StatusInternalServerError)
w.Write(json.RawMessage(fmt.Sprintf(`{"error": "%s"}`, err.Error())))
return
}
} else {
octoprint.Stop()
err := octoprint.Stop()
if err != nil {
logger.Print(err)
w.WriteHeader(http.StatusInternalServerError)
w.Write(json.RawMessage(fmt.Sprintf(`{"error": "%s"}`, err.Error())))
return
}
}
w.WriteHeader(http.StatusOK)
}

View File

@@ -19,7 +19,7 @@ type DockerState struct {
const (
start_cmd = "docker-compose -f /etc/printctrl/octoprint/docker-compose.yml up -d"
stop_cmd = "docker-compose -f /etc/printctrl/octoprint/docker-compose.yml down"
status_cmd = "docker ps -a"
status_cmd = "docker ps"
)
var (
@@ -30,21 +30,22 @@ func init() {
logger.SetFlags(log.Llongfile | log.Ltime)
}
func Start() {
func Start() error {
p := process.NewProcess(start_cmd)
p.Start()
p.Wait()
return p.Start()
}
func Stop() {
func Stop() error {
p := process.NewProcess(stop_cmd)
p.Start()
p.Wait()
return p.Start()
}
func ReStart() {
Stop()
Start()
func ReStart() error {
err := Stop()
if err != nil {
logger.Print(err)
}
return Start()
}
func Status() DockerState {
@@ -57,7 +58,7 @@ func Status() DockerState {
std := <-p.StdoutChannel
if strings.Contains(std, "octoprint/octoprint") {
res := strings.Split(std, " ")
if len(res) < 7 {
if len(res) != 7 {
logger.Printf("Unkown number pf parameters (%d vs. 7)", len(res))
} else {
state.ContainerID = res[0]
@@ -66,11 +67,7 @@ func Status() DockerState {
state.Created = res[3]
state.Status = res[4]
state.Ports = res[5]
if len(res) == 7 {
state.Name = res[6]
} else if len(res) == 9 {
state.Name = res[8]
}
}
}
}

View File

@@ -36,7 +36,7 @@ func main() {
apiservice_printer.AddHandler()
apiservice_relay.AddHandler()
port := ":80"
port := ":8083"
http.Handle("/", http.FileServer(http.Dir(webui_path)))
logger.Fatal(http.ListenAndServe(port, nil))
}