Lars Cornelissen


How to Make a Drone Fly Whenever Someone Subscribes on Twitch

Profile Picture Lars Cornelissen
Lars Cornelissen • Follow
CEO at Datastudy.nl, Data Engineer at Alliander N.V.

4 min read


white and red DJI quadcopter drone

Introduction

Have you ever wished there was a way to make your Twitch streams more engaging and interactive for your viewers? Imagine this: someone subscribes to your Twitch channel, and immediately, a drone lifts off and starts flying around your room. Sounds intriguing, right? Well, it’s totally possible, and in this blog, I’m going to walk you through how you can make this happen.

Making a drone fly when someone subscribes on Twitch isn't just a cool party trick. It can significantly increase viewer engagement and make your streams more memorable. This kind of interactive feature can set you apart from other streamers. Plus, it adds an element of excitement and unpredictability to your content. You’ll find viewers subscribing just to see the drone in action, which is a win-win for everyone involved.

But before you dive into the technical setup, you need to have a few basic skills under your belt. First, a fundamental understanding of Twitch and its API (Application Programming Interface) is crucial. Don’t worry, though; you don’t need to be a coding wizard to get through this. Basic programming skills in Python or JavaScript will suffice. If you can write a simple script, you’re halfway there.

You’ll also need to know how to operate a drone, particularly the one that you plan to use for this project. It's not like driving a car, and I can tell you from personal experience that crashes are not just reserved for beginners. So, make sure you’ve got some drone flying practice under your belt.

Finally, having some knowledge in automation and webhooks will make things easier. Webhooks are essentially automated messages sent between apps when something happens. In this case, the “event” is someone subscribing to your Twitch channel, and the “action” is the drone taking off. Sounds simple enough, right?

Stay tuned, as I take you through the step-by-step process of turning this idea into a reality, and let’s make your Twitch streams the talk of the town! 🚀

Materials and Tools Required

To bring this exciting idea to life, we'll need a few key materials and tools. Don't worry; I'll break it down piece by piece so you won't miss out on anything essential. Plus, where possible, I'll include affiliate links to the products. If you purchase through these links, it helps out without costing you extra—think of it as buying me a virtual coffee. ☕

1. The Drone
First things first, you need a reliable drone that can take off and fly inside your room. I recommend using the DJI Tello drone. It's affordable, easy to program, and stable for indoor flights.
DJI Tello

2. Computer with Python or JavaScript Programming Software
You'll need a computer to write and execute the script that will make everything work. I personally prefer using PyCharm for Python, but you can use any IDE (Integrated Development Environment) that you are comfortable with. Here are some common options:

Python IDEs:
- PyCharm Download PyCharm
- Visual Studio Code Download VSCode

JavaScript IDEs:
- Visual Studio Code Download VSCode
- WebStorm Download WebStorm

3. Twitch Account and Setup
Ensure you have a Twitch account set up and you're familiar with its interface. If you haven't already got an account, you can create one here: Twitch Sign Up.
You will also need to enable Twitch's EventSub to listen for subscription events. This is where the action happens.

4. Webhook Service
To receive the subscription notifications, you'll need to set up a webhook. Popular options include:
- IFTTT (If This Then That): Easy to set up and use. IFTTT
- Zapier: A bit more advanced but highly customizable. Zapier

5. WLAN or Bluetooth Module
This will connect your computer to your drone. The DJI Tello can be controlled via Wi-Fi, so make sure your computer has a WLAN capability. If you're using a different drone, ensure you have the appropriate module.
- USB Wifi Adapter Buy on Amazon

6. Basic Hardware Tools
Keep some basic tools handy, like a screwdriver set and a laptop cooling pad if your drone tends to get hot. Here's a small list:
- Screwdriver Set Buy on Amazon
- Laptop Cooling Pad Buy on Amazon

7. Batteries and Chargers
Make sure you have extra batteries for your drone and a reliable charging station. You don't want your drone dying mid-flight.
- Extra Batteries for DJI Tello Buy on Amazon
- Multi-Battery Charger Buy on Amazon

Alright, these essentials should set you on the right path. By having all these tools and materials ready, you'll be able to glide through the setup process smoothly. Now, let's get into the nitty-gritty of making your drone respond to Twitch subscriptions.

Step-by-Step Guide

Step-by-Step Guide

Now that we have all the materials and tools we need let’s dive into the step-by-step process of making your drone fly when someone subscribes to your Twitch channel. Think of it as a fun journey into the world of interactive streaming. Ready? Let’s go!

Step 1: Setting Up Your Drone

The first thing you need to do is set up your DJI Tello drone. If you haven’t flown your drone before, take some time to get familiar with its controls. Practice makes perfect! Here's a basic checklist:

  1. Unbox the drone and ensure all components are intact.
  2. Charge the battery. Make sure it's fully charged before setting it up for your Twitch events.
  3. Install the companion app on your smartphone. This app will help you control the drone manually if needed.
  4. Connect the drone to your smartphone and ensure it takes off and lands without issues.

Step 2: Connecting the Drone to Your Computer

Now that your drone is ready, it’s time to connect it to your computer. Here’s how:

  1. Install necessary software: For the DJI Tello, you’ll need pyTello, a Python library for controlling the drone. Run the following commands to install it:

python pip install djitellopy

  1. Connect to the drone’s Wi-Fi: Ensure your computer is connected to the drone's Wi-Fi network. It's typically TELLO-XXXXXX.
  2. Test the connection: To make sure everything is configured correctly, write a simple Python script to make the drone take off and then land. Here's a sample:

```python from djitellopy import Tello

tello = Tello() tello.connect()

battery = tello.get_battery() print(f"Battery life percentage: {battery}")

tello.takeoff() tello.land() ```

Run this script to verify that your computer can control the drone. If the drone doesn't respond as expected, double-check your connections and software setup.

Step 3: Integrating the Drone’s API with Twitch

We’ll be using Twitch's EventSub, which can notify your application whenever a user subscribes to your channel. Here's how to integrate it:

  1. Set up your Twitch account with the necessary permissions. Go to the developer portal and create a new application.
  2. Create an EventSub subscription. You’ll need to subscribe to the channel.subscribe event.
  3. Write a Python script to act as your webhook endpoint. This script will listen for Twitch subscription events and make the drone take off.

```python from flask import Flask, request, jsonify from djitellopy import Tello import hmac import hashlib

app = Flask(name) tello = Tello() tello.connect()

@app.route('/webhook', methods=['POST']) def listen_event(): signature = request.headers.get('Twitch-Eventsub-Message-Signature') secret = bytes('YOUR_SECRET_KEY', 'utf-8') message = bytes(request.get_data(), 'utf-8') computed_hash = 'sha256=' + hmac.new(secret, message, hashlib.sha256).hexdigest()

   if hmac.compare_digest(computed_hash, signature):
       data = request.json
       event_type = data['subscription']['type']
       if event_type == 'channel.subscribe':
           tello.takeoff()
           tello.land()
       return jsonify({'message': 'event received'}), 200
   return jsonify({'message': 'invalid signature'}), 401

if name == 'main': app.run(host='0.0.0.0', port=5000) ```

Run this script, and it will wait for subscription events. Make sure you host this script on a server or use a service like ngrok to create a public URL.

Step 4: Linking It All Together

Your final task is to link Twitch events to your running script:

  1. Configure your Twitch app to point to your webhook URL.
  2. Test the setup: Subscribe to your own channel (or ask a friend) to see if the drone responds correctly.
  3. Adjust settings as needed. For example, add extra checks to ensure the drone doesn’t take off multiple times if someone resubscribes quickly.

Troubleshooting Tips:

Setting this up takes some effort, but once everything works, it’s incredibly rewarding. Plus, your viewers will love the interactive twist! Enjoy becoming the coolest streamer on the block. 😎

# Ensuring Safety and Compliance

Alright, now that we've covered the technical side of things, let's talk about a crucial aspect: safety. Making your drone take off when someone subscribes is undeniably cool, but safety should always be your top priority. You don’t want to be known as the streamer who accidentally knocked over their own setup with a rogue drone. Trust me, that's not the kind of 'viral' you want to go for. 😅

Here are some tips to ensure that your drone flight is safe for you, your equipment, and your viewers:

1. Choose an Appropriate Flight Zone
Select a specific area in your room where the drone can take off and land safely. Make sure this area is free from obstacles like overhead lights, hanging cables, and other electronic devices. Also, keep pets and small children away from the flight zone. The space should be large enough for the drone to maneuver without crashing into anything.

2. Safety Gear
While it might sound like overkill, wearing safety goggles can protect your eyes from accidental drone collisions. Flying a drone indoors comes with risks, and it's better to be safe than sorry, especially when things can go wrong quickly.

3. Use a Drone with Obstacle Detection
Some advanced drones come with obstacle detection technology, which helps prevent crashes. If you're able to upgrade, consider one with this feature. It can make your setup significantly safer and provide peace of mind.

4. Secure Loose Objects
Before starting your stream, make sure to secure any loose objects in your room. Items like paper, lightweight decor, or anything that the drone's propellers can catch on should be put away. The last thing you want is a mess mid-stream.

5. Monitor Battery Levels
Keep a close eye on your drone’s battery levels. An unexpected battery drop can result in a hard landing, potentially damaging the drone or surrounding objects. Always start with a full battery and have spare batteries charged and ready.

6. Use Propeller Guards
Propeller guards can greatly reduce the risk of injury or damage. They're designed to protect the drone's propellers from hitting objects, which also minimizes the potential for accidents.

7. Stay Within Line of Sight
Never fly your drone out of your line of sight. This not only helps you maintain control but also allows you to quickly intervene if something goes wrong. This applies even if you're just flying it around your room.

### Regulatory Requirements and Guidelines
When operating a drone, even indoors, it's essential to be aware of any regulatory requirements or guidelines that need to be followed. Here are some general points to consider:

1. Know Your Local Laws
While indoor drone flights might not be strictly regulated, it's good practice to be aware of local drone laws. Some regions might have specific rules for drone usage, even indoors. For example, some countries have specific regulations about flying drones near private property or in densely populated areas.

2. Register Your Drone
If your drone exceeds a certain weight limit, it might need to be registered with aviation authorities. Check the specific requirements in your country. In the United States, drones over 0.55 pounds must be registered with the FAA.

3. Fly Below Altitude Limits
Ensure that your indoor flights comply with any altitude restrictions. While this might seem more relevant for outdoor flying, it’s good practice to be aware of height limits to prevent accidents indoors.

4. Educate Yourself About No-Fly Zones
Certain areas might be designated as no-fly zones due to security or privacy concerns. While this is generally more applicable outdoors, being educated about such restrictions can keep you compliant with broader drone regulations.

By following these safety tips and regulatory guidelines, you can make sure that your new interactive feature is both fun and safe. The added layer of security will let you enjoy your streams without any worries about unexpected mishaps. So go on, impress your viewers with a drone that takes flight with every new subscription—just make sure it’s done safely! 🚁

Common Issues and Their Solutions

Common Issues and Their Solutions

Alright, we've covered setting up your drone and ensuring everything runs smoothly and safely. But let's be real—technology has a way of throwing curveballs at us when we least expect it. Here, I’ll go over some common issues you might encounter and how to troubleshoot them. Let’s get you back to streaming with minimal downtime!

1. Connectivity Issues Connectivity issues are probably the most common problem you'll face, whether it's between your drone and computer or your computer and Twitch. Here’s how to tackle these issues:

Problem: Drone not connecting to Wi-Fi

Problem: Webhook not receiving events

2. Programming Bugs Even seasoned programmers encounter bugs. The good news is most of these issues can be solved relatively easily.

Problem: Script not executing properly

Problem: Drone doesn’t respond to commands

Here is a small Python script to test basic drone commands:

from djitellopy import Tello

tello = Tello()
tello.connect()

if not tello.get_battery():
    print("Could not connect to the drone")
else:
    print("Drone connected!")
tello.takeoff()
tello.land()

3. Hardware Malfunctions Nothing is more frustrating than dealing with hardware that decides to take a nap mid-project.

Problem: Drone won’t take off

Problem: Inconsistent flight behavior

4. Webhook Errors If your webhook suddenly stops working, it can be due to multiple reasons.

Problem: Signature validation failed


import hmac
import hashlib

secret = bytes('YOUR_SECRET_KEY', 'utf-8')
message = bytes(request.get_data(), 'utf-8')
computed_hash = 'sha256=' + hmac.new(secret, message, hashlib.sha256).hexdigest()

if not hmac.compare_digest(computed_hash, signature):
    return jsonify({'message': 'invalid signature'}), 401

5. Latency Issues Latency can ruin the sync between Twitch subscriptions and the drone’s actions.

Problem: Delayed drone response

By arming yourself with these troubleshooting techniques, you'll be better prepared to face any issues that come your way. Remember, the more you tinker with the setup, the better you'll get at anticipating and solving problems. Happy streaming! 🚀

Conclusion

Conclusion

We've covered a lot of ground in this blog on how to make your Twitch streams more interactive by making a drone fly when someone subscribes. From gathering the necessary materials to setting up the technical infrastructure, and making sure everything operates safely, I hope this guide has provided a comprehensive roadmap for your project.

Let's recap the key points we discussed:

The blend of technology and creativity in this project can really set you apart as a streamer. When viewers see a drone taking off because someone subscribed, it adds a layer of excitement and engagement that's hard to match. 🚁

But don't just take my word for it—give it a shot and see how it transforms your streaming experience. And if you encounter any hiccups along the way or have tips you’ve discovered yourself, don't hesitate to share them in the comments. Your feedback and questions are always welcome and can help everyone in the community.

So go ahead, start setting up your drone, and bring a new level of fun and interactivity to your Twitch streams. Happy streaming, and may your subscriber count soar sky high! 🎉


drone

Twitch

automation

subscription alerts

DIY project