Bitbull Tech Notes - home of free minds ...

Modify Debian Package

I found this useful when needed to fix a pre-install error in a debian package.

mkdir another-out-dir
dpkg-deb -x some-deb.deb another-out-dir
dpkg-deb -e some-deb.deb another-out-dir/DEBIAN
# modify another-out-dir/DEBIAN/preinst)
dpkg-deb -b another-out-dir some-deb2.deb
dpkg -i some-deb2.deb

Control Relais Shield by Raspberry pi GPIO

I needed to use a Arduino relay shield with arduino GPIO.

Ther are some nice tools around which can do everything, but for me, I need a solid and robust on/off handler.

This are the tools:

http://raspberrypiguide.de/howtos/raspberry-pi-gpio-how-to/

This is the simple Script I wrote:

#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

[ $# -ne 2 ] && echo 'usage: gpio-relay.sh PIN [0|1]'
[ $# -ne 2 ] && exit 1

PIN=$1
MODE=$2

test -L /sys/class/gpio/gpio$PIN || echo $PIN > /sys/class/gpio/export
test -L /sys/class/gpio/gpio$PIN || exit 1
cat /sys/class/gpio/gpio$PIN/direction | grep -q out || echo out > /sys/class/gpio/gpio$PIN/direction
cat /sys/class/gpio/gpio$PIN/direction | grep -q out || exit 1
echo $MODE > /sys/class/gpio/gpio$PIN/value
echo "OUT-PIN: $PIN / VALUE: $(cat /sys/class/gpio/gpio$PIN/value)"

Result: fire same command multiple time, does no unneeded switch of  relay state

This are the PINs on RPI:

 +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | OUT  | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | ALT0 | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | ALT0 | CE1     | 11  | 7   |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |  28 |  17 | GPIO.17 |   IN | 0 | 51 || 52 | 0 | IN   | GPIO.18 | 18  | 29  |
 |  30 |  19 | GPIO.19 |   IN | 0 | 53 || 54 | 0 | IN   | GPIO.20 | 20  | 31  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+

FAZIT:

IT WORKS GREAT!!!

Do not use RxD and TxD PINs for Relay if there are other free PINs.
Because this two PINs are flickering during reboot of PI. :-)

 

 

 

Install watchdog on Raspberry Pi debian

With Raspberry Pi, you can build nice things, but sometimes it is hanging around (sdcard, power supply, ...).

To avoid such a state, I recommend to install Watchdog.

Here are my notes for debian 7.9 on Rasberry Pi B+

Install the Software:

apt-get update
apt-get dist-upgrade
rpi-update
reboot
apt-get install watchdog sendmail-bin

ls /etc/rc2.d/S0*watchdog
update-rc.d watchdog disable
ls /etc/rc2.d/S0*watchdog

modprobe bcm2708_wdog
echo "bcm2708_wdog" | tee -a /etc/modules
lsmod | grep bcm2708_wdog

 

Configure Watchdog as you need: /etc/watchdog.conf

#ping			= 192.168.223.254
#file			= /tmp/easyiot.log
#change                  = 600
watchdog-timeout = 10 max-load-1 = 12 min-memory = 1 watchdog-device = /dev/watchdog pidfile = /var/run/watchdog.pid realtime = yes priority = 1

 

Test it!!!

 

Enable it:

ls /etc/rc2.d/S0*watchdog
update-rc.d watchdog defaults
ls /etc/rc2.d/S0*watchdog
reboot

 

Test it again:

tail -f /var/log/syslog

 

Note:

There is a bug in debian watchdog startscript, which produces error message on watchdog restart.
But this is not a problem when booting the pi:

watchdog[2021]: cannot open /dev/watchdog (errno = 16 = 'Device or resource busy')

 

Create .deb packages for oracle java

1) Install needed Packages:
apt-get install build-essential checkinstall

 

1) Download OracleJRE:
mkdir -p /srv/devel/java
cd /srv/devel/java
http://www.java.com/de/download/
jre-xxx-linux-i586.tar.gz

2) check and modify this files:
*-pak
version.cfg
*.sh (install.sh for exception file generator)

3) create package with
bash create-deb.sh

4) done!

This is was you need to get it running:


vi create-deb.sh ###------ create this file ------
#!/bin/bash -e
# DESC: create debian package with checkinstall

. version.cfg

cd $DIR
rm -f backup* || true

apt-get remove --purge -y $NAME

checkinstall -D --backup --exclude=$DIR --fstrans=no --nodoc --pkgname $NAME --pkgversion $VERS --arch $ARCH --pkgrelease $REL --pkggroup $GRP --pkglicense "$LIC" --pkgsource "$SRC" --maintainer "$MAINT" --provides "$PROVIDES" --replaces="$REPLACES" --include $INCLUDE ./$INSTALL

rm -f backup* || true
### ------ end of file ------

vi deployment.properties ###------ create this file ------
deployment.security.level=MEDIUM
deployment.browser.path=/usr/bin/firefox
deployment.user.security.exception.sites=/usr/lib/oracle-java8-jre/lib/security/exception.sites
### ------ end of file ------
touch exception.sites

vi postinstall-pak ###------ create this file ------
#!/bin/sh
set -e

rm -f /usr/lib/mozilla/plugins/libnpjp2.so || true
rm -f /usr/lib/mozilla/plugins/*java* || true
update-alternatives --remove-all java || true
update-alternatives --install "/usr/bin/java" "java" "/usr/lib/oracle-java8-jre/bin/java" 1
update-alternatives --remove-all javaws || true
update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/oracle-java8-jre/bin/javaws" 1
update-alternatives --remove-all mozilla-javaplugin.so || true
update-alternatives --install "/usr/lib/mozilla/plugins/mozilla-javaplugin.so" "mozilla-javaplugin.so" "/usr/lib/oracle-java8-jre/lib/i386/libnpjp2.so" 1
### ------ end of file ------

vi postremove-pak ###------ create this file ------
#!/bin/sh
set -e
echo
### ------ end of file ------

vi preinstall-pak ###------ create this file ------
#!/bin/sh
set -e

rm -fr /usr/lib/oracle-java8-jre || true
### ------ end of file ------

vi preremove-pak ###------ create this file ------
#!/bin/sh
set -e

rm -f /usr/lib/mozilla/plugins/libnpjp2.so || true
rm -f /usr/lib/mozilla/plugins/*java* || true
update-alternatives --remove-all java || true
update-alternatives --remove-all javaws || true
update-alternatives --remove-all mozilla-javaplugin.so || true
### ------ end of file ------

vi version.cfg ###------ create this file ------
# ------ GERNERAL VARS ------
DIR=/srv/devel/java
NAME=oracle-java8-jre
VERS=1.8.45
REL=1
ARCH=i386
GRP=Crap
INSTALL=install.sh
INCLUDE=/usr/lib/oracle-java8-jre
PROVIDES='java-runtime, java2-runtime, java5-runtime, java6-runtime, sun-java6-bin, sun-java6-jre, sun-java6-plugin, java7-runtime, sun-java7-bin, sun-java7-jre, sun-java7-plugin'
REPLACES='oracle-java7-jre'
LIC='Oracle Binary Code License Agreement'
SRC='http://www.java.com/en/download/linux_manual.jsp'
MAINT="chris@bitbull.ch"

# ------ SETUP SPECIFIC VARS for $INSTALL ONLY ------
# JAVA PACKAGE
TGZ=jre-8u45-linux-i586.tar.gz
JRE_PROP_FILE=deployment.properties
JRE_EXCEPTION_FILE=exception.sites
### ------ end of file ------

vi install.sh ###------ create this file ------
#!/bin/bash

. version.cfg

cd $DIR
rm -rf /usr/lib/oracle-java*
rm -fr /usr/lib/jre*
rm -rf /etc/alternatives/*java*

tar -C /usr/lib -xzf $DIR/$TGZ

# create exception file
cat << EOF > $DIR/$JRE_EXCEPTION_FILE
https://server1.mysite.ch
https://javacrap.ch
https://printer-xy.ch
EOF

for D in /usr/lib/jre*/lib/
do
   cp $DIR/$JRE_PROP_FILE $D
   cp $DIR/$JRE_EXCEPTION_FILE $D/security/
done

cp -a /usr/lib/jre* /usr/lib/oracle-java8-jre
rm -fr /usr/lib/jre*

echo installation done
### ------ end of file ------

vi create-deb.sh ###------ create this file ------
#!/bin/bash -e
# DESC: create debian package with checkinstall

. version.cfg

cd $DIR
rm -f backup* || true

apt-get remove --purge -y $NAME

checkinstall -D --backup --exclude=$DIR --fstrans=no --nodoc --pkgname $NAME --pkgversion $VERS --arch $ARCH --pkgrelease $REL --pkggroup $GRP --pkglicense "$LIC" --pkgsource "$SRC" --maintainer "$MAINT" --provides "$PROVIDES" --replaces="$REPLACES" --include $INCLUDE ./$INSTALL

rm -f backup* || true
### ------ end of file ------
Home