Sonntag, 29. April 2018

minecraft server on pi

Try https://pimylifeup.com/raspberry-pi-minecraft-server/

Samstag, 25. November 2017

torrent i2p

inspired by https://www.deepdotweb.com/2016/12/31/torrenting-dark-net/

Install i2p accorindg to https://geti2p.net/en/download/debian

then follow instruction as in https://rebuildingalexandria.wordpress.com/2012/02/21/secure-and-anonymous-file-sharing-using-torrents-on-the-i2p-network-library-nu-exiles-take-a-look/


some hints that might help to get the beast running
https://github.com/m6urns/i2pberry/blob/master/README.md

Samstag, 17. Dezember 2016

surveillance cam : zoneminder and rasperry pi model b+

got a pi b+ model from straubson and installed: raspian jessy on it.

- add a file "ssh" in the /boot/ directory so you can access the pi without using a monitor, change the password afterwards.
Based on  https://bkjaya.wordpress.com/2016/11/23/how-to-install-zoneminder-1-29-0-on-raspberry-pi-3-with-raspbian-8-1-jessy-64-bit/  adapted it to work following these steps
-add zhe Jessie backports
sudo gedit  /etc/apt/sources.list
-add following line to the bottom of the file and save
deb http://http.debian.net/debian jessie-backports main
You will encounter signature errors, to
-fix those errors run following on the terminal

gpg --keyserver pgpkeys.mit.edu --recv-key  8B48AD6246925553
gpg -a --export 8B48AD6246925553 | sudo apt-key add -
gpg --keyserver pgpkeys.mit.edu --recv-key  7638D0442B90D010
gpg -a --export 7638D0442B90D010 | sudo apt-key add -

-Then run on the terminal
sudo apt-get update
-Install PHP, and MySQL server. You will be prompted to set a MySQL password
sudo apt-get install php5 mysql-server php-pear php5-mysql php5-gd
- Then install zoneminder using the software center of Raspbian
sudo apt-get install zoneminder

Create Zoneminder database in MySQL
There is a line missing from zm_create.sql that is packed with this version.
-If you search /usr/share/zoneminder/db/zm_create.sql (On Debian Wheezy, Your location may differ) for line:

CREATE TABLE `Logs` (

Simply add a line above this which reads:

DROP TABLE IF EXISTS `Logs`;

-Run following on the terminal

mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql
mysql -uroot -p -e "grant all on zm.*
to 'zmuser'@localhost identified by 'zmpass';"
mysqladmin -uroot -p reload
sudo chmod 740 /etc/zm/zm.conf
sudo chown root:www-data /etc/zm/zm.conf
sudo systemctl enable zoneminder.service
sudo adduser www-data video
sudo ln -s /etc/zm/apache.conf /etc/apache2/conf-enabled/zoneminder.conf
sudo a2enmod cgi
sudo a2enconf zoneminder
sudo a2enmod rewrite
sudo chown -R www-data:www-data /usr/share/zoneminder/
sudo systemctl enable zoneminder
sudo service zoneminder start

-Adding  timezone to PHP

sudo nano /etc/php5/apache2/php.ini

Edit 894 line to enter your time zone  and save the php.ini file
-then

sudo service apache2 reload

Open Zoneminder http://localhost/zm/

As USB Camera I used a 046d:08da Logitech, Inc. QuickCam Messanger (sic) according to lsusb

the resolution is bad, but, heck lets also account for annonymity

I set it up the following way

Monitor

If the USB camera on your pi tends to crash /stop working: set the resolution to 320 and 240


Zone Setting


Challenge: I want to count people using the biodegradbale bin . ( yep, nerdy...)

"The bin"



False events I get from

a) big cars/semis covering the bin



b) lights of cars passing by at night




Task

Set up zones

Zone 1 setting


zone 2 setting


zone 3



zone 4




and then I added as well a zone to overcome moving shadow induced by the trees/wind

  




Create a event video  every day

Since ffmpeg avconv etc and rasperry is not a love story, due to missing hardware accelerated video encoding of those packages use gstreamer - with that you use the very powerfull GPU, and it is actually converting the thousands of images to a vid faster than my WIN10 machine. Inspired , I managed to get the it run following this steps
sudo apt-get install gstreamer1.0-tools
sudo sh -c 'echo deb http://vontaene.de/raspbian-updates/ . main >> /etc/apt/sources.list'
add the missing key for this repo

gpg --recv-keys 0C667A3E
gpg -a --export 0C667A3E | sudo apt-key add -
 update your machine
sudo apt-get update
sudo apt-get -y upgrade
Install all necessary OPENMAX plugins for gstreamer

sudo apt-get install libgstreamer1.0-0 liborc-0.4-0 gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 gstreamer1.0-alsa gstreamer1.0-omx gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-base-apps gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-pulseaudio gstreamer1.0-tools gstreamer1.0-x libgstreamer-plugins-bad1.0-0 libgstreamer-plugins-base1.0-0
done

Create a bash script to create a movie out of daily images
and upload it to youtube based
install sudo apt-get python-pip 
based on on http://stackoverflow.com/questions/36962260/batch-upload-videos-to-youtube-via-command-line-python

#!/bin/bash
# Ugly script to generate AVI files for youtube  from zoneminder events
# Change the followingvariables to accomodate your install and where you want the videos exported, there are more links in the code to check

events_dir=/var/cache/zoneminder/events/
THEDATE=$(date --date="today" +%Y-%m-%d)
MYTITLE="KompostNutzer-Gaselstr-$THEDATE"

#cd $events_dir
# If you don't want the ENTIRE server's events and just want the latest week's worth
# then just add something like -mtime -7 before the "-print" part.  That's what I did later so I could have a weekly cron job.
find $events_dir -name "*-capture.jpg" -mtime -1 -print > /home/pi/temp/unsortedallevents.txt
sort -n /home/pi/temp/unsortedallevents.txt > /home/pi/temp/allevents.txt
filename='/home/pi/temp/allevents.txt'

echo Start copying files ....
cd temp/
aa=0
while read p; do
#    echo $p
cp $p `printf "%04d" $aa`.jpg; aa=$(($aa+1))
done < $filename

echo Start creating vid files .... grab a coffee
#gsttramer create movie
gst-launch-1.0 multifilesrc location=%04d.jpg index=1 caps="image/jpeg,framerate=24/1" ! jpegdec ! omxh264enc ! avimux ! filesink location=daily.avi

#upload
youtube-upload --title=$MYTITLE daily.avi

cd

#sleep 10
rm /home/pi/temp/*.jpg
rm /home/pi/temp/*.avi
rm /home/pi/temp/allevents.txt
rm /home/pi/temp/unsortedallevents.txt
exit

run the script as cron every nite

Mail events to Googledrive spreadsheet

install mail agent: http://www.sbprojects.com/projects/raspberrypi/exim4.php I prefer  exim4 with my gmail account, set gmail account to accept unsecure (sic) apps
since zoneminder EMAIL send is PITA
use https://ifttt.com/channels/google_drive/actions/81-add-row-to-spreadsheet

install

apt-get install html-xml-utils 

and add run with cron or a script for daily entries with a date and number events of the last 24


wget http://192.168.1.100/zm/index.php?view=events&page=1&filter[terms][0][attr]=DateTime&filter[terms][0][op]=%3E%3D&filter[terms][0][val]=-1+day&filter[terms][1][cnj]=and&filter[terms][1][attr]=MonitorId&filter[terms][1][op]=%3D&filter[terms][1][val]=1

hxnormalize -x zr49zcf | hxselect -s '\n' -c "h2" > FILE
sed "s@Events@@g" FILE > EVENTS
THEDATE=$(date --date="today" +%Y-%m-%d)
mail -s "$THEDATE #ZM" trigger@applet.ifttt.com < EVENTS

and in case: the USB cam does suddenly stops working: unplug cam reboot device use a different port, etc see
https://www.raspberrypi.org/forums/viewtopic.php?t=17212

I have script which checks if the conenction zoneminder usb cam is broken, and reboots the pi, which usually brings the cam back on
#/bin/bash
echo Checking if USB Cam is still running.....
cd /home/pi/temp/

#extracting last 10min of syslog
sed -n "/^$(date --date='10 minutes ago' '+%b %_d %H:%M')/,\$p" /var/log/syslog
> last10min.txt

#if usb cam is not working..simply reboot.
if grep -q "Failed to start capture stream: Broken pipe" last10min.txt ; ##note
the space after the string you are searching for
then
echo "Cam not working" ; echo "restarted zoneminder due to broken pipe of USBCAM
" | mail -s "zm restarted" david.oesch@gmail.com ; sleep 10m ; rm last10min.txt
; /sbin/reboot
else
echo "Cam working"
fi

#if usb cam is not working..simply reboot.
if grep -q "Failed to set video format: Device or resource busy" last10min.txt ;
 ##note the space after the string you are searching for
then
echo "Cam not working" ; echo "restarted zoneminder due to Device busy" | mail -
s "zm restarted" david.oesch@gmail.com ; sleep 10m ; rm last10min.txt ; /sbin/re
boot
else
echo "Cam working"; rm last10min.txt
fi


exit


To omit zoneminder running at night I halt via sunwait command on bootup:

install
wget http://www.risacher.org/sunwait/sunwait-20041208.tar.gz
tar xvzf sunwait-20041208.tar.gz
cd sunwait-20041208/
ls
make
sudo cp sunwait /usr/local/bin


then launch it on boot



i) Create a script called mystartup.sh in /etc/init.d/ directory(login as root)

# vi /etc/init.d/mystartup.sh

ii) Add commands to this script one by one:

#!/bin/bash
/usr/local/bin/sunwait civ down -1:00:00 46.90860N 7.41549E; /usr/sbin/service zoneminder stop

iii) Setup executable permission on script:
# chmod +x /etc/init.d/mystartup.sh
iv)Make sure this script get executed every time Debian Linux system boot up/comes up:

# update-rc.d mystartup.sh defaults 100


Where,

mystartup.sh: Your startup script name

defaults : The argument ‘defaults’ refers to the default runlevels, which are 2 through 5.

100 : Number 100 means script will get executed before any script containing number 101. Just run the command ls –l /etc/rc3.d/ and you will see all script soft linked to /etc/init.d with numbers.

Next time you reboot the system, you custom command or script will get executed via mystartup.sh. You can add more commands to this file or even call other shell/perl scripts from this file too.

And of course I have at sixish in the morning a cron which starts up zoneminder

Upload Event Images

Download gdrive-linux-rpi and install it according to this guide 

Analogue above, create a script called zm_alatm which scans messages for alarmstates and add it to run update-rc.d


#!/bin/bash
tail -f /var/log/messages | grep --line-buffered 'Gone into alarm state' | while read line; do cp -p "`find /var/cache/zoneminder/events/1/$(date +"%y/%m/%d/") -name "*aptur*" -printf "%p\n" | sort -rn | head -n 1`" /home/pi/eventimages/$(date +"%Y%m%d%H%M").jpg;  done




the Result? Here


UPDATE: 2018

with "stretch" if followed this https://wiki.zoneminder.com/Raspbian
- just install php (not php5)
- for raspberry pi camera modul follow http://marcel.duketown.com/?p=651

Samstag, 30. März 2013

XBMC and Raspberry Pi

Teste raspbmc: well the official package showed already some errors when an apt-get update was done... so I switced to xbian.org. I like this one since couchpotatoe and transmission are already built in, and I can install other packages I need... since it is based on debian

Xbian runs fine, but there seems to be an issue with my SD Card ( a transcend SDHC class 10 8GB card) file system gets corrupted after approx one week

Back up raspian/xbain installation:

Followed this instruction 


Montag, 30. Juli 2012

Raspberry PI

Raspian Linux image

- write to a ntfs external HD, 

configure /etc/fstab according to http://www.liberiangeek.net/2012/04/auto-mount-windows-ntfs-partitions-in-ubuntu-12-04-precise-pangolin/

UUID="822482F72482ED8B" /media/Pladde ntfs-3g defaults,auto,uid=1000,gid=1000,umask=000 0 0

- podcast: 

install "podracer"

- mail server and sending mails using the gmail account

mutt is your tool of choice
use this instruction from lifehacker 
and then, from 2013 onward sudo apt-get install  libsasl2-modules
  then echo "hello from raspi"   | mutt test@mail.com test

- couchpotato: dowload movies when the are available

follow this guide http://raspberry-blog.com/howto/installing-couchpotato-on-raspberry-pi/


- rtmp

Some radio streams are not available as mp3... solution: use a script to dump the stream and convert it to the mp3 Here the bash script, install rtmdump and mplayer and avconv


#!/bin/bash
URL="${1}"
FILEmp3="${URL##*\/}"
FILEwav="${FILEmp3%%.*}.wav"
FILE3="${FILEwav%%.*}.mp3"
WDIR="$(mktemp -d "/tmp/rtpdump.XXXXXX")"
trap 'rm -rf "${WDIR}"' EXIT INT HUP
rtmpdump -r ${URL} -o ${WDIR}/${FILEmp3}
mplayer ${WDIR}/${FILEmp3} -ao pcm:file=${FILEwav}
avconv -i $FILEwav  "$FILE3"
rm $FILEwav




- Samba 

according to http://www.forum-raspberrypi.de/Thread-tutorial-samba-windows-freigabe-server-installation-raspbian-debian and dont forget to add the support for symlinks in case you would like to use an mounted device

http://www.maistech.net/2011/09/ubuntu-server-samba-sharing-with.html


- Sync your data do the cloud

Dropbox aint working: no support for the ARM chip. Therefore I used BOX.com, as descriebd here:
http://linuxfordummies.org/mount-your-box-com-account-in-linux/
EDIT: dropbox seems to work now: see https://github.com/andreafabrizi/Dropbox-Uploader 

- Check & Monitor temperature... and mail it to you

https://github.com/fechu/PiTemp nice script for local display
and
https://sites.google.com/site/benhewitttechnology/raspberry-pi-with-xivley for the internet of things (may fail if network connection is to slow while torrenting)

- control podcast remote with a smartphone:

install vlc
and make sure you use the 3.5mm jack (thanks to this post)
sudo modprobe snd_bcm2835sudo amixer cset numid=3 1

edit  sudo nano /usr/share/vlc/lua/http/.hosts according to http://wiki.videolan.org/Documentation:Modules/http_intf#Access_control
start vlc on boot based on http://mvpmc.wikispaces.com/vlc the script , add  the --extraintf=http in the vlc call at the end and 

and finally add the script with 
update-rc.d vlc defaults

Sonntag, 18. März 2012

convert youtube to mp3 bash script

this nice script will do it
call it youtube2mp3.sh and call it up like  youtube2mp3 "url youtube" "title.mp3"


x=~/.youtube-dl-$RANDOM-$RANDOM.flv
youtube-dl --output=$x --format=18 "$1"
ffmpeg -i $x -acodec libmp3lame -ac 2 -ab 128k -vn -y "$2"
rm $x

prerequisites here; http://askubuntu.com/questions/218932/convert-youtube-to-mp3