Run the ApolloTV server on your Raspberry Pi 🥧

Running a copy the server on your Raspberry Pi decreases load on the official servers, as well as giving you faster access. You can also enjoy ApolloTV even when the official server is down.

What is the ApolloTV Server?

The ApolloTV server, codename Claws, is a component of ApolloTV that runs on our machines.

We split our app into a client and server because it speeds up the app and makes updating sources simpler. When you choose to play content in the client (app), this is the software that makes the magic happen. It scrapes websites for the content and returns the content to the app.

Setting up Claws on your Raspberry Pi (or other Debian machine)

Lines that start with a # are comments explaining the commands (below them) that should be executed.

Commands are on any lines that start with a $ . The command is all text to the right of the dollar sign. E.g. for the line $ sudo su the command that you would copy would besudo su

# Obtain root permissions
# This will save you from typing your password over and over.
$ sudo su
# Update your Pi
$ apt update -y
$ apt upgrade -y
# Install Git
$ apt install -y git
# Install Redis
$ apt install -y redis-server
# Install NodeJS
# This isn't in the official apt repository, so we're using their
# apt repository.
# Should this step fail with the message 'You appear to be running on
# ARMv6 hardware...', see the section below: manually install NodeJS.
$ curl -sL https://deb.nodesource.com/setup_11.x | bash -
$ apt install -y nodejs
# Install PM2 (process manager 2)
# IMPORTANT: Be sure to copy the '-g'
$ npm install -g pm2
# Add a reference to PM2 in the applications directory
# If you see the message 'failed to create symbolic link... File exists',
# that's fine. That just means the installer already did this step for
# you.
$ ln -s /opt/nodejs/bin/pm2 /usr/bin/pm2
# Typing the command 'exit' will log you out of
# the root user (provided you executed sudo su at the
# beginning of the guide.)
$ exit
# Create and open a directory for Claws
$ mkdir "~/ApolloTV" && cd $_
# Download a copy of the server to the current directory
$ git clone https://github.com/ApolloTVofficial/Claws .
# Install the necessary libraries
$ npm install
# Copy the example configuration to the real configuration
# location.
$ cp .env.dist .env

By following the above steps, you will have Claws setup in /home/pi/ApolloTV (where pi is your username.)

Manually install Node.JS You can safely ignore this if you were able to set up Node.JS. This section is specifically for the Raspberry Pi.

$ wget https://nodejs.org/dist/v11.15.0/node-v11.15.0-linux-armv6l.tar.xz
$ tar xvf node-v11.15.0-linux-armv6l.tar.xz
$ cd node-v11.15.0-linux-armv6l
$ cp -R bin/* /usr/bin/
$ cp -R lib/* /usr/lib/
$ apt install build-essential

Now you need to configure Claws:

  • Open the .env file in your preferred text editor.

    • If you're in GUI mode (you have a desktop), run leafpad .env

    • If you're not in GUI mode (you just have a fullscreen command line), run nano .env

  • Between the quotations after PORT= you should add 3000

  • Between the quotations after SECRET_CLIENT_ID= you should add a random 32 character string. You can use something like http://www.unit-conversion.info/texttools/random-string-generator/ (just put 32 in the length box) and copy the output.

  • Save and close the file. (For nano, the keyboard shortcuts are Ctrl + X, Y and then ENTER.)

The file should look like this at the bare minimum:

.env
PORT="3000"
SECRET_CLIENT_ID="your_32_character_client_id_here"

Finally, test Claws and let's get it to automatically run on boot:

You can use the command npm run dev to see if the server starts. If there are no errors, you're good to go. If it all works out you should see something like the following:

{"message":"claws v0.0.1 server listening on http://127.0.0.1:3000","level":"info"}

You should then take this opportunity to get the device's hostname / IP address. You'll need it later when you setup the app.

$ hostname -l

(The number that is returned is the hostname - it may look vaguely like this: 192.154.0.2)

Now you can use pm2 to get Claws to start on boot.

# Run this command to *get instructions* for setting up PM2 on boot.
# You pretty much just run the output of this command.
$ pm2 startup
# Now, we start Claws
$ npm run start
# Finally, we save the currently running processes.
# If the system goes offline for any reason, once the
# system boots PM2 will restart any saved processes.
$ pm2 save

...and that's all there is to it!

Using your server: configuring the app

Tap the three dots in the top right of the app's homepage.
Once in Settings, choose 'Advanced'
In the 'CORE' category, choose 'Change Default Server'
The following dialog will open.

Type your server's hostname or IP address in the top box, and type your server key in the bottom box. Your server's hostname or IP address should start with http:// and should end with a /.

It should also include the port number - e.g. if your server is setup to use port 3000, you should add :3000 before the trailing / and after the hostname or IP address.