Welcome! Log In Create A New Profile

Advanced

Repetier Server API logs me out immediately

Posted by magmabyte 
Repetier Server API logs me out immediately
May 29, 2015 09:15AM
Hey there,

I am trying to use the Repetier Server API for a project. When logging in, the server logs me out immediately:

> {"action": "login", "callback_id": 2, "data": {"rememberMe": true, "login": "delta", "password": "3e87a0f2996c4e4dd53eda8f54f643ad"}}
< {u'callback_id': 2, u'session': u'ZkQl^ha@Ym&jjqgKrtUNmVyMNjf$9j6v', u'data': {u'login': u'delta', u'settings': {}, u'ok': True, u'permissions': 15}}
< {u'callback_id': -1, u'eventList': True, u'data': [{u'data': {}, u'event': u'logout'}, {u'data': {u'login': u'delta', u'settings': {}, u'permissions': 15}, u'event': u'userCredentials'}]}

When deleting any user and sending plain "send" commands, I get this:
> {"action": "send", "callback_id": 2, "printer": "Delta", "data": {"cmd": "G28"}}
< {u'callback_id': 2, u'session': u'Cj$%!&*bb6!fUjvx90kAxa0235%XcIu5', u'data': {}}
> {"action": "send", "callback_id": 3, "printer": "Delta", "data": {"cmd": "G28"}}
< {u'callback_id': -1, u'eventList': True, u'data': [{u'data': {u'login': u'global', u'settings': {u'gcodeViewMode': u'0', u'tempDiagMode': u'0'}, u'permissions': 65535}, u'event': u'userCredentials'}]}

Nothing happens with the printer at any times though I am able to trigger commands via the command line interface of the server. Can you tell me what the problem is?

Regards

Edited 1 time(s). Last edit at 05/29/2015 12:06PM by magmabyte.
Re: Repetier Server API logs me out immediately
May 30, 2015 04:31AM
Okay, it seems to be that despite the event in the event list I am still online and able to send events. As I just realized "'data': {}" is actually the correct response of the server to "send" commands. These events I get both when no user is defined or an user is defined I am logged in and I am sending "send" commands. However, the printer is unaffected. I am wondering whether "G28" is a valid G-Code command to send with the API. As I mentioned, I am able to execute it in the web interface.

Logging in as "delta":
> {"action": "login", "callback_id": 2, "data": {"login": "delta", "password": "fe46844b93ad908aaa0cbfd967b6594f"}}
< {u'callback_id': 2, u'session': u'gpaJoZ^hOq1SuMc@eLykDajVK8W8xdAj', u'data': {u'login': u'delta', u'settings': {}, u'ok': True, u'permissions': 15}}
> {"action": "send", "callback_id": 3, "printer": "Delta", "data": {"cmd": "G28"}}
< {u'callback_id': -1, u'eventList': True, u'data': [{u'data': {}, u'event': u'logout'}, {u'data': {u'login': u'delta', u'settings': {}, u'permissions': 15}, u'event': u'userCredentials'}]}
< {u'callback_id': 3, u'session': u'gpaJoZ^hOq1SuMc@eLykDajVK8W8xdAj', u'data': {}}

Not logging in with user "delta" defined:
{"action": "send", "callback_id": 2, "printer": "Delta", "data": {"cmd": "G28"}}
{u'callback_id': 2, u'session': u'8$JXMTtuLmRDCzzmetuAQp9#bb$t3dkj', u'data': {u'permissionDenied': True}}
Re: Repetier Server API logs me out immediately
May 30, 2015 05:23AM
Somehow it stopped working when users are required to log in. I have updated it so it now works with login as well.

It's a bit tricky as you can get a permissionDenied at the beginning which you need to catch especially if you have already send a login request ignore all permission denied until the callback id of the login is handled. See demo code what I mean.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Repetier Server API logs me out immediately
May 30, 2015 06:04AM
Somehow it stopped working when users are required to log in. I have updated it so it now works with login as well.


Quote
repetier
See demo code what I mean.
What do you mean by demo? I am using the current Windows version at [www.repetier-server.com]. My references were [www.repetier-server.com] and [github.com]. I can not find a demo besides the API examples.

Quote
repetier
It's a bit tricky as you can get a permissionDenied at the beginning which you need to catch especially if you have already send a login request ignore all permission denied until the callback id of the login is handled.
permissionDenied seems to work fine. I get the event only when I am not logged in, even after the logout event. Does the logout event have any relevance? I seem to be logged in still. I get
{u'callback_id': -1, u'eventList': True, u'data': [{u'data': {}, u'event': u'logout'}, {u'data': {u'login': u'delta', u'settings': {}, u'permissions': 15}, u'event': u'userCredentials'}]}
from the server (logout in an eventList) after I send to the server the login request
{"action": "login", "callback_id": 2, "data": {"login": "delta", "password": "fe46844b93ad908aaa0cbfd967b6594f"}}

Also, do you have any idea why can't execute the simple "G28" command when sending "send" and receiving "'data': {}"? According to the API it is the correct response?
Re: Repetier Server API logs me out immediately
May 30, 2015 06:25AM
With demo I thought you were using the testing application at the bottom of the api documentation:

[www.repetier-server.com]

which you can use for testing. Works really good and is helpfull if you are not sure what to expect. Use it myself from time to time.

logout event comes when you send a logout command to server. Then it resets the associated user to none. Do you send a logout before login?

On action send with {"cmd":"G28" } you get only a empty response that is correct. You never see any answers from the firmware. These go into state and get reported there.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Repetier Server API logs me out immediately
May 30, 2015 07:51AM
Okay, currently I do not have access to the printer. I will try again on Monday. Sadly, I have changed nothing and I don't really know what the problem is.

I am able to successfully execute "send" commands in the console of the server's web GUI but not via the API and my Python client (I can send them and get a response but the printer is unaffected). Hopefully, it works with the Demo (any other command that I tried seems to work but these work also with my Python client) and I will check whether it does anything different. Is there any other way to send G-Code to the printer, perhaps via uploading and executing files?

The demo I downloaded seemed to be missing the "https:" for the jquery libraries.

Edited 1 time(s). Last edit at 05/30/2015 07:52AM by magmabyte.
Re: Repetier Server API logs me out immediately
May 30, 2015 08:45AM
https was in deed missing. Strangely it worked anyway :-) Clever chrome seems to have fixed it.

The Web UI also uses send for homing so there is no reason why it should not work except perhaps a spelling error. You can open console with send commands enabled and see if the server sees you G28. If you see it there and printer does not react let me know.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Repetier Server API logs me out immediately
June 01, 2015 07:13AM
Didn't work for me with Chromium. winking smiley

Okay, so I tried both the Demo and my code again. Neither worked. Send in the Python code looks like this: {"action": "send", "callback_id": 2, "printer": "Delta", "data": {"cmd": "G28"}}. For Send in the demo I typed "send" for Action and {"cmd": "G28"} for JSON payload. I can send other commands with my Python code and the Demo.

As you said and as far as I can tell your Web API does the same thing (there I just typed "G28" in the console). Could this be some kind of security feature? Do you know of a convient way to debug Websockets?
Re: Repetier Server API logs me out immediately
June 01, 2015 07:22AM
The only security that might be there is if your user has no print permission.

Since it works from normal frontend debug there what to send. All you need to do is open debugger in chrom and select the socket file in network tab (reload for it to appear) and go to preview I think it is. Then you see a nice list of commands send and received. Everything is json so it is easy to read, Then send G28 from there and see what the package contains.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Repetier Server API logs me out immediately
June 01, 2015 08:20AM
When I finally found the window with the Websocket traffic (it was hidden and I had to slide down a slider to find it...), I saw that the printer had a different name internally than I specified. There it is called "Delta2" and not "Delta".

I saw the string before when using "listPrinter" but I didn't think about trying it out with this printer name.

Your demo also didn't list "Delta2" (and it sends {"action":"send","data":{"cmd":"M119"},"printer":"","callback_id":778}). This is such a stupid problem but I am happy it finally works. Thanks!

Edited 1 time(s). Last edit at 06/01/2015 08:21AM by magmabyte.
Re: Repetier Server API logs me out immediately
June 01, 2015 08:32AM
Yes, you always need to use the slug name for every action. It has no spaces etc. and stays the same even if you rename the printer. listPrinter lists all names along with internal slug name.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Sorry, only registered users may post in this forum.

Click here to login