Obtaining a screenshot using the internal API
I'm a student writing custom software to automate a host machine (also referred to as the "target") through the TinyPilot Voyager 2 using the exposed APIs defined in api.py (for RESTful calls) and socket_api.py (for WebSocket connections).
For the curious and as a quick summary; the socket connection mainly handles keyboard and mouse input while the RESTful API exposes system-level operations like restart, shutdown, and status amongst others.
I'm hoping its also possible to obtain the current state of the host video output similar to the "Actions > Screenshot" functionality in the web-client which downloads a jpeg file. Which internal API has ability exposed?
- Michael Lynch @michael2022-08-01 22:15:21.443Z
Disclaimer: We don't guarantee that this method will work in future versions. For those kind of guarantees, you can sign up for a plan that includes the Enterprise REST API.
If you check the source of the "Screenshot" button, you can see it's a simple anchor tag:
<li class="item"> <a id="screenshot-btn" href="/snapshot">Screenshot</a> </li>
If you visit the
/snapshot
route on your device likehttps://tinypilot/snapshot
, it will give back the image currently on the screen remote as a JPEG.- A@astigmatism
Ah yes, thanks for the guidance Michael!
I'm discovering however that calling the /snapshot API results in a 500 error when I open it from a new browser tab or use a tool like Postman. Are there authentication headers or something else required on the network request?
- A@astigmatism
Nope, my bad. I was sending the request via http and not https. Confirmed! Thanks again Michael. Loving this product :)
- Michael Lynch @michael2022-08-02 20:09:02.581Z
Glad you got it working! I've filed a bug on this internally because it really should just redirect you to the HTTPS URL if you don't have plaintext HTTP enabled.
- JIn reply toastigmatism⬆:Jason P @jason
Hey @astigmatism did you ever get a custom script working with the websocket? If so care to share the code you used? I'm starting to dive into this and am trying to connect to the internal api websocket. I see the definitions in https://github.com/tiny-pilot/tinypilot/blob/master/app/socket_api.py but am not sure if im doing wrong with my connection via websockets.
- Michael Lynch @michael2023-01-30 23:05:52.414Z
It might be helpful to see how TinyPilot's web client communicates with the server via websockets:
Or for a simplified version, you can look at how it worked in version 1.0.0 of TinyPilot:
https://github.com/tiny-pilot/tinypilot/blob/1.0.0/app/static/js/app.js