Trying to make my silly project on getting GCODE messages outputted to my terminal window without GUI in place, so doing this from the thin python client and command line.
I managed to get the REST API working with some status messages included such as bed temps etc, just to prove that it works.
Next got a websocket connected and just wanted to confirm it doesn't seem to have an authentication at all? Right now it keeps things simple, but in the future at least 2-way communication I guess needs to have authentication, if this was not meant to be more for plugin injector or similar.
I'm having hard time finding though where to place hooks to get the terminal messages visible? API docs talk very little about this and I would be happy to contribute if needed.
Thanks again in advance for all the help. This community is awesome here.
I'm probably misunderstanding some part here, but if you only want to get the terminal messages via websocket, you don't need any hooks server-side. That information is already in the websocket messages.
So once you have established the websocket connection, you need to check for event that have a "current" property on the payload. There you'll find a logs property which contains the terminal messages since the last websocket event, as far as I understand.
This is an adapted version of my own function that extracts some information from the websocket:
private handleMessage(event: MessageEvent) {
if (event.data.startsWith("a")) {
var payload = JSON.parse(event.data.slice(1));
if (payload.length === 1 && payload[0].current) {
const data = payload[0].current;
// terminal messages would be here:
const messages = data.logs;
console.log(messages);
}
}
}
Thanks Fabian. I am using Python websockets and upon connect I get one message, but nothing further. Not sure if I should automatically be subscribed to all GCODE messages as well:
I suspect that the missing authentication is the reason you only get one message (see http://docs.octoprint.org/en/master/api/push.html). I'm experimenting with an Octoprint instance without any authentication right now, so I haven't looked at that part in detail yet.
I think has been changed at some point, since after returning to my project I've no longer getting the GCODE messages. Just in case someone is wondering about this example here.
I'll contact the development team for further info.
And your authenticating to create the session key?
The auth message expects the user id of the user to authenticate followed by : and a session key to be obtained from the successful payload of a (passive or active) login via the API.