API send Gcode and get back information from console log
Hi, after searching a lot in API documentation, API demo script and the forum my question is still unanswered / have no idea how to do that. What i want to do is to send different GCodes to a printer and get their response from log line. This is not time critical. The sending gcode part works - i can see this in Repetier Server UI > Console. Doing from bash:
CMD='{"cmd":"M552"}' #empty response
source /opt/urlcoder.sh && ENC_CMD=$(urlencode $CMD)
curl "http://localhost:3344/printer/api/myPrinter?apikey=AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEEEE&a=send&data=$ENC_CMD"
But how do i catch the result?
in the UI it prints:
23:47:24.408: Network is enabled, configured IP address: 0.0.0.0, actual IP address: 10.149.10.80
i think it has to be done with the action called "response". Could you please help me with some example? What i want to grab is the actual IP address in this example. And id like to be able to parse other output from other M/G commands later
regards, Mario
Comments
You have 2 possible solution.
Bad solution is to enable logging in frontend and watch all responses for the one you need. This increases traffic and load and is not very elegant.
The better solution is to make the server scan for a special response and send an event with the line content. You can do this in printer configuration->g-codes->advanced. There you define a regular expression to detect your line. If you assign a event name, it will issue an event like other server events just with the name given and the line and matched string of first group as content. Alternatively you can send a gocde in response. But that is the easiest and best way to do it.
If you need to trigger an action you could in this case use the gcode to execute a script and do something with the ip you get as parameter.
A empty line is no issue and gets not executed, but will check why save did not work. Is not supposed to happen.
But otherwise, your solution is a cool example what is possible with a simple script and joining some commands.
Lua is not reachable with @execute - it is more for code you want to run server side. It can e.g. add new api commands or react on events.