Jan 102013
 

So a few people have tried to follow Part 3 of this series of posts, and had issues with the connections once everything is setup.
The main cause for that, was that hostapd would take away the IP address of wlan0 for some reason.
I worked around it by modifying the /etc/init.d/hostapd startup file.

In that file, there is a switch case statement which controls what the file does depending on how you run the file.

The example below is what you will see part way down the file. What we need to do is add in some commands into that block of code.

case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
start-stop-daemon --start --oknodo --quiet --exec "$DAEMON_SBIN" \
--pidfile "$PIDFILE" -- $DAEMON_OPTS >/dev/null
log_end_msg "$?"
;;
stop)

The command we will need to add are :
ifup wlan0

Which brings up wlan0 with the specified IP address. The IP address should have been setup in Part 3 of this series.

So the above block of code will now become –

case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
start-stop-daemon --start --oknodo --quiet --exec "$DAEMON_SBIN" \
--pidfile "$PIDFILE" -- $DAEMON_OPTS >/dev/null
log_end_msg "$?"
ifup wlan0
;;
stop)

This will force wlan0 to come up after hostapd is started.

Alternatively to force wlan0 to use an ip.address, replace ifup wlan0 with this
ifconfig wlan0 10.0.0.1 netmask 255.255.255.0 up
Hopefully this helps everyone when they come to making their Pi a WiFi Router ! 😀

Share
Jan 102013
 

A while ago, I was having an issue with one of my computer’s WiFi connection not connecting correctly on startup.
Maybe the signal was too weak on startup or the WiFi adapter just wasn’t fast enough when the computer wanted it to connect, for some reason it would never connect and I would have to manually run an ifup command to make it connect.

I ended up making this script to check whether the WiFi had an IP address, and if it didn’t it would take down the WiFi adapter and bring it back up again.
Now, I never need to worry about that computer’s WiFi connection !
I was also going to use this for one of my Raspberry Pi projects but never got around to putting the script onto the Pi, so anyone who has the issue where hostapd breaks the IP address, this script is perfect for it !


#!/bin/bash

wlan=`/sbin/ifconfig wlan0 | grep inet\ addr | wc -l`
if [ $wlan -eq 0 ]; then
/sbin/ifdown wlan0 && /sbin/ifup wlan0
else
echo interface is up
fi

I’ve setup this script to run as a cronjob every 5 minutes to make sure the WiFi stays up.

Share
Jan 072013
 

So I recently got back into the Pi as I could now use the PiSU to do a few things.
I saw a Logitech c110 webcam and decided to pick that up to test out the mjpeg world of webcams.

I started off with a fresh re-install of Raspbian Server Edition (RSE), and found that the instructions in Part 1 don’t work any more. Not sure why that is, but I’m assuming there’s an issue in the code somewhere for ffmpeg so I ended up using git to get the source code to build.

First step is to install git, as RSE didn’t include git.
I was root when I ran the rest of these commands, so if you’re not root, either sudo bash to become root, or just prepend sudo to everything

apt-get install git

Once git was installed, I went into /usr/src to download the source.

cd /usr/src
git clone git://source.ffmpeg.org/ffmpeg.git

Git retrieved the source code I needed to build ffmpeg from scratch, which is next up !
*Note*
If you need sound for ffmpeg, you will need to also install the libasound2-dev package which enables ALSA.

cd ffmpeg
./configure
make && make install

*Note* Compiling ffmpeg on the Pi will take a while, I left it running overnight to let it finish up. */Note*

Once ffmpeg was compiled and installed, I followed the same steps as before to setup ffmpeg.
I’ll repost the config that I used here –

Port 80
BindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 50000
NoDaemon

<Feed webcam.ffm>
file /tmp/webcam.ffm
FileMaxSize 10M
</Feed>

<Stream webcam.mjpeg>
Feed webcam.ffm
Format mjpeg
VideoSize 320x240
VideoFrameRate 10
VideoBitRate 20000
VideoQMin 1
VideoQMax 10
</Stream>

<Stream stat.html>
Format status
</Stream>

And the script file I use to start ffserver and ffmpeg

ffserver -f /etc/ff.conf & ffmpeg -v quiet -r 5 -s 320x240 -f video4linux2 -i /dev/video0 http://localhost/webcam.ffm

When I tried streaming, I found out that the webcam only supports 30fps and 15fps, so the driver automatically forces it to 15fps.
For some reason, ffserver also has trouble streaming mjpeg when the source is also mjpeg.
To stream straight mjpeg, I used the -vcodec mjpeg parameter by itself in the script to start ffmpeg. The output of ffmpeg shows that it is definitely streaming straight mjpeg but for some reason I can’t tap into the stream.
Looking at the ffmpeg/ffserver status page, it shows that ffserver is definitely pushing data to my devices, so I’m unsure as to what is happening there.

When I was streaming it from raw -> mjpeg, it could stream on my laptop via VLC but not on my Android Mobile.
I’m currently looking into why it might be doing this, but I’m stumped 🙁
Streaming from raw video -> mjpeg isn’t very cpu intensive for the Pi but it can’t keep up streaming at a good fps on the Logitech Webcam. I tried it on the lowest resolution possible which is 176×144 and I still had a ~2 second delay.

I tried some of my other cheaper webcams which didn’t have mjpeg format and they fared a bit better than the Logitech one in the Raw department, possibly due to the fact that the Logitech forced 15fps.

CPU usage was around 20% with the 176×144 resolution with a cheap webcam, and 25% with the Logitech c110
Almost doubling the resolution to 320×240 resulted in barely any video on the Logitech with ffmpeg stalling altogether, and not streaming to ffserver at all, and the same for the cheap webcam.

I seem to recall in older versions of ffmpeg and Raspbian that the cheaper webcams could still stream well at 320×240, so I’m unsure as to whether it’s ffmpeg causing issues or Raspbian now.

That’s all from me for now, hopefully this post helps someone get their webcams up and running 🙂

Share
Jan 012013
 

I’ve just updated the GUI for Perth Traffic Updates Plus
It now also features a feed from the Main Roads website direct, rather than going through Get The Bigger Picture.
From the main screen, under Today’s Alerts a section called ‘Updates from Main Roads’ has been added.

I’m looking for some feedback for this app, so if you’re from Perth, and comment on this post, ensure that your email is in the comments form and I will send you a free copy of the paid app in exchange for some feedback, whether negative or positive.

Share