Installing castnow

Wanted to stream videos from the Raspberry Pi to my Chromecast and control it on the command line through ssh.  Found out about a cli tool that does just that.  It’s called castnow and it was quite a beast figuring out how to install it, so I’ve boiled it down here.

# It’s actually not a regular program you can just download with apt-get.  It runs on nodejs.

So here’s the install breakdown:

Pre-install flight check:

sudo apt-get update -y

sudo apt-get install wget

# Update and install wget if not already installed.

 

Install nodejs:

wget http://nodejs.org/dist/v0.10.28/node-v0.10.28-linux-arm-pi.tar.gz

tar -zxvf node-v0.10.28-linux-arm-pi.tar.gz && cd node-v0.10.28-linux-arm-pi/bin

This downloads an archive of nodejs version 0.10.28 and extracts it.

sudo su

PATH=”$PATH:/location/to/download/node-v0.10.28-linux-arm-pi/bin/”

apt-get install npm

npm install -g castnow

Change to root and add this path so that castnow will be able to run as a regular command once it’s installed.  Install npm, the nodejs package manager.  Then use npm to install castnow.

su pi

sudo ln -s “$(which nodejs)” /usr/bin/node

Change back to the pi user and make a symbolic link to the node directory in /usr/bin.

There’s a few cool things you can do with castnow.

  • Play local .mp4 video files.

castnow ./video.mp4

  • Play video and / or audio files from a directory.

castnow ./Media/

  • Play multiple videos in a row.

castnow episode1.mp4 episode2.mp4 episode3.mp4

There’s many more commands and options to play with, more information can be found on castnow’s github:

https://github.com/xat/castnow

Advertisements

Simple Automation Scripts

Making a script to automate a few commands is actually pretty easy, but seemed really daunting on the first few attempts.

Here is a breakdown to create a simple script, make it executable and run it.  Once you get the hang of this you can create your own customized scripts.

nano automation.sh

Create a new file with the .sh extension.  While the extension is not necessary for the script to run, it helps you know it’s a script when looking at the file in the directory listing using ls.

#!/bin/sh

This is the first line of the script that tells bash “hey, this is a script!”

# Start Automation Script

Adding comments like this helps to keep track of what the script is doing.

echo “This is an automation script!”

Here’s an example of a command that can be run, really any command run in the terminal can be put into this kind of script.

Your script file should look like this when editing in nano.

#!/bin/sh

# Start Automation Script

echo “This is an automation script!”

Exit and save the file with Ctrl x, confirm you want to save with y and press enter.

chmod +x automation.sh

Modify the permissions to make the script executable.

./automation.sh

Run the script.  This command will run the script but make sure you’re in the same directory as the script.

 

Updating & Upgrading

There’s a few key commands needed to update & upgrade software, firmware and the OS running on the Raspberry Pi.

sudo apt-get update

First use apt-get update to update package lists and information about newest versions of software and their dependencies.

# Using apt-get update before installing new software ensures that the newest version is installed.

sudo apt-get upgrade

Use apt-get upgrade to upgrade all software packages and firmware to the newest version.  

sudo apt-get upgrade -y

The apt-get upgrade command will prompt to confirm [y,n] that you want to proceed. You can pre-confirm by adding -y at the end of apt-get upgrade.

sudo apt-get update && sudo apt-get upgrade -y

Both apt-get update and upgrade commands can be strung together with two ampersands, executing both one after the other.

You can also update the OS distribution with the following command.

sudo apt-get dist-upgrade

So if you want to update and upgrade everything all in one go and you don’t want to confirm at every step of the way then use the following command.

sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y

Now everything will be up to date.  It’s also a good idea to do this periodically to keep your Raspberry Pi up to date.

Setup: Bluetooth

Setting up Bluetooth for the first time can be a bit of a bear, especially if you want to use a Bluetooth keyboard and mouse.  Since both are critical to getting anything done on the Raspberry Pi it’s important to set them up so they work seamlessly on boot.  Otherwise you may find yourself up a creek with out a mouse and keyboard.

Although the documentation for the Raspberry Pi and Rasbian says that Bluetooth is functional out of the box, I found that I had to install a few things and tinker around with it to get it working.  Going through the GUI seemed intuitively like that would be the easiest way but, again, the command line is really where it’s at.

(Just a side note but setting up Bluetooth on Ubuntu MATE was much easier than Rasbian.)

First step is to install a few Bluetooth packages.

sudo apt install pi-bluetooth bluez bluez-firmware blueman

Set your Bluetooth device to pairing mode and then use bluetoothctl to scan for, trust, pair and connect to your device.

bluetoothctl

Your prompt will change showing that we are now using bluetoothclt.

[bluetooth]#

First scan for the device with the scan on command.

scan on

It will say “Discovery started” and when it finds your device it will show you the device MAC address and name.

[NEW] Device 00:2B:CD:34:55:72 Keyboard

Trust the device with by typing the trust command and then the first two numbers or letters of the MAC address, you can use autocomplete by pressing tab.  Make sure that is the same MAC address as the one just found in the scan and press enter.

trust 00:2B:CD:34:55:72

Then pair and connect to your device, and finally quit out of bluetoothctl.

pair 00:2B:CD:34:55:72

connect 00:2B:CD:34:55:72

quit

There are more commands to use in bluetoothctl and it’s helpful to check them out using the help command.  This way you can unpair devices or troubleshoot if you encounter issues.

bluetoothctl

[bluetooth]# help

 

Setup: The Resolution

One thing that is a bit annoying when you start up your Raspberry Pi for the first time is that you’ll notice a black border around the screen.  Even though the output is HD it still dosen’t look like it.

This is easy to fix.

The setting that makes this happen is called overscan and by default it is turned on in Rasbian.  Edit the config.txt file in the /boot directory.

sudo nano /boot/config.txt

In the third paragraph you will see the instructions.

# uncomment this if your display has a black border of unused pixels visible

# and your display can output without overscan

# disable_overscan=1

Delete the # in front of disable_overscan=1 to uncomment it.  This will enable the disable overscan feature and set it to a value of 1, or turn it on.  It should look like this.

# uncomment this if your display has a black border of unused pixels visible

# and your display can output without overscan

disable_overscan=1

Exit and save the file by pressing Ctrl x, then y, then Enter.

If you get an error when saving, it will be because you don’t have permission to edit the file.  So use sudo before the nano command when editing the file.

Reboot your Raspberry Pi for the changes to take effect and you will see the resolution fits the screen perfectly.

sudo reboot now

 

Setup: The Password

Right out of the box the Raspberry Pi needs a bit of finesse to get things working.  One of the most important things to do first is change your password.  Otherwise anyone can log in to it.

Let’s update our password for the default pi and root users.

passwd pi

Follow the prompt to enter and confirm your password.

passwd root

Follow the prompt again for the root password.

 

Let’s test our passwords to make sure they work.  You can change between these two users using the su command.  Starting from the pi user change to the root user.

su

Follow the prompt to enter your password.  Now you will see that pi@ will change to root@ and the $ before your cursor will change to #.

You are now root and can enter any command and make any changes to any files with out having to enter your password.  Be careful with that.

Change back to the pi user.

su pi

Enter your password and root@ will change to pi@ and the # will change to $.  Now you are not able make changes to important files or execute certain command with out putting sudo before the command.

Setup: The Network

Connecting to your wifi for the first time is easy as Pi on most computers and mobile devices.  On the Raspberry Pi my first reaction to the GUI was a confused one.  Since most everything can be done on the command line, and it’s much more cooler – let’s set it up that way.

To do this we will edit the wpa_supplicant.conf  file in the /etc directory that stores network configuration information.  We will use nano to edit the file and add the router name and password.

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add your wifi information in the following format to the bottom of the file.

network={
ssid=”router name”
psk=”password”
}

Save and close the file by pressing Ctrl x, then y to confirm to save the modifications, then press Enter to save it to the same file name and overwrite the file.

Let’s restart the wifi on the Raspberry Pi and check to see if the settings are working.  Turn off the wifi and turn it back on.

sudo ifdown wlan0

sudo ifup wlan0

Then check your wifi network interface is up and running using ifconfig.  The wifi interface is called wlan0 (wireless LAN 0).

ifconfig wlan0

You will see a block of information about wlan0 like the MAC address, IP addresses and other networking information.

To find out what your IP address is look for “inet addr:” in the second line.  You can show just this line with the following command.

ifconfig wlan0 | grep “inet addr”

You will see your IP, broadcast and mask like this.

inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0