From 1184d67315f2f967aa3c4b75f109efffedad9361 Mon Sep 17 00:00:00 2001 From: JeffB42 <10328858+JeffB42@users.noreply.github.com> Date: Sun, 28 Mar 2021 10:40:08 -0700 Subject: [PATCH 01/10] added aditional logging to doRequest() --- octoprintApis/client.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/octoprintApis/client.go b/octoprintApis/client.go index 9fed9455..9e29ef64 100755 --- a/octoprintApis/client.go +++ b/octoprintApis/client.go @@ -81,10 +81,13 @@ func (this *Client) doRequest( ) ([]byte, error) { logger.TraceEnter("Client.doRequest()") logger.Debugf("method: %s", method) - logger.Debugf("target: %s",target) + logger.Debugf("target: %s", target) + logger.Debugf("contentType: %s", contentType) + url := joinUrl(this.Endpoint, target) + logger.Debugf("url: %s", url) - req, err := http.NewRequest(method, joinUrl(this.Endpoint, target), body) + req, err := http.NewRequest(method, url, body) if err != nil { logger.LogError("Client.doRequest()", "http.NewRequest()", err) logger.TraceLeave("Client.doRequest()") @@ -93,12 +96,19 @@ func (this *Client) doRequest( req.Header.Add("Host", "localhost:5000") req.Header.Add("Accept", "*/*") - req.Header.Add("User-Agent", fmt.Sprintf("go-octoprint/%s", Version)) + + userAgent := fmt.Sprintf("go-octoprint/%s", Version) + logger.Debugf("userAgent: %s", userAgent) + req.Header.Add("User-Agent", userAgent) + if contentType != "" { req.Header.Add("Content-Type", contentType) } + // Don't log APIKey due to privacy & security. + // logger.Debugf("API key: %s", this.APIKey) req.Header.Add("X-Api-Key", this.APIKey) + resp, err := this.httpClient.Do(req) if err != nil { logger.LogError("Client.doRequest()", "this.httpClient.Do()", err) From 10465926aee181622f43ec58f8bbe6192f50d438 Mon Sep 17 00:00:00 2001 From: JeffB42 <10328858+JeffB42@users.noreply.github.com> Date: Sun, 28 Mar 2021 10:49:49 -0700 Subject: [PATCH 02/10] added a pause of 5 seconds in OctoScreenSettingsRequest.Do() to prevent plug-in loading bug --- octoprintApis/OctoScreenSettingsRequest.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/octoprintApis/OctoScreenSettingsRequest.go b/octoprintApis/OctoScreenSettingsRequest.go index 0ca89741..fb12473b 100755 --- a/octoprintApis/OctoScreenSettingsRequest.go +++ b/octoprintApis/OctoScreenSettingsRequest.go @@ -3,6 +3,7 @@ package octoprintApis import ( "encoding/json" "fmt" + "time" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" ) @@ -16,6 +17,12 @@ type OctoScreenSettingsRequest struct { } func (this *OctoScreenSettingsRequest) Do(client *Client, uiState string) (*dataModels.OctoScreenSettingsResponse, error) { + // Pause for 5 seconds here. This is in response to the "OctoScreen 2.7.0 doesn't recognize that OctoScreen plugin 2.6.0 is installed" + // bug (see https://github.com/Z-Bolt/OctoScreen/issues/275). I was able to repro the bug sometimes, yet other times it worked fine. + // I examined the logs and they were exactly the same (up to the error, which was "HTTP/1.x transport connection broken: malformed MIME + // header line: Not found"). Very weird. + time.Sleep(time.Second * 5) + target := fmt.Sprintf("%s?command=get_settings", PluginZBoltOctoScreenApiUri) bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors) if err != nil { From 0aae301ee8db006ecae4e368f41ae8dd4696ec6f Mon Sep 17 00:00:00 2001 From: JeffB42 <10328858+JeffB42@users.noreply.github.com> Date: Sun, 28 Mar 2021 11:04:44 -0700 Subject: [PATCH 03/10] updated version number to 2.7.1 --- Makefile | 2 +- ui/CommonPanel.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 40509c73..8b525719 100755 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ JESSIE_GO_TAGS := gtk_3_14 # Build information #GIT_COMMIT = $(shell git rev-parse HEAD | cut -c1-7) -VERSION := 2.7.0 +VERSION := 2.7.1 BUILD_DATE ?= $(shell date --utc +%Y%m%d-%H:%M:%S) #BRANCH = $(shell git rev-parse --abbrev-ref HEAD) diff --git a/ui/CommonPanel.go b/ui/CommonPanel.go index 0dd2a122..95815c0e 100755 --- a/ui/CommonPanel.go +++ b/ui/CommonPanel.go @@ -16,7 +16,7 @@ import ( ) // OctoScreenVersion - set at compilation time. -var OctoScreenVersion = "2.7.0" +var OctoScreenVersion = "2.7.1" type CommonPanel struct { UI *UI From f1a3ad23c43bb8b78e42ebe6e943af6bd1fb8b49 Mon Sep 17 00:00:00 2001 From: JeffB42 <10328858+JeffB42@users.noreply.github.com> Date: Sun, 28 Mar 2021 11:25:35 -0700 Subject: [PATCH 04/10] changed the trottle from 5 sec to 2 sec, and updated the comment --- octoprintApis/OctoScreenSettingsRequest.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/octoprintApis/OctoScreenSettingsRequest.go b/octoprintApis/OctoScreenSettingsRequest.go index fb12473b..52dac9f5 100755 --- a/octoprintApis/OctoScreenSettingsRequest.go +++ b/octoprintApis/OctoScreenSettingsRequest.go @@ -17,11 +17,11 @@ type OctoScreenSettingsRequest struct { } func (this *OctoScreenSettingsRequest) Do(client *Client, uiState string) (*dataModels.OctoScreenSettingsResponse, error) { - // Pause for 5 seconds here. This is in response to the "OctoScreen 2.7.0 doesn't recognize that OctoScreen plugin 2.6.0 is installed" - // bug (see https://github.com/Z-Bolt/OctoScreen/issues/275). I was able to repro the bug sometimes, yet other times it worked fine. + // Pause for 2 seconds here. This is in response to the "OctoScreen 2.7.0 doesn't recognize that OctoScreen plugin 2.6.0 is installed" + // bug (see https://github.com/Z-Bolt/OctoScreen/issues/275). I was able to repro the bug sometimes, yet other times this worked fine. // I examined the logs and they were exactly the same (up to the error, which was "HTTP/1.x transport connection broken: malformed MIME - // header line: Not found"). Very weird. - time.Sleep(time.Second * 5) + // header line: Not found"). This might not be an issue after the state machine rewrite in 2.8. + time.Sleep(time.Second * 2) target := fmt.Sprintf("%s?command=get_settings", PluginZBoltOctoScreenApiUri) bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors) From 30ff9c3ea0b64031f25842ccf1133c11d8febe68 Mon Sep 17 00:00:00 2001 From: JeffB42 <10328858+JeffB42@users.noreply.github.com> Date: Sun, 28 Mar 2021 12:11:20 -0700 Subject: [PATCH 05/10] added SelectTool(), also refacted code into functions with a similar format --- utils/filament.go | 53 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/utils/filament.go b/utils/filament.go index a2145fc4..397dc329 100755 --- a/utils/filament.go +++ b/utils/filament.go @@ -32,28 +32,36 @@ func Extrude( return } - logger.Infof("filament.Extrude() - setting flow rate percentage of %d", flowRatePercentage) - if err := SetFlowRate(client, flowRatePercentage); err != nil { - logger.LogError("filament.Extrude()", "SetFlowRate()", err) + if err := SelectTool(client, extruderId); err != nil { // TODO: display error? return } - cmd := &octoprintApis.ToolExtrudeRequest{} - if isForward { - cmd.Amount = length - } else { - cmd.Amount = -length + if err := SetFlowRate(client, flowRatePercentage); err != nil { + // TODO: display error? + return } - logger.Infof("filament.Extrude() - sending extrude request with length of: %d", cmd.Amount) - if err := cmd.Do(client); err != nil { - logger.LogError("filament.Extrude()", "Do(ToolExtrudeRequest)", err) + if err := SendExtrudeRrequest(client, isForward, length); err != nil { // TODO: display error? - return } } +func SelectTool( + client *octoprintApis.Client, + extruderId string, +) error { + cmd := &octoprintApis.ToolSelectRequest{} + cmd.Tool = extruderId + + logger.Infof("filament.SelectTool() - changing tool to %s", cmd.Tool) + if err := cmd.Do(client); err != nil { + logger.LogError("filament.SelectTool()", "Go(ToolSelectRequest)", err) + return err + } + + return nil +} func SetFlowRate( client *octoprintApis.Client, @@ -70,3 +78,24 @@ func SetFlowRate( return nil } + +func SendExtrudeRrequest( + client *octoprintApis.Client, + isForward bool, + length int, +) error { + cmd := &octoprintApis.ToolExtrudeRequest{} + if isForward { + cmd.Amount = length + } else { + cmd.Amount = -length + } + + logger.Infof("filament.SendExtrudeRrequest() - sending extrude request with length of: %d", cmd.Amount) + if err := cmd.Do(client); err != nil { + logger.LogError("filament.Extrude()", "Do(ToolExtrudeRequest)", err) + return err + } + + return nil +} From 2fad643c00efc35d0c8c086bac522974c6d3e547 Mon Sep 17 00:00:00 2001 From: JeffB42 <10328858+JeffB42@users.noreply.github.com> Date: Mon, 29 Mar 2021 22:54:19 -0700 Subject: [PATCH 06/10] reverted call to Sleep() --- octoprintApis/OctoScreenSettingsRequest.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/octoprintApis/OctoScreenSettingsRequest.go b/octoprintApis/OctoScreenSettingsRequest.go index 52dac9f5..0ca89741 100755 --- a/octoprintApis/OctoScreenSettingsRequest.go +++ b/octoprintApis/OctoScreenSettingsRequest.go @@ -3,7 +3,6 @@ package octoprintApis import ( "encoding/json" "fmt" - "time" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" ) @@ -17,12 +16,6 @@ type OctoScreenSettingsRequest struct { } func (this *OctoScreenSettingsRequest) Do(client *Client, uiState string) (*dataModels.OctoScreenSettingsResponse, error) { - // Pause for 2 seconds here. This is in response to the "OctoScreen 2.7.0 doesn't recognize that OctoScreen plugin 2.6.0 is installed" - // bug (see https://github.com/Z-Bolt/OctoScreen/issues/275). I was able to repro the bug sometimes, yet other times this worked fine. - // I examined the logs and they were exactly the same (up to the error, which was "HTTP/1.x transport connection broken: malformed MIME - // header line: Not found"). This might not be an issue after the state machine rewrite in 2.8. - time.Sleep(time.Second * 2) - target := fmt.Sprintf("%s?command=get_settings", PluginZBoltOctoScreenApiUri) bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors) if err != nil { From 5092ddea7512cf6121a5b4df1a5618d129709efe Mon Sep 17 00:00:00 2001 From: JeffB42 <10328858+JeffB42@users.noreply.github.com> Date: Mon, 29 Mar 2021 22:55:39 -0700 Subject: [PATCH 07/10] changed order in which loadSettings() is called --- ui/ui.go | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/ui/ui.go b/ui/ui.go index 0276fc6f..a753045a 100755 --- a/ui/ui.go +++ b/ui/ui.go @@ -171,6 +171,10 @@ func (this *UI) verifyConnection() { this.ConnectionState = connectionResponse.Current.State newUIState, splashMessage = this.getUiStateAndMessageFromConnectionResponse(connectionResponse, newUIState, splashMessage) + + if this.Settings == nil { + this.loadSettings() + } } else { logger.LogError("ui.verifyConnection()", "Broke into the else condition because Do(ConnectionRequest) returned an error", err) newUIState, splashMessage = this.getUiStateAndMessageFromError(err, newUIState, splashMessage) @@ -341,6 +345,12 @@ func (this *UI) checkNotification() { func (this *UI) loadSettings() { logger.TraceEnter("ui.loadSettings()") + if this.Settings != nil { + logger.Error("ui.loadSettings() - this.Settings has already been set") + logger.TraceLeave("ui.loadSettings()") + return + } + settingsResponse, err := (&octoprintApis.OctoScreenSettingsRequest{}).Do(this.Client, this.UIState) if err != nil { text := err.Error() @@ -355,19 +365,26 @@ func (this *UI) loadSettings() { } this.OctoPrintPluginIsAvailable = false - - logger.TraceLeave("ui.loadSettings()") - return + // Use default settings + this.Settings = &dataModels.OctoScreenSettingsResponse { + FilamentInLength: 100, + FilamentOutLength: 100, + ToolChanger: false, + XAxisInverted: false, + YAxisInverted: false, + ZAxisInverted: false, + MenuStructure: nil, + } } else { logger.Info("The call to GetSettings succeeded and the OctoPrint plug-in is available") this.OctoPrintPluginIsAvailable = true - } - if !this.validateMenuItems(settingsResponse.MenuStructure, "", true) { - settingsResponse.MenuStructure = nil - } + if !this.validateMenuItems(settingsResponse.MenuStructure, "", true) { + settingsResponse.MenuStructure = nil + } - this.Settings = settingsResponse + this.Settings = settingsResponse + } logger.TraceLeave("ui.loadSettings()") } @@ -425,7 +442,7 @@ func (this *UI) update() { logger.TraceEnter("ui.update()") this.sdNotify(daemon.SdNotifyWatchdog) - + if this.connectionAttempts > 8 { logger.Info("ui.update() - this.connectionAttempts > 8") this.splashPanel.putOnHold() @@ -442,28 +459,12 @@ func (this *UI) update() { this.connectionAttempts = 0 } - if this.Settings == nil { - this.loadSettings() - - if this.Settings == nil { - this.Settings = &dataModels.OctoScreenSettingsResponse { - FilamentInLength: 100, - FilamentOutLength: 100, - ToolChanger: false, - XAxisInverted: false, - YAxisInverted: false, - ZAxisInverted: false, - MenuStructure: nil, - } - } - } + this.verifyConnection() if this.OctoPrintPluginIsAvailable { this.checkNotification() } - this.verifyConnection() - logger.TraceLeave("ui.update()") } From 9c1fe2c1ae1e6f7578f6ebe29091bbba3dd25953 Mon Sep 17 00:00:00 2001 From: JeffB42 <10328858+JeffB42@users.noreply.github.com> Date: Sat, 3 Apr 2021 08:41:01 -0700 Subject: [PATCH 08/10] changed log message to use LogError() --- ui/HttpRequestTestWindow.go | 2 +- ui/ui.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/HttpRequestTestWindow.go b/ui/HttpRequestTestWindow.go index e4bc00ba..2fb30845 100755 --- a/ui/HttpRequestTestWindow.go +++ b/ui/HttpRequestTestWindow.go @@ -135,7 +135,7 @@ func (this *HttpRequestTestWindow) sdNotify(state string) { _, err := daemon.SdNotify(false, state) if err != nil { - logger.Errorf("sdNotify()", "SdNotify()", err) + logger.LogError("sdNotify()", "daemon.SdNotify()", err) logger.TraceLeave("sdNotify()") return } diff --git a/ui/ui.go b/ui/ui.go index a753045a..a60be6ee 100755 --- a/ui/ui.go +++ b/ui/ui.go @@ -164,7 +164,7 @@ func (this *UI) verifyConnection() { logger.Debug("ui.verifyConnection() - ConnectionRequest.Do() succeeded") jsonResponse, err := utils.StructToJson(connectionResponse) if err != nil { - logger.Debug("ui.verifyConnection() - utils.StructToJson() failed") + logger.LogError("ui.verifyConnection()", "utils.StructToJson()", err) } else { logger.Debugf("ui.verifyConnection() - connectionResponse is: %s", jsonResponse) } From 91eb5fc60dffa57bf4b35b4bcf4148538009c36e Mon Sep 17 00:00:00 2001 From: JeffB42 <10328858+JeffB42@users.noreply.github.com> Date: Sat, 3 Apr 2021 08:42:03 -0700 Subject: [PATCH 09/10] bumped version to 2.7.1 --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3b0c3bab..a42476d1 100755 --- a/README.md +++ b/README.md @@ -83,15 +83,15 @@ There are two ways to install OctoScreen: the recommended and supported way is t For example, to install on a new RaspberryPi with OctoPi: ```sh -wget https://github.com/Z-Bolt/OctoScreen/releases/download/2.6.1/octoscreen_2.6.1_armhf.deb -sudo dpkg -i octoscreen_2.6.1_armhf.deb +wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.1/octoscreen_2.7.1_armhf.deb +sudo dpkg -i octoscreen_2.7.1_armhf.deb ``` Or to update an existing version of OctoScreen: ```sh -wget https://github.com/Z-Bolt/OctoScreen/releases/download/2.6.1/octoscreen_2.6.1_armhf.deb +wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.1/octoscreen_2.7.1_armhf.deb sudo dpkg -r octoscreen -sudo dpkg -i octoscreen_2.6.1_armhf.deb +sudo dpkg -i octoscreen_2.7.1_armhf.deb sudo reboot now ``` From 2f67f647c7def36d735d48a4ff63994365847ef1 Mon Sep 17 00:00:00 2001 From: JeffB42 <10328858+JeffB42@users.noreply.github.com> Date: Sat, 3 Apr 2021 08:44:14 -0700 Subject: [PATCH 10/10] updated the cmd.Confirm condition to include a prompt --- uiWidgets/SystemCommandButton.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uiWidgets/SystemCommandButton.go b/uiWidgets/SystemCommandButton.go index 134a5d37..a1865a2c 100755 --- a/uiWidgets/SystemCommandButton.go +++ b/uiWidgets/SystemCommandButton.go @@ -51,7 +51,7 @@ func CreateSystemCommandButton( confirmationMessage := "" if len(cmd.Confirm) != 0 { - confirmationMessage = cmd.Confirm + confirmationMessage = fmt.Sprintf("%s\n\nDo you wish to proceed?", cmd.Confirm) } else if len(name) != 0 { confirmationMessage = fmt.Sprintf("Do you wish to %s?", name) } else {