"Pause and Resume" Printer with Light Sensor Data

Hello! 

I am pretty new to messing around with 3d printers, but that's what I need to do... So please help me out here!

I am working on a project where I control a 3d printer with Repetier connected through a USB and what I need to do is sending commands to pause and resume a printer based on sensor data I get real-time from a light-meter.

For example, I use a light sensor that reads Lux value real-time and if the number goes below 10,000, pause the printer and resume the printer when it goes back up 10,000. 

I currently read the sensor from the light-meter and pause/resume the printer manually through Repetier. 
I would like to automate this part by calling a command based on input data from the light-meter. 
I am logging/reading Lux on my computer and the printer is connected to the same computer through Repetier.

Please let me know if you have any suggestions to implement the system through Repetier (Or any other methods).

Any advice would be appreciated. 

Thanks! 

Comments

  • You can use the web API as described here:
    https://www.repetier-server.com/manuals/programming/API/index.html

    To make a pause use the send command with "@pause some message" as gcode. To continue use the "continueJob" command.
  • Thanks for your reply!

    I have been using Host and now switching to Server to use the web API.

    So when I use the serial connection, I had no problem.
    But I am having an unstable connection with TCP/IP connection. Constantly connected and disconnected. 

    Getting this in the console. Mesg:17:30:17.692: Connection started (29)

    Even when it's connected just for a few seconds, I cannot send a command and operate my printer. 
    I tried different internet connections for different IP addresses. The connection issue was the same. 

    Do you have any thoughts on why I am getting this connection problem? 

    Thanks. 
  • Is the printer connected with tp/ip to server? You said you use usb connection for that. This is important as these have different kind of reasons.

    With usb it means it did not get a communicating connection. Maybe wrong firmware selected. Also right choice of DTR/RTS seems to be important here.
  • I am using my laptop as a local server and the printer is connected to the computer through USB. 
    I might completely misunderstand the concept of using my laptop as a server. 

    Please see the video here and let me know if I am doing something wrong. 

    https://youtu.be/qQNx0lLD2Ck

    (I used the Api key for the Host.)
    As you can see, when I connected my computer through the Serial Port, it's working just fine.
    But when I switched it to the TCP/IP connection, it's unstable. 

    Basically, the reason why I am trying to use the TCP/IP connection is to use the Repetier web API you suggested for my problem in this thread. If it's possible to use the web API through just the serial connection with Repetier-server. Please let me know. 

    If I should have the IP connection to use the web API, I need to resolve this connection problem. 
    I am repurposing HE3D K200 Delta printer and using Repetier as a firmware. 

    Thanks again! 
  • OK so I was able to send a direct WebSocket command like this below and operate my printer

    http://localhost:3344/printer/api/deltaHyperreal?apikey=blahblahblah&a=send&data={"cmd":"G1 X10 Y10 Z10"}

    This is done through the serial connection which means I don't need to try to solve the TCP/IP connection issue for my purpose. (Although I still want to know what causes the problem)

    Now I am playing with the API demo. 
    I filled the ACTION with send and JSON Payload with {"cmd":"G1 X10 Y10 Z10"}

    But this didn't work. I assume that's because I didn't put API-key somewhere? 
    I was able to retrieve some information with listFirmwareNames, testPushMessage
    So I know it's communicating where it doesn't require API-key. 
    But most of the functions either do not work at all or give me empty responses. 

    How can I solve this problem? Am I using the demo in the correct way?? 

    Thanks!

  • Demo asks for user/password if required instead of using api key. If you have no users no key or user is required - all have full access then.

    The link it self is not correct - you need to urlencode the json string or parts get interpreted wrong.
    For tthe payload you can use https://jsonlint.com/ to verify the json syntax is correct. For me it looks correct so demo should work if you are authenticated or do not need authentication.
  • edited August 2020
    Repetier said:
    Demo asks for user/password if required instead of using api key. If you have no users no key or user is required - all have full access then.

    The link it self is not correct - you need to urlencode the json string or parts get interpreted wrong.
    For tthe payload you can use https://jsonlint.com/ to verify the json syntax is correct. For me it looks correct so demo should work if you are authenticated or do not need authentication.
    Thanks again for the reply.

    I am still having hard time to make it work. I think I am authenticated. When I call userlist, I am getting this response. { "loginRequired": true, "users": [ { "apikey": "blahblah-9ae7-4860-8748-a79edb5a6064", "id": 1, "login": "ss2432", "permissions": 1023, "uuid": "" } ] }

    The strange thing is when I tried Action with a command login and the right JSON payload to double-check if I am authenticated. I am getting this. { "error": "Login or password invalid!"}

    It's weird because I can retrieve the information with the userlist?

    But when I tried to operate the printer with babystep, the response I am getting is {"ok":false}
    I am expecting true but the reason I am getting false is I assume I still have an authentication problem? 

    Probably stupid question... the username and password are the credential for the Repetier-server account?

    Update event list continues to print this line which I assume normal. { "data": { "O": 0, "S": 0, "T": -20, "id": 0, "t": 1598550770860 }, "event": "temp", "printer": "deltaHyperreal" } }

    Do you have any idea why it's not working? loginRequired should be false in case I am already logged in?  
    I am confused... 

    Thanks for your prompt reply! Please let me know! 



  • Login with user and password only work if you have a real websocket connection. When that closes the session will invalidate. So if you use the get/post api solution you must always use the api key. Some functions do not require a validated login so return always data.

    The vent list what you see are the temperature updates.
  • edited September 2020
    Pretty sure I was connected to the open websocket server properly. I tested if I got a connection or not through different ways including websocket.org Echo Test and my own Python test. But I am still having difficulty communicating with my printer. Direct get/post API solution works though.

    When I connected, I am receiving this message 

    ws://localhost:3344/socket/&apikey=blah-blah-4b9d-8820-3b330638e751
    RECEIVED: {"callback_id":-1,"data":[{"data":{"session":"mtbIvUj9GyZznmab8S1Hlr9cQvaOHtYc"},"event":"loginRequired","printer":""}],"eventList":true}

    Although I put the API key, I was unsure if I am authenticated. So I send login with my repetier server username  and password that I use for the server frontend. But I am getting this error message. 

    RECEIVED: {"callback_id":2,"data":{"error":"Login or password invalid!"},"session":"mtbIvUj9GyZznmab8S1Hlr9cQvaOHtYc"}

    Why is this saying it's invalid? Is that the reason why some of the important requests such as send, move, stopJob, and continueJob do not work?   

    In most cases I am getting something like this. "permissionDenied":true

    SENT: {"action":"listJobs","data":{},"printer":"deltaHyperreal","callback_id":3}
    RECEIVED: {"callback_id":3,"data":{"permissionDenied":true},"session":"mtbIvUj9GyZznmab8S1Hlr9cQvaOHtYc"}


  • ws://localhost:3344/socket/&apikey=blah-blah-4b9d-8820-3b330638e751
    is wrong syntax. It has no parameter. First parameter MUST be preceded by ? like
    ws://localhost:3344/socket?apikey=blah-blah-4b9d-8820-3b330638e751
    That should work. When you late ruse login/passwort remember that we never send passwords in plain text. You need to create a hash as described in api:
    Authenticates a user. Password is MD5(sessionId + MD5(login + password)) so it never goes in clear text over the line. If authentication is required, you get a loginRequired event directly after connecting to the socket.

  • Now it's all working fine. The documentation in the WS says  
    If you have a apikey you can also add &apikey=your key to authenticate directly.

    I guess it has to be updated. 

    For the authentication, PW is pretty much MD5 of MD5? Please let me know.

    Anyways, I got what I need for this post! I have another question regarding the printing speed. I will make a new post for that. Thanks again for the prompt support! 

  • Yes we say to add &apikey=your key but the sample link already contained a ? for language selection and session. Additional parameter use & but first requires ?  :-)
Sign In or Register to comment.