Tablet Photo Frame with FTP Sync and Automated Start&Stop

I was searching for a Photo Frame to be placed at the grandparents of my little daughter with the following features:

  • Synchronisation with a FTP server to allow remote update of photos
  • Automated stop in the evening and start in the morning to prevent the photo frame from illuminating the room

As I could not find a turnkey solution I deceided to build it on my own based on an old Samsung Galaxy Tab 3 8.0 (T310). Note: The tablet needs to be rooted to allow automated stopping of the photo frame in the evening.

Step 1: FTP Synchronisation

  • Create FTP server login (I used my hosted webspace to create a ftp subaccount)
  • Create local folder for pictures on tablet (e.g. /sdcard/fotos_bilderrahmen)
  • Install FolderSync lite app (Play Store)
  • In FolderSync create “Account” using your FTP login data
  • In FolderSync create “Folderpair”. Select the FTP-Account and the local folder. Define scheduling e.g. hourly, activate deleting files on local side if deleted on server.

Step 2: Photo Frame app

  • Install Photo Frame app Premium (Play Store)
  • Start app and configure (e.g. refresh folder content e.g. 15min, orientation, transition between photos, …)
  • Select local photo folder (SD) and create startpage shortcut to start photoshow directly from this folder (use button top right)

Step 3: Automate start and stop of photo frame app

  • Install Automate app (Play Store)
  • Start app and activate app start after boot (in app properties)
  • Create new flow (see screenshots, take care on values for app start block)

    Step 4: Integrate in wooden photo frame

    • Fix tablet with double sided mirror tape (e.g. Tesa)
    • Glue additional wooden spacers to stabilize
    • Optional: Order (or DIY) taylored passepartout (e.g. art&more)

    Jdownloader Seedbox on Debian vServer

    The last ~1 year, I used my Raspi to run Jdownloader in headless mode (see post) and store/extract files on my local NAS.
    As I wanted to have high bandwith access to that files from several locations, I deceided to set up a private server with some storage and access via CIFS/FTPS/SFTP/Webdavs for Kodi.
    I figured out a hosting provider which offers a vServer monthly for about 5€ and additional storage for about 6€ (for 500GB). This storage can be accessed internally as well as externally via CIFS/FTPS/SFTP/Webdavs, which makes it very easy for me, because I do not need to care about setting up external access to the storage via the vServer.
    All I had to to do is to set up JDownloader headless on the Debian minimal and to mount the storage (I am using CIFS):

    Based on:
    https://kaistech.wordpress.com/2016/01/31/jdownloader-headless-on-raspberry-pi/
    https://misterunknown.de/blog/2016/05/jdownloader-headless-auf-debian-ubuntu-server-installieren.html

    Login as root

    mkdir /home/jd
    useradd -g users -d /home/jd -s /bin/bash jd
    chown -hvR jd /home/jd

    apt-get install openjdk-7-jre-headless

    su jd
    mkdir /home/jd/jdownloader
    cd /home/jd/jdownloader
    wget http://installer.jdownloader.org/JDownloader.jar
    java -jar JDownloader.jar
    reboot

    su jd
    cd /home/jd/jdownloader
    java -jar JDownloader.jar
    (then press y to enter MyJdownloader Logins)
    Exit with Strg-C

    Exit su jd with “exit” (now you are root again)

    touch /home/jd/jdownloader/JDownloader.pid
    nano /etc/init.d/jdownloader
    (insert from: https://gist.github.com/WtfJoke/45796a5cfb0e746c84eb0d5b4650e11c)

    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides: JDownloader2
    # Required-Start: networking
    # Required-Stop:
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: JDownloader2 server daemon
    # Description: JDownloader2 server daemon
    ### END INIT INFO
    
    DIR="/home/jd/jdownloader"
    PIDFILE="$DIR/JDownloader.pid"
    JAVA="/usr/bin/java"
    PARAM="-Djava.awt.headless=true -jar $DIR/JDownloader.jar"
    USER="jd"
    
    start_daemon () {
    start-stop-daemon --start --background --oknodo --chuid $USER --make-pidfile --pidfile $PIDFILE --exec $JAVA -- $PARAM
    }
    
    stop_daemon () {
    start-stop-daemon --stop --pidfile $PIDFILE
    }
    
    # Switch case
    case "$1" in
    start)
    # On start
    echo "Start JDownloader"
    start_daemon
    ;;
    
    stop)
    # On stop
    echo "Stop JDownloader"
    stop_daemon
    ;;
    
    restart)
    # On restart
    echo "Restart JDownloader"
    start_daemon
    stop_daemon
    ;;
    *)
    # Default action
    echo "(start|stop|restart)"
    ;;
    esac
    
    exit 0
    

    chmod 755 /etc/init.d/jdownloader
    systemctl daemon-reload
    systemctl enable jdownloader
    reboot

    Storage connected with CIFS like this: https://anteru.net/blog/2014/09/20/2480/

    Login as root

    apt-get install autofs cifs-utils

    For safety reasons disable some server services which came with autofs and cifs-utils:
    systemctl disable rpcbind
    (portmapper server which came with autofs)
    systemctl disable smbd
    (SAMBA server which came with cifs-utils)
    systemctl disable nmbd
    (Netbios server which came with cifs-utils)
    reboot

    check with “netstat -tuplen”
    it should only show sshd listening on port 22 (IPv4 and IPv6), dhclient and systemd-timesyn.

    mkdir /mnt/net
    mkdir /mnt/net/smb
    nano /etc/auto.master
    -> insert: /mnt/net/smb /etc/auto.cifs-shares
    su jd
    nano /home/jd/.smbcredentials
    -> insert:
    username=
    password=

    exit

    find id for user jd
    cut -d: -f1,3 /etc/passwd
    -> e.g. id=1000

    nano /etc/auto.cifs-shares
    -> insert: storage -fstype=cifs,rw,credentials=/home/jd/.smbcredentials,uid=1000 ://cifspathtoyourstorage/subfolder

    service autofs restart

    su jd
    cd /mnt/net/smb/storage
    touch test.txt

    change JDownloader path via MyJdownloader to /mnt/net/smb/storage

    In Expert settings change MyJDownloaderSettings: Direct Connect Mode to “Disable direct connections” (this will change Jdownloader not to open a public tcp port on your server!).

    Set up IPv4 to IPv6 portforwarder on vServer

    To be used of you are behind a DS-Lite Cable/DSL-Connection and only have a fixed IPV6 (and a floating NATed IPv4).
    Same service like offered by Universal Portmapper from e.g. feste-ip.net

    Login as root
    apt-get install 6tunnel

    e.g. for OpenVPN running on remote host
    6tunnel localport remotehost remoteport
    6tunnel 1194 homeserver.remote 1194
    or
    6tunnel 10000 homeserver.remote 1194

    Show running processes of 6tunnel
    ps aux | grep 6tunnel

    Create bootup-start/stop-script:
    nano /etc/init.d/6tunnel
    Insert:

    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides: 6tunnel
    # Required-Start: networking
    # Required-Stop:
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: 6tunnel server daemon
    # Description: 6tunnel server daemon
    ### END INIT INFO

    PARAM="/usr/bin/6tunnel 10000 homeserver.remote 1194"
    USER="root"

    start_daemon () {
    start-stop-daemon --start --background --oknodo --chuid $USER --exec $PARAM
    }

    stop_daemon () {
    start-stop-daemon --stop --name 6tunnel
    }

    # Switch case
    case "$1" in
    start)
    # On start
    echo "Start 6tunnel"
    start_daemon
    ;;

    stop)
    # On stop
    echo "Stop 6tunnel"
    stop_daemon
    ;;

    restart)
    # On restart
    echo "Restart 6tunnel"
    start_daemon
    stop_daemon
    ;;
    *)
    # Default action
    echo "(start|stop|restart)"
    ;;
    esac

    exit 0

    chmod +x /etc/init.d/6tunnel

    Test with:
    /etc/init.d/6tunnel start
    netstat -tulpen
    /etc/init.d/6tunnel stop

    systemctl daemon-reload
    systemctl enable 6tunnel

    OpenVPN on Unitymedia DS-Lite Cable DSL

    Install OpenVPN on Raspi and create Login-Certificate for 1 User (Client1)

    http://www.feste-ip.net/fip-box/basic/fip-box-vpn/
    (https://jankarres.de/2013/05/raspberry-pi-openvpn-vpn-server-installieren/)

    Install required packages and upgrade system based on bash-script from feste-ip.net
    (optional: modify sh-Script for your own demands)

    sudo su
    cd /tmp
    wget http://www.portmapper.de/fipbox/fipboxvpn.sh
    bash fipboxvpn.sh

    Enable DynDNS for IPv6 (because prefix will change every few days)

    http://blog.belodedenko.me/2013/07/dynamic-ipv6-updates-using-ddclient-for.html

    Open Firewall of Raspi IPv6 for Port 1197

    Enable IPv4->IPv6 Port Forwarding using feste-ip-net and DynDNS Host

    http://www.feste-ip.net/dslite-ipv6-portmapper/universelle-portmapper/

    Calling a HTTP url from FHEM to trigger action

    I need to call HTTP urls from FHEM for several things, like firing IR signals to my TV (see my post: https://kaistech.wordpress.com/2016/10/09/wifi-infrared-ir-remote-extension-using-esp8266/ ).
    As far as I know, FHEM currently does not have a way to do this easily (HTTPMOD seems to be a bit too complicated for that).

    My solution is based on a simple PERL script which is called directly from FHEM:

    Script /home/pi/irhttp.pl:

    #!/usr/bin/perl -w

    use warnings;
    use strict;
    use Time::HiRes qw/time usleep/;
    use Socket qw(:all);
    use POSIX ":sys_wait_h";

    use LWP::Simple;

    #print $ARGV[0];
    #print "\n";

    my $url = 'http://192.168.2.114/ir?code=';
    $url .= $ARGV[0];

    my $content = get($url);
    die "Can't GET $url" if (! defined $content);

    Then make it executable: sudo chmod +x /home/pi/irhttp.pl

    Now you can call it from FHEM e.g. from a DOIF like this:

    define DOIF_Dummy_WohnzimmerTVMode DOIF ([Dummy_WohnzimmerTVMode]) ({system ("/home/pi/irhttp.pl 50153655 &")})

    Note: Here I pass the a argument to the Perl script which is attached to the URL.

    Wifi Infrared IR Remote Extension using ESP8266

    In the last months we integrated a rising count of IoT devices into our FHEM based homeautomation system (Wifi switches, LED lights, door and window sensors etc.). Nevertheless, most of my entertainment devices (TV, Sounddeck) were not integrated and required their own infrared remote to be turned on, switch channel, etc. A infrared adapter needed to get in place to integrate these devices into my tablet based FHEM interface.

    As I had a lot of success using ESP8266 modules for 24×7 running devices in the past, I deceided again to use a ESP8266 (Wemos D1 mini module, cheap available at Aliexpress). My aim was to let the ESP fire two IR leds which are installed directly in front of at TV and Sounddeck. A HTTP server running on the ESP receives the IR request in form of decimal IR code (which I identified before using a IR receiver on a ESP).

    Hardware
    – ESP8266 (e.g. Wemos D1 mini or NodeMCU)
    – 2x IR transmitting LED (any 950nm IR led will work), ~20Ohm 0.5W resistor, NPN transistor (any NPN like BC547, BC548 or PN2222 will work) , 330Ohm 0.125-0.25W resistor
    – optional to identify IR codes using your devices IR remote: IR-receiver 38kHz (e.g. TSOP 4838)

    My code is based on this nice library and its examples:https://github.com/markszabo/IRremoteESP8266/blob/master/README.md

    Using the TSOP4838 wired to 5V of Wemos board, GND and D2 (aka GPIO 4) and the example from the libary (https://github.com/markszabo/IRremoteESP8266/blob/master/examples/IRrecvDumpV2/IRrecvDumpV2.ino) I identified the following IR codes for my device (library will print out HEX but DEC required for HTTP call lateron):

    TV ONOFF
    NEC
    32
    0x2FD48B7
    50153655

    AUDIO ONOFF
    NEC
    32
    0x40BFEA15
    1086319125

    AUDIO VOL+
    NEC
    32
    0x40BFB04F
    1086304335

    AUDIO VOL-
    NEC
    32
    0x40BFF20D
    1086321165

    AUDIO SOURCE BT
    NEC
    32
    0x40BF8877
    1086294135

    AUDIO SOURCE TOSLINK
    NEC
    32
    0x40BF08F7
    1086261495

    The hardware of the IR transmitting server is set up as follows. I use the 5V of Wemos board which is hardwired to the 5V rail of the USB power supply:

    The IR leds are consuming about 100mA of current. I deceided to run 2 in series with a 20Ohms 0.5W resistor burning about 2Volts (3Volts burned by two led and transistor collector-emitter). The NPN transistor is driven by D2 (aka GPIO 4) via a 330Ohms resistor.

    My Arduino sketch for the ESP bases on this example from the library: https://github.com/markszabo/IRremoteESP8266/blob/master/examples/IRServer/IRServer.ino

    A few pictures of the hardware:

    Finally now I am able to put my old IR remotes away and send out IR commands via simple HTTP request to the ESP (e.g. http://192.168.1.110/ir?code=104937399).

    Remarks:
    The examples of the library are using GPIO 2. So the PIN needs to be updated in the Arduino sketches to GPIO 4.
    I configured my DSL router, to assign the same IP for the ESP all the time.

    Hint: See my next post how to call the IR server from FHEM: https://kaistech.wordpress.com/2016/10/11/calling-a-http-url-from-fhem-to-trigger-action/

    Door bell via SIP call with Arduino and Ethernet shield

    Since mid of the 90s we had a ISDN PBX at home. This PBX had a port to connect a door bell pushbutton and perform a ring to a defined group of internal phones. Now we switched over to SIP trunk (Sipgate) and a AVM Fritzbox as internal PBX. Unfortunately the Fritzbox does not have such a door bell port, so I had to develop a solution:

    – Arduino Uno
    – Arduino Ethernet Shield
    – Door bell pushbutton triggering Arduino digital input pin via optocoupler
    – Performing SIP call to a Fritzbox callgroup (eg **701) when button is pressed
    – watchdog to restart Arduino on hangup

    During the first tests I found out, the Ethernet Shield tends to hang up after a few hours. Therefore, after pressing the pushbutton the Ethernet Shield will be reset before the SIP call is being performed.
    To reset the Ethernet shield I connected a Arduino digital out pin to the reset port of the Ethernet Shield which goes to LOW to reset the shield. Beware, that normally the shields reset pin is connected with the reset pin of the Arduino via pin header. This would do a reset of the Arduino as well. To prevent this, I bended this one pin of the shield to prevent from connecting.
    Additionally, I used a 0.5W resistor to drive some power through the pushbutton. I found out, that these kind of buttons tend to have a problem when the current is too low (e.g. because of corrosion).

    In the Fritzbox the following needs to be prepared:
    – create a SIP user/password for the door bell device
    – create a group containing all devices which will ring on door bell press

    DSCF9351.JPG

    DSCF9352.JPG

    (on the second picture you can see the reset pin of the Ethernet Shield bond by side)

    Schematic:

    FritBoxBell_Schematic

    Code: https://dl.dropboxusercontent.com/u/561711/kaistech.wordpress.com/FritzboxBell.zip

    The device is running for more than one year now and seems to be very reliable.