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?
- 6 replies
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
/snapshotroute on your device like
https://tinypilot/snapshot, it will give back the image currently on the screen remote as a JPEG.
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?
Nope, my bad. I was sending the request via http and not https. Confirmed! Thanks again Michael. Loving this product :)
- 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.
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: