Tuesday, December 11, 2018

RASPBERRY PI 2 MODEL B WITH TL-WN725N Version 2

#********************************************************************************
# RASPBERRY PI 2 MODEL B ON DEBIAN STRETCH 9.6
#********************************************************************************

root@raspime:~# cat /etc/debian_version
9.6

root@raspime:~# cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

root@raspime:~# uname -a
Linux raspime 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l GNU/Linux

root@raspime:~# cat /proc/cpuinfo | grep Revision
Revision        : a01041

Note :
Hardware revision code from Cpuinfo for Pi 2 Model B is a01041 (Sony, UK) or a21041 (Embest, China).


If you are not sure for your TP-LINK wifi dongle version , please refer to this page
#*******************************************************************************
# WIFI DONGLE TL-WN725N Version 2
#*******************************************************************************

root@raspime:~# lsusb
Bus 001 Device 005: ID 0bda:8179 Realtek Semiconductor Corp. RTL8188EUS 802.11n Wireless Network Adapter


#*******************************************************************************
# DRIVER FOR TL-WN725N Version 2
#*******************************************************************************

root@raspime:~# sudo wget http://downloads.fars-robotics.net/wifi-drivers/install-wifi -O /usr/bin/install-wifi
root@raspime:~# sudo chmod +x /usr/bin/install-wifi
root@raspime:~# /usr/bin/install-wifi

Then run install-wifi to install driver automatically, for more information (updated information) please refer to this site




MINIDLNA - AUTO SCAN WHEN USB DISK INSERTED

READ THIS BEFORE CONTINUE

#
#*******************************************************************************
# RASPBERRY PI 2 MODEL B ON DEBIAN STRETCH 9.6
#*******************************************************************************
#
# /etc/os-release
#
root@raspime:~# cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

Instal needed package using this command
root@raspime:~# apt-get install udisks-glue policykit-1 supervisor

#
#*******************************************************************************
# MINIDLNA CONFIGURATION
#*******************************************************************************
#
# /etc/minidlna.conf
#
root@raspime:~# cat /etc/minidlna.conf

media_dir=V,/media/minidlna/MOVIES
media_dir=A,/media/minidlna/MUSICS
media_dir=P,/media/minidlna/PICTURES

friendly_name=Raspime Media Server
inotify=yes
notify_interval=30
db_dir=/var/cache/minidlna
log_dir=/var/log
log_level=warn


Check minidlna version
root@raspime:~# apt show minidlna

Package: minidlna
Version: 1.2.1-1
Status: install ok installed
Priority: extra
Section: checkinstall
Maintainer: diantokam@raspime
Installed-Size: 598 kB
Provides: minidlna
Download-Size: unknown
APT-Manual-Installed: yes
APT-Sources: /var/lib/dpkg/status
Description: MiniDLNA Version 1.2.1 Compiled December 4, 2018
Compiled for Debian 9.6 by  diantokam.blogspot.com


root@raspime:~# minidlnad -V

Version 1.2.1

#
# /etc/init.d/minidlna status
#
root@raspime:~# /etc/init.d/minidlna status

minidlna.service - LSB: minidlna server
Loaded: loaded (/etc/init.d/minidlna; generated; vendor preset: enabled)
Active: active (exited) since Thu 2018-12-06 20:00:02 WIB; 6min ago
Docs: man:systemd-sysv-generator(8)
Process: 7385 ExecStop=/etc/init.d/minidlna stop (code=exited, status=0/SUCCESS)
Process: 7395 ExecStart=/etc/init.d/minidlna start (code=exited, status=0/SUCCESS)

Dec 06 20:00:02 raspime systemd[1]: Started LSB: minidlna server.

#*******************************************************************************
# SUPERVISOR
#*******************************************************************************

root@raspime:~# cat /etc/supervisor/conf.d/minidlna_scanmedia.conf

[program:minidlna_scanmedia]
command=/usr/local/bin/minidlna_scanmedia.sh
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/minidlna_scanmedia-out.log
stderr_logfile=/var/log/supervisor/minidlna_scanmedia-err.log



root@raspime:~# /etc/init.d/supervisor restart

[ ok ] Restarting supervisor (via systemctl): supervisor.service.


root@raspime:~# supervisorctl

minidlna_scanmedia               RUNNING   pid 10259, uptime 0:01:45
udisks-glue                      RUNNING   pid 10260, uptime 0:01:45

supervisor>

* Type quit for quit

#*******************************************************************************
# MINIDLNA_SCANMEDIA.SH
#*******************************************************************************
#
# /usr/local/bin/minidlna_scanmedia.sh
#
root@raspime:~# cat /usr/local/bin/minidlna_scanmedia.sh

#!/bin/bash
# Created by diantokam.blogspot.com
# December 8, 2018
# This script will runing continuous to check if any
# flashdisk mounted on /media/ by checking log from
# udisk-glue fromsupervisord


while :
do
cat /var/log/supervisor/udisks-glue-out.log | grep -v "BOOTLOADER" | grep media | grep Successfully
cat /var/log/supervisor/udisks-glue-out.log | grep media | grep Successfully
        if [ $? -eq 0 ]
                then
                echo `date`
                echo "mounted media successfully and minidlna will force-reload"
                sleep 10

                service minidlna force-reload
                sleep 5
                echo "" >/var/log/supervisor/udisks-glue-out.log
                break
        fi
                #echo "scan terus gan"
sleep 3
done


WHEN USB FLASHDISK INSERTED AND MOUNTED BY UDISK-GLUE

Supervisord continously run minidlna_scanmedia.sh until it recognize there is usb disk mounted on /media/SLAX9.4, it will run "service minidlna force-reload" and then clear "/var/log/supervisor/udisks-glue-out.log" so it becomes empty

#*******************************************************************************
#ACTION !
#*******************************************************************************
root@raspime:~# mount | grep media

/dev/sdb1 on /media/SLAX9.4 type fuseblk (rw,nosuid,nodev,noatime,sync,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096,uhelper=udisks)


root@raspime:~# cat /var/log/supervisor/minidlna_scanmedia-out.log

Successfully automounted /dev/sdb1 at /media/SLAX9.4
Thu 6 Dec 20:31:43 WIB 2018
mounted media successfully and minidlna will force-reload

The script will then clear udisks-glue-out log

root@raspime:~# cat /var/log/supervisor/udisks-glue-out.log
** EMPTY **

Configure automount for usb drives using UDISK-GLUE and SUPERVISOR

#
#*******************************************************************************
# RASPBERRY PI 2 MODEL B ON DEBIAN STRETCH 9.6
#*******************************************************************************
#
# /etc/os-release
#
root@raspime:~# cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
root@raspime:~# apt-get install udisks-glue policykit-1 supervisor


#
#*******************************************************************************
# UDISK-GLUE
#*******************************************************************************
#
# /etc/udisks-glue.conf
#
root@raspime:~# cat /etc/udisks-glue.conf
filter disks {
    optical = false
    partition_table = false
    usage = filesystem
}

match disks {
           automount = true
          # For NTFS mount with read and write
           automount_options = { sync, noatime, 'dmask=0000', 'fmask=0000', 'umask=0000' }
           post_mount_command = "mount-notify mounted %device_file %mount_point"
           post_unmount_command = "mount-notify unmounted %device_file %mount_point"
}


#
#*******************************************************************************
# SUPERVISOR
#*******************************************************************************
#
# /etc/supervisor/supervisord.conf
#
root@raspime:~# cat /etc/supervisor/supervisord.conf
[unix_http_server]

[supervisord]

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]

[include]
files = /etc/supervisor/conf.d/*.conf
[inet_http_server]

# For web accesses
port=*:9001
username=admin
password=admin

#
# /etc/supervisor/conf.d/udisks-glue.conf
#
root@raspime:~# cat /etc/supervisor/conf.d/udisks-glue.conf
[program:udisks-glue]
user = root
command = udisks-glue -f
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/udisks-glue-out.log
stderr_logfile = /var/log/supervisor/udisks-glue-err.log


root@raspime:~# ls -al /etc/supervisor/conf.d/
total 16
drwxr-xr-x 2 root root 4096 Dec  6 20:15 .
drwxr-xr-x 3 root root 4096 Dec  6 13:29 ..
-rw-r--r-- 1 root root  209 Dec  6 14:25 udisks-glue.conf

Restart service after create configuration file
root@raspime:~# /etc/init.d/supervisor restart
[ ok ] Restarting supervisor (via systemctl): supervisor.service.

Check if udisk-glue process from supervisor running or not
root@raspime:~# supervisorctl
udisks-glue                      RUNNING   pid 10260, uptime 0:01:45
supervisor>
* Type quit for quit

OR check via web