Nico111
(Nico F.)
December 8, 2018, 6:51pm
1
So I have following code to send gcode to my ender 3:
rule "POST System Kommando"
when
Item OctoprintPrinterCommand received update
then
var String PrinterCmd = OctoprintPrinterCommand.state.toString()
var url = "http://octopi/api/job?apikey=`XXXXXXXXXXXXXXX"
var contenttype = "application/json"
var POSTrequest = '{"command":"'+PrinterCmd+'"}'
logInfo(filename, "Ender3 kompiliert GCode: " + PrinterCmd )
var output = sendHttpPostRequest(url, contenttype, POSTrequest)
logInfo(filename, output);
end
the json api looks like this:
But the logs are showing the following when I do a HTTP post with “G28” (Auto home) to my printer:
2018-12-08 19:48:11.203 [INFO ] [arthome.model.script.Octoprint.rules] - Ender3 kompiliert GCode: G28
2018-12-08 19:48:11.262 [INFO ] [arthome.model.script.Octoprint.rules] - Expected valid command
Is my syntax incorrect ? Does the command maybe need to have those
inverted commas (")? if yes - how do I type them, without comment out my Code?
Dim
(Angelos)
December 8, 2018, 7:28pm
2
I think? that you need to add double quotes to your POSTrequest (and maybe escape the double quotes within the content also)
try this:
var POSTrequest = "{\"command\":\"+PrinterCmd+\"}"
see example here: JSONPATH updating Item state - #11 by Udo_Hartmann
edit: you many need to play with single and double quotes to get the PrinterCmd
working… my proposal may not pull correctly the PrinterCmd
var… I have to re-think the syntax
1 Like
Nico111
(Nico F.)
December 8, 2018, 7:29pm
3
thank you!
give me a second
1 Like
Nico111
(Nico F.)
December 8, 2018, 7:37pm
4
new Code:
var POSTestRequest = "{\"command\":\"+PrinterCmd+\"}"
logInfo(filename, "Ender3 kompiliert GCode: " + PrinterCmd )
logInfo(filename, POSTestRequest)
//Antwort der API
var output = sendHttpPostRequest(url, contenttype, POSTestRequest)
logInfo(filename, output);
Output:
2018-12-08 20:32:35.921 [INFO ] [arthome.model.script.Octoprint.rules] - Ender3 kompiliert GCode: G28
2018-12-08 20:32:35.936 [INFO ] [arthome.model.script.Octoprint.rules] - {"command":"+PrinterCmd+"}
2018-12-08 20:32:36.004 [INFO ] [arthome.model.script.Octoprint.rules] - Expected valid command
still the same behaviour…
If it helps, the old Code gave out the following
var POSTrequest = '{"command":"'+PrinterCmd+'"}':
2018-12-08 20:31:39.052 [INFO ] [arthome.model.script.Octoprint.rules] - {"command":"G28"}
Dim
(Angelos)
December 8, 2018, 7:55pm
5
I don’t understand why your original rule is not working…
I checked 3D Printer Status and Commands from/to Octoprint via HTTP REST API also and I see that your syntax is correct. It seems that you don’t need the double quotes…
I am going to try to reproduce this on my system for deeper validation and let you know what I find.
1 Like
vzorglub
(Vincent Regaud)
December 8, 2018, 9:04pm
6
@Nico111
Could you please ensure that you select a category for your posts?
Thanks
Nico111
(Nico F.)
December 8, 2018, 9:55pm
7
I would be really grateful, if you take the time to do this
Thank you alot!
Yes, sorry!
namraccr
(namraccr)
December 8, 2018, 10:53pm
8
var POSTestRequest = "{\"command\":\"+PrinterCmd+\"}"
I think that should be
var POSTestRequest = "{\"command\":\"" + PrinterCmd + "\"}"
2 Likes
Nico111
(Nico F.)
December 9, 2018, 9:46am
9
still getting:
2018-12-09 10:45:12.067 [INFO ] [arthome.model.script.Octoprint.rules] - {"command":"G28"}
2018-12-09 10:45:12.146 [INFO ] [arthome.model.script.Octoprint.rules] - Expected valid command
this is weird, the syntax should be correct …
Nico111
(Nico F.)
May 16, 2019, 10:18am
11
Hey,
are you referencing a Epson printer?
I was talking about my ender 3, and everything worked in the end
rossko57
(Rossko57)
May 16, 2019, 11:46am
12
I think it just wants you to click its link
many times is happening with my HP printer that printer is connected with the devices but HP printer not printing . printer not printing anything so that reasons could be anything. there is a basic mistake that we made so the occurred these issues, I know about the all basic factors from the HP tech support.