Difference between revisions of "Cerealbot/rpi"

From Makers Local 256
Jump to: navigation, search
m (Authbind to Port 80: Fixed authbind directions)
m (MJPG-Streamer: Not done with this section)
Line 137: Line 137:
  
 
== MJPG-Streamer ==
 
== MJPG-Streamer ==
 +
 +
First, you may want to collect some information on your webcam:
 +
 +
To list available formats:
 +
<pre>
 +
v4l2-ctl --list-formats
 +
</pre>
 +
or
 +
<pre>
 +
v4l2-ctl -d /dev/videoX --list-formats-ext | less
 +
</pre>
  
 
=== Install ===
 
=== Install ===
 +
 +
[https://github.com/jacksonliam/mjpg-streamer mjpg-streamer] is by far the best solution for webcam streaming from the RPi. A recent update brought immense relief for CPU overhead (I believe in the form of H264 support).
 +
 +
Install some dependancies:
 +
<pre>
 +
sudo apt-get install libjpeg62-dev cmake subversion imagemagick libav-tools
 +
<pre>
 +
 +
Git the project:
 +
<pre>
 +
git clone https://github.com/jacksonliam/mjpg-streamer.git
 +
cd mjpg-streamer/mjpg-streamer-experimental/
 +
make clean
 +
make all
 +
</pre>
 +
 +
The base command to run mjpg-streamer. Don't worry about this, its handled by out init.d script.
 +
<pre>
 +
mjpg_streamer -b -i "./input_uvc.so -d /dev/video0 -n -f 5 -r 1280x720" -o "./output_http.so -p 8080 -w ./www"
 +
</pre>
 +
Previously I've used the -y flag for compatibility, which totally crushed the little CPU, but the most recent build of mjpg-streamer appears to work quite well with my Logitech webcam using the default MJPG codec.
 +
 +
=== Setup Init Script ===
 +
 +
In this folder, create a ''octo_start.sh'' script:
 +
 +
<pre>
 +
sudo update-rc.d octoprint defaults
 +
<pre>
 +
 +
=== Octoprint Protip ===
 +
 +
To use an http stream with octoprint, the URL has to be formatted correctly.
 +
 +
At first glance, I tried: cerealbox.256.makerslocal.org:8081, which didn't work.
 +
 +
Turns out Octoprint blindly appends a GET variable to the URL, which turns the above into: cerealbox.256.makerslocal.org:8081?2354jk345 which isn't a valid URL anymore.
 +
 +
So, you have to set up the webcam URL like: http://cerealbox.256.makerslocal.org:8081/
 +
 +
Here the trailing slash lands the GET variable. It took Hunter Fuller to figure all that out.
  
 
== Arduino/ATmega/AVR ==
 
== Arduino/ATmega/AVR ==

Revision as of 23:55, 8 June 2015

I'm using an RPi 2 model B for this project. Here are my notes.

OS

Install

I'm just using Rasbian from the foundation's download page. I find Debian derivatives to be comfortable for projects such as this. You're welcome to use whatever distro you like.

I strongly recommend you follow some official guide for installing the OS if you're at all uncertain. The notes here are sparse and meant to make it faster for me to recover from a broken system.

Get the archive, extract the file. Should be along the lines of '2015-05-05-rasbian-wheezy.img'.

Flash it to the SD card: 'sudo dd if=2015...img of=/dev/sdX bs=4M'.

Configure things with the raspi tool that loads on first boot, then install your favorite packages. Mine are:

htop vim emacs byobu tmux build-essential bash-completion haproxy authbind

Set the time/zone

http://aryo.lecture.ub.ac.id/configure-timezone-settings-on-raspberry-pi-raspbian-wheezy/

By default, Rasbian has an ntp daemon running, but you may still need to select a timezone. Use tzselect to set the timezone, then echo the returned line into .profile.

for me, this means:

echo "TZ='America/Chicago'; export TZ" >> ~/.profile

Setup SSH

I really recommend setting up SSH keys. There are many good guides for this elsewhere.

Setup Git

There's really no need to do this, but I like having git handle passwords for me.

https://help.github.com/articles/caching-your-github-password-in-git/

git config --global credential.helper 'cache --timeout=3600'

Setup Byobu

  • F1 allows you to set "log into byobu" to save some time while logging in.
  • 'C-a a' will send C-a to /usr/bin/screen, so you can use screen within byobu to debug serial connections.

Recover SD Filesystem

Hypothetically, in a strictly theoretical sense, with no basis whatsoever to the real world and real people:

Say someone at your hackerspace is horsing around and trips the breaker that your Pi is powered from. Well if you're lucky, then you just walk over and reboot the sucker. Sometimes that doesn't work though, and the computer's little SD card has become corrupt. Rather than break out the backup that you totally have, let's try a quick recovery first.

First, remove the SD card and insert it into your computer. Make sure it is unmounted.

Test recovery:

sudo dd if=/dev/sdX2 of=pi_bkup.img
cp pi_bkup.img pi_bkup_recv.img
sudo e2fsck -fy pi_bkup_recv.img

You may have to run that last command twice, idk why. If the program successfully recovers the test image, you have two options:

  • Flash this cured image file back to the partition it came from
  • Try to directly recover the SD card, since you know it has a chance of working.

The second option is faster:

sudo e2fsck -ft /dev/sdX2

Reference thread

Good luck!

Octoprint

Install

There are good guides elsewhere for installing Octoprint. I really don't see a need for repeating the instructions.

  • Install Octoprint
  • Have it start on boot
  • Configure your account
  • Generate an API key

Authbind to Port 80

If your network supports it, go ahead and use HAProxy. Ours didn't work initially, so I gave up and instead used Authbind.

https://mutelight.org/authbind

sudo apt-get install authbind
sudo touch /etc/authbind/byport/80
sudo chown pi /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80

Adjust a few lines in /etc/default/octoprint to match:

...
PORT=80
...
DAEMON_ARGS="--port=$PORT"
...

In /etc/init.d/octoprint you need to add a line for authbind in the variable declaration area:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Octoprint Daemon"
NAME="Octoprint"
DAEMON=/usr/local/bin/octoprint
AUTHBIND=/usr/bin/authbind
...

In the same file, you then need to find the line which starts octoprint and insert authbind:

start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \
       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- $DAEMON_ARGS

To:

start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \
       --exec $AUTHBIND $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- $DAEMON_ARGS

MJPG-Streamer

First, you may want to collect some information on your webcam:

To list available formats:

v4l2-ctl --list-formats

or

v4l2-ctl -d /dev/videoX --list-formats-ext | less

Install

mjpg-streamer is by far the best solution for webcam streaming from the RPi. A recent update brought immense relief for CPU overhead (I believe in the form of H264 support).

Install some dependancies:

sudo apt-get install libjpeg62-dev cmake subversion imagemagick libav-tools
<pre>

Git the project:
<pre>
git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental/
make clean
make all

The base command to run mjpg-streamer. Don't worry about this, its handled by out init.d script.

mjpg_streamer -b -i "./input_uvc.so -d /dev/video0 -n -f 5 -r 1280x720" -o "./output_http.so -p 8080 -w ./www"

Previously I've used the -y flag for compatibility, which totally crushed the little CPU, but the most recent build of mjpg-streamer appears to work quite well with my Logitech webcam using the default MJPG codec.

Setup Init Script

In this folder, create a octo_start.sh script:

sudo update-rc.d octoprint defaults
<pre>

=== Octoprint Protip ===

To use an http stream with octoprint, the URL has to be formatted correctly.

At first glance, I tried: cerealbox.256.makerslocal.org:8081, which didn't work.

Turns out Octoprint blindly appends a GET variable to the URL, which turns the above into: cerealbox.256.makerslocal.org:8081?2354jk345 which isn't a valid URL anymore.

So, you have to set up the webcam URL like: http://cerealbox.256.makerslocal.org:8081/

Here the trailing slash lands the GET variable. It took Hunter Fuller to figure all that out.

== Arduino/ATmega/AVR ==

=== Use GPIO for Programming/Comm ===

=== Compile and Flash from CLI ===