Live gcode sending
Hi,
I am trying to send xyze coordinates from a custom python app to my repetier server.
The idea is to perform "live plotting", which involves sending mouse coordinates to the server at a frequency of 60fps. So that's a ton of commands to process..
So I have read the Websocket API, and so far I can successfully send both 'send' actions and 'move' actions. I understood 'send' action is not designed to be queued like that, but it is working fine with the 'move' action.
The problem I am facing is that it takes about 2 sec to process each new command, and I need it the to be the fastest possible.
My code structure looks like this:
My code structure looks like this:
import subprocess import json import urllib.parse #### coords = {"x":x, "y":y, "z":z, "e":e, "speed":speed} # new coords sent at 60fps
# format dict into json
jsonparams = json.dumps(coords)
# encode json as a proper url
data = str(jsonparams).encode("utf-8")
data = urllib.parse.quote(data)
data = data.replace('%27', '%22')
# make the curl command
curl = f'curl.exe {host}/printer/api/{slug}?apikey={api}&a=move&data={data}'
# send command to server
subprocess.run(curl, capture_output=False, text=True)
Do you have any suggestion ?
Any help would be very appreciated!
Edit: Well I think I found out... I am not using the right tool, and like so I am reopening a socket each time. So i need to use Websockets like so: ws://localhost:3344/socket/?lang=<Language ID>&sess=<session id>
I'll post a better answer later on!
Edit: Well I think I found out... I am not using the right tool, and like so I am reopening a socket each time. So i need to use Websockets like so: ws://localhost:3344/socket/?lang=<Language ID>&sess=<session id>
I'll post a better answer later on!
Comments
Reason you are so slow is you start an external program curl.exe instead of using a direct communication with python. Alway starting curl.exe as external process needs a lot of time.
Thanks for the advice, I have been trying to implement websockets this week-end. It is a hard topic to me, I am making very slow progress... I got stuck on something, but I am not even sure I am going in the right direction.
But is it what I should do ?
thasor
You should search the forum. I'm quite sure there was soneone presenting a free library to communicate with python. Or google it.
Thanks you for your help :-)