Skip to content

Equipment monitoring for Opentrons OT-2 (camera stream to YouTube) #80

Open

Description

@sgbaird

@Neil-YL could you link the docs you found related to accessing the built-in camera?

EDIT: Based on info and link below, trying to stream to YouTube might render the OT-2 unresponsive. In this case, it might be better to simply wire the USB webcam into a separate RPi Zero 2 W (could be embedded within the OT-2), or use a separate camera altogether. Static images via an HTTP request are still an option (not quite as compelling as a video, but still quite functional in terms of seeing visual changes to the experimental setup).

Activity

  1. Neil-YL commented on Oct 16, 2024

    @Neil-YL
    Contributor

    Note: it only has a resolution 320x240px for video

    Using the OT-2 Camera as a live feed webcam
    The OT-2 camera is plugged into the Raspberry Pi through a USB cable. In order to establish a live feed camera for your OT-2 you will need to locate and upload the USB cable from the Raspberry Pi and you will need a USB extender for your computer. The cable for the camera only reaches the USB port on the Raspberry Pi which means you will not be able to directly plug the camera into your computer.
    Here is an example USB extender:
    image
    Next you will need to access the rear electronics by following our support article: https://support.opentrons.com/s/article/Accessing-the-OT-2-s-rear-electronics

    Once you have gained access to the rear electronics you will then see cable for the camera plugged into the Raspberry Pi USB port:
    image

    You will now plug this camera USB cable into your USB extender and then plug the USB extender into your computer. This will act as a normal Webcam for your computer which you will be able to use with webcam software available on your computer.

    Link: https://support.opentrons.com/s/article/Using-the-OT-2-s-camera

  2. Neil-YL commented on Oct 16, 2024

    @Neil-YL
    Contributor

    trying to stream to YouTube might render the OT-2 unresponsive

    I believe it says it could be unresponsive when taking (saving) photos.
    The streaming function suggested in this article is to remove the the camera from the OT-2 RB controller and connect it directly to the computer to host the streaming

  3. sgbaird commented on Oct 16, 2024

    @sgbaird
    CollaboratorAuthor

    Agreed. Adding a second RPi and maybe even just using a separate camera might be better

  4. Neil-YL commented on Oct 16, 2024

    @Neil-YL
    Contributor

    If it only supports 320x240px for video(not sure the limitation is on controller end or camera end), using a separate camera might be a better option.

  5. changed the title [-]OT2 camera feed streaming to YouTube[/-] [+]Equipment camera monitoring for OT-2 (stream to YouTube)[/+] on Jan 21, 2025
  6. changed the title [-]Equipment camera monitoring for OT-2 (stream to YouTube)[/-] [+]Equipment monitoring for OT-2 (camera stream to YouTube)[/+] on Jan 21, 2025
  7. sgbaird commented on Jan 21, 2025

    @sgbaird
    CollaboratorAuthor

    Let's go with the usual Pi Zero 2W camera setup described in #11

  8. changed the title [-]Equipment monitoring for OT-2 (camera stream to YouTube)[/-] [+]Equipment monitoring for Opentrons OT-2 (camera stream to YouTube)[/+] on Jan 21, 2025
  9. Neil-YL commented on Feb 3, 2025

    @Neil-YL
    Contributor

    I have run a speed test on the network of the Nokia router.

    Live on:
    Image

    Live down:
    Image

    According to YouTube’s streaming network recommendations:

    • 480p (30fps): 1.5 Mbps
    • 720p (30fps): 3 Mbps(our current streaming setting)
    • 720p (60fps): 4.5 Mbps
    • 1080p (30fps): 6 Mbps
    • 1080p (60fps): 7.5 Mbps

    We may need a network with a higher upload bandwidth to support our device’s streaming. The ping could be a problem as well.

  10. Neil-YL commented on Feb 6, 2025

    @Neil-YL
    Contributor

    I had streaming survived for 69 hours through the weekend, and it went down with following logs:

    [flv @ 0x55cac6f680] Failed to update header with correct duration.
    [flv @ 0x55cac6f680] Failed to update header with correct filesize.
    Error writing trailer of rtmp://a.rtmp.youtube.com/live2/rr8p-pbf1-uzp1-tdju-80ag: Broken pipe
    Error closing file rtmp://a.rtmp.youtube.com/live2/rr8p-pbf1-uzp1-tdju-80ag: Broken pipe

    I would try to add a restarting rtmp when it fails

  11. sgbaird commented on Feb 12, 2025

    @sgbaird
    CollaboratorAuthor

    You can login with eduroam / UoT credentials on the Pi Zero 2W instead of using the Nokia. Pi Zero 2W supports eduroam, etc. Trouble is we probably need to get a login that's not tied to a personal account, but a personal one might be ok in the meantime.

    In addition to logging into eduroam, I suggest setting it to 480p or lower instead of 720p, and let's see how long it can go for. High uptime is more important than resolution right now (since right now we just want to see it moving).

  12. sgbaird commented on Feb 12, 2025

    @sgbaird
    CollaboratorAuthor

    Oh, and I think if you click "reuse settings" and choose the dead stream, you might be able to keep the link the same so you don't have to update it everytime it goes down. Or maybe that only kept the stream key the same, not the URL..

  13. Neil-YL commented on Feb 12, 2025

    @Neil-YL
    Contributor

    Or maybe that only kept the stream key the same, not the URL..

    YouTube will generate a new live(and later for video) even we reuse the setting (and by doing so you reuse the same stream key). Twitch could be a better streaming option because it is a channel based streaming so the link is the same(but you may need a twitch account for each device?)

    I have added a restart on the Pi and hope the live can survive longer. I saw you help me correct the "embed" syntax on huggingface. Thanks.

    You can login with eduroam / UoT credentials on the Pi Zero 2W instead of using the Nokia. Pi Zero 2W supports eduroam, etc. Trouble is we probably need to get a login that's not tied to a personal account, but a personal one might be ok in the meantime.

    In addition to logging into eduroam, I suggest setting it to 480p or lower instead of 720p, and let's see how long it can go for. High uptime is more important than resolution right now (since right now we just want to see it moving).

    I see. I’ll try the UofT network then—it should be much better. I’ve already reduced the bitrate by a quarter, and it seems fine so far.

    ---- Update Feb 13----

    I haven’t switched to the UofT network yet. The stream has been live for two days so far, and I will continue monitoring it throughout the OT-2 practical.

  14. sgbaird commented on Feb 14, 2025

    @sgbaird
    CollaboratorAuthor

    It looks like the stream made it to about 60 hours and then cut out again, but you started a new one already.

    A couple comments/options:

    We can utilize the backup stream URL, possibly with a second device or cloud service.

    Lengthy conversation here: https://chatgpt.com/share/67afc522-62fc-8006-89d0-6b0fa409a08a

    Castr might work.

    To avoid having a new URL, we can create a new channel on YouTube per camera and then use a certain URL that points to that channel. https://www.reddit.com/r/k12sysadmin/comments/lgv591/a_way_for_my_livestream_to_avoid_ending_in_case/

    For example, https://m.youtube.com/@ac-hardware-streams/live

    (Here's for a channel that has multiple live streams going simultaneously, not sure why it chose to go to this one specifically: https://youtube.com/@lofigirl/live)

    EDIT: https://chatgpt.com/share/67afc9dc-94b8-8006-9021-c5b30760edc8 is consistent with my impressions about Twitch from before. Worth considering and glad you brought it up. For now, let's not use Twitch.

  15. sgbaird commented on Feb 14, 2025

    @sgbaird
    CollaboratorAuthor

    @Jonathan-Woo is this something you can keep supporting on?

    I lean towards creating one channel per camera, using the channel ID link, (maybe also setting the stream key to something we specify rather than autogenerated so it's easier to keep it fixed), and automatically stopping the stream and starting a new one every 8 hours via the API:
    https://developers.google.com/youtube/v3/live/getting-started

    This would provide us a single persistent link we could use per camera and would have the benefit of keeping archived recordings that YouTube stores for us.

  16. Neil-YL commented on Feb 18, 2025

    @Neil-YL
    Contributor

    To avoid having a new URL, we can create a new channel on YouTube per camera and then use a certain URL that points to that channel. https://www.reddit.com/r/k12sysadmin/comments/lgv591/a_way_for_my_livestream_to_avoid_ending_in_case/

    I turned on the Auto-stop on the YTB studio to see how it works.

    For example, https://m.youtube.com/@ac-hardware-streams/live

    Nice to know. I will see how to used it as embedded url.

    Update: failed to use the channel id in embedded video, will look it up after lunch break. Another alternative suggested by Chatgpt is use playlist link as embedded url and put the latest stream in the playlist.

  17. sgbaird commented on Feb 21, 2025

    @sgbaird
    CollaboratorAuthor

    Maybe if we get the video ID programmatically: https://stackoverflow.com/a/76541269

    (Would convert the Java to Python first so we could use directly in HF)

  18. sgbaird commented on Feb 28, 2025

    @sgbaird
    CollaboratorAuthor

    Two related notes: per-equipment channels and YouTube Live Streaming API. The latter may provide a lot of flexibility in terms of where/how we include the videos (i.e., the workaround of trying to have one channel per piece of equipment to get the livestream might not be necessary - but it's worth thinking about whether there are other reasons to separate into multiple channels or keep it in one for now). I suppose the Pi Zero 2W would be the one using the Live Streaming API, starting a new stream every 8 hours or so (or if the stream goes offline for some reason). On HF side, we can also use the Live Streaming API to figure out what the latest video we should pull is (based on title/date/etc.). We can also create playlists and add videos to it programmatically. It doesn't seem like we'd run into limitations on YouTube's end in terms of number of videos, but we could move to a multi-channel approach if that becomes an issue.

    One channel per piece of equipment

    To create new brand channels: https://www.youtube.com/channel_switcher, then click "create a channel". On the channel itself, scroll on left sidebar to Settings,


    When you invite, you get the following dialogue box:

    One important consideration is that new channels/accounts have certain limitations:

    Verifying a phone number isn't too big of a deal, and with a valid government ID (snapping a picture), the restrictions are pretty minimal.

    YouTube Live Streaming API

    After a long rabbit hole looking into the Live Streaming API, I came upon https://developers.google.com/youtube/v3/code_samples/code_snippets 🔥🔥

    Image

    Image

    Part of the difficulty of finding this is that I think the YouTube Live Streaming API is technically encapsulated by the YouTube Data API. If we run into issues, https://stackoverflow.com/questions/tagged/youtube-livestreaming-api is probably a good place to ask.

    My rabbit hole

    Aside: From the Live Streaming API page, I happened upon a link to GitHub examples of the YouTube API usage, which even has examples specific to Python (e.g., create a broadcast and stream). Some others:

    The repo hasn't been updated in ~7 years, and based on the issues, many aren't working / are meant for Python 2. However, they might be a good reference point still.

    Hopefully someone puts an update in https://stackoverflow.com/questions/78170151/live-video-using-youtube-live-streaming-api-python.

    In terms of general examples, maybe the following: https://developers.google.com/youtube/v3/quickstart/python. At first glance, it looked like there was a more official Python client for Livestream API listed at https://developers.google.com/youtube/v3/live/libraries, but it turned out to go to the generic top-level API. However, I stumbled upon samples/youtube --> https://developers.google.com/youtube/v3/code_samples#apps-script --> https://developers.google.com/youtube/v3/code_samples/code_snippets 🔥🔥

    This last one is gold:

    Image

    Image

  19. sgbaird commented on Mar 11, 2025

    @sgbaird
    CollaboratorAuthor

    Live Streaming API with an auto-start script on the Pi, with new streams every eight hours, and automatically finding of the latest stream from the orchestrator side (i.e., HF) is probably the way to go. The stream is relatively fragile: #161 (comment)

    This probably allows us to circumvent needing to stream to the backup URL, and we should be able to have it go to a single YT account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions