Essays / s /

Control Max2Play with Logitech Smart Control

Max2Play (www.max2play.com) on Raspberry Pi 3 is a great alternative for Logitech Squeezeboxes.

I needed a Jivelite setup for my HD screen to control my Logitech Touch as a couch potato without using binoculars. I had set my mind on controlling Max2Play with the Logitech Smart Control. Out of the box it doesn't:

Connect the Harmony bluetooth keyboard

  • First get Max2Play (Premium) and Jivelite up and running:
    Burn the image on SD, Expand Filesystem, Update Kernel and Update Packages, Update Max2play.
    Install Raspberry Cam plugin if you need it. If this plugin is installed later it won't work (in my case anyway).
  • Install the JiveLite and Bluetooth plugin from the max2play webpage.
  • In MyHarmony or the Harmony App create a new device: a Windows PC. Harmony remotes feature a bluetooth keyboard for three devices: Apple, WIndows and Other OS's. The big difference is the available keys. Only Apple and Windows have enough keys to play with and Windows offers the most. For instance "Esc" and most important "0" - "9".
  • Next create a Harmony activity with this new device and your other devices.
  • During the process Harmony wants to pair it's bluetooth keyboard to the Raspberry:
  • Start a SSH connection to the Pi3: ssh pi@your.ip password is "raspberry"
  • Start bluetoothctl
  • In bluetoothctl type scan on
  • The mac adress of the Harmony keyboard should popup
  • pair the harmony keyboard with pair 12:34:56:78:90. Replace the ID with your ID
  • Connect the harmony keyboard with connect 12:34:56:78:90.
  • Trust the harmony keyboard with trust 12:34:56:78:90
  • Harmony should display a message "pairing succesfull"
  • The webpage of max2play should now display a green text on the bluetooth page: "Following Bluetooth Speakers are known: Harmony Keyboard (12:34:56:78:90)". Yes your Harmony Keyboard is recognized as Bluetooth Speakers.
  • exit bluetoothctl
  • Keep SSH open
Program your Harmony remote
The basic keys are now available for your Harmony like direction keys and Esc which do most of the job controlling Jivelite. Program your remote the way you want it, minimal:
- Direction keys under the direction keys.
- Enter under the OK button
- and Esc under the Exit button.
This way the Harmony also works with Kodi if you need to remote control Kodi. 
The hard part are the others keys. Jivelite supports every function with a hotkey. The file which controls this is /opt/jivelite/jivelite/share/jive/jive/InputToActionMap.lua. With a normal wired or bluetooth keyboard you can use all action keys. The Harmony bluetooth keyboard has most if not all normal keys missing. 

I really needed the "Add" shortcut which does the same as the Add button on a Logitech Touch remote. With a normal keyboard "a" would do the job. Those keys are not available on a Harmony remote. Time to hack and remap some keys:

Hacking JiveLite
  • (re)open SSH to max2play
  • cd /opt/jivelite/jivelite/share/jive/jive 
  • sudo nano InputToActionMap.lua
  • Find any line with ["1"] ["2"] etc and comment it out, for instance:
    -- ["1"] = "play_preset_1",
  • Add the following lines:
    -- begin logitech harmony
    ["1"] = "go_current_track_info",
    ["2"] = "go_home_or_now_playing",
    ["3"] = "add",
    ["4"] = "add_end",
    ["5"] = "play_next",
    ["6"] = "play",
    ["7"] = "pause",
    ["8"] = "volume_up",
    ["9"] = "volume_down",
    ["0"] = "mute",
    ["\13"] = "go", -- RETURN

    --end logitech harmony
  • Don't forget the last one. Without this hack Jivelite won't respond to the Ok button.
  • Save the file and exit.
  • Exit SSH
  • Restart Jivelite or reboot the Pi. Don't restart or reboot with nano editing the lua file! If you do reinstall Jivelite from the max2play webpage and reapply the hack.
  • After a reboot of the Pi sometimes your remote doesn't respond. Stop and Start JiveLite from the max2play webinterface and JiveLite now recognizes the (Harmony Bluetooth) keyboard.
  • The "1" key is available for Harmony remotes. Program the "1" key under any button for instance the Info button. "2" goes under the Menu button, "6" for Play, and "7" for Pause. "4" and "5" some other button.
Done!

Remember:
  • Everytime you reinstall Jivelite, the file InputToActionMap.lua is back to factory defaults and you need to fire up SSH to reapply the hack.

Koken export original images

Koken organizes photos in Albums (and Sets), The original uploaded photos are stored in an obscure folder structure like:

/YourPathToKoken/koken/storage/originals/g2/5n/originalfilename.jpg

Every uploaded photo has two unique subfolders in the koken storage. Impossible to see what goes where from Finder or FileExplorer. The PHP script below reads the Koken database and copies the original files to a new location with a separate folder for each album.

It's one of my first scripts in PHP and very, very brute force :)
It runs on OSX and should run on Linux with minor adjustments (osx command cp -n is unsupported on other unix systems). Windows users must edit the mkdir and cp parts.

I think something like this should be part of the Koken GUI. A set of folders and files in the structure of Koken is needed for offline viewing on digital image frames and photoviewers on tablets, smartphones, TV's etc. etc. In my case Plex. Or just as a backup.

I need to update the code below. visibility instead of listed should be used in the SQL statements. See my other blog post.


/**
Koken organizes photos in albums
The original uploaded photos are stored in an obscure folder structure like
/YourPathToKoken/koken/storage/originals/g2/5n/originalfilename.jpg
This php script reads the koken database and copies the original files to a new
location where every album is a new folder.
run from console:
php thisscript.php
**/
query($sql); 
foreach($results as $row) 
{ 
   $makedir = sprintf('mkdir -p \'/YourPath/%s\'',$row['title']);
   system($makedir$retval);  
} 
//end create folders

//copy photos in public

$sql = "SELECT * FROM koken_albums WHERE visibility = 0"$resultsalbum = $pdo->query($sql); 
foreach($resultsalbum as $row) 
{ 
     $albumtitle = $row['title'];
     $albumid = $row['id'];  
     $sqlcontent = sprintf('SELECT * FROM koken_join_albums_content WHERE album_id = %s'$albumid); 
     $resultscontent = $pdo->query($sqlcontent); 
     foreach($resultscontent as $rowcontent)
     {
          $photoid = $rowcontent['content_id'];
          $sqlphoto = sprintf('SELECT * FROM koken_content WHERE id = %s'$photoid); 
          $resultsphoto = $pdo->query($sqlphoto); 
          foreach($resultsphoto as $rowphoto) 
                 { 
                 $photovisibility = $rowphoto['visibility'];
                  //If you set visibility to unlisten in a public album it won't show in the site and it won't copy
                  if($photovisibility == "0") 
                    {
                    //EDIT YourPathToKoken and YourPath
                    $photo_in_storage = sprintf('/YourPathToKoken/koken/storage/originals/%s/%s/%s',
                        substr($rowphoto['internal_id'],0,2),substr($rowphoto['internal_id'],2,2),$rowphoto['filename']);
                   $photo_in_plex = sprintf('/YourPath/%s/%s',$albumtitle,$rowphoto['filename']);
                   $copyphoto = sprintf('cp -n \'%s\' \'%s\'',$photo_in_storage,$photo_in_plex);
                   echo $copyphoto;
                   echo "\n";
                  system($copyphoto$retval);
                  } 
                 
               }
     }
} 
//copy favorite photos in public
//copy all photos marked as favorite in koken
         
$sqlphoto = sprintf('SELECT * FROM koken_content WHERE favorite = 1'); 
$resultsphoto = $pdo->query($sqlphoto); 
foreach($resultsphoto as $rowphoto) 
      { 
      //EDIT YourPathToKoken and YourPath
    $photo_in_storage = sprintf('/YourPathToKoken/koken/storage/originals/%s/%s/%s',
        substr($rowphoto['internal_id'],0,2),substr($rowphoto['internal_id'],2,2),$rowphoto['filename']);
    $photo_in_plex = sprintf('/YourPath/%s',$rowphoto['filename']);
    $copyphoto = sprintf('cp -n \'%s\' \'%s\'',$photo_in_storage,$photo_in_plex);
    echo $copyphoto;
    echo "\n";
    system($copyphoto$retval);
    }
?>

Koken database repair

Albums disappearing, albums don't sort properly, albums jumping from one Set to another: Your koken database is confused. Easy to fix if you have a MySQL editor like phpMyAdmin or Navicat.

Open the table koken_albums and sort the table on the following columns:
level, left_id, right_id and visibility

visibility
visibility = 0: the album is public
visibility = 1: the album is unlisted
visibility = 2: the album is private

The same logic applies applies to the content tables for individual photos in the koken database

listed

The table koken_albums also has a column listed. What it does is unclear for me, most likely it's a relic from the past and overruled by visibility which supports private, a new function of more recent koken releases.

level is the level of the album/set in koken's collection tree 

level = 1: the top level either Public, unlisted or private in the collection tree
Any album directly under Public has visibility = 0 and level = 1 
level = 2: A set or album inside a Set in the top levels (public, unlisted or private) of the collection tree. For instance a Set in the unlisted tree has visibilty = 1 and level = 1. Albums within that Set have visibility = 1 and level = 2.
level = 3: etc etc

Grouping and sorting

It gets a little complicated with sorting and grouping of albums and sets. Differentiating between Sets and Albums and sorting and grouping is handled by left_id and right_id. 

For instance, three (public) albums are sorted like this (id could be any number and is controlled by your koken install)

id, left_id, right_id
21, 1,       2
6,  3,       4
3,  5,       6

A set could be

id, level, left_id, right_id
9,  1,     3,       10

Albums within that set are sorted like this:

id, level, left_id, right_id
35, 2,     4,       5
7,  2,     6,       7
10, 2,     8,       9

level = 2 because the albums are part of the set

left_id of the albums within the Set starts with the left_id + 1 of the corresponding Set, in this example left_id = 4. The left_id and the right_id of the Set should span the left_id and right_id's of the albums within that set.

If you move albums and or sets around in Koken the left_id and right_id is changed by koken and the resulting database structure should be correct. Somehow my koken install managed to confuse itself. Maybe due to some bugs in the past which never showed it ugly face in the past. You can fix the logic yourself with any MySQL database editor! After your done save the database table, clear the system cache of koken and refresh your browser.

If you make a mistake and the collection tree is totally messed up, don't panic and try again. The albums and set don't disappear if you don't delete records in the koken_albums table.

The logic above is what I discovered with trial and error. I could be wrong, it worked for me. A good backup is a very good idea before you start hacking your database!

Logitech Boom speaker repair

The Logitech Squeezebox Boom has a major fault. The rubber of the woofers is falling apart after a few years:

start

What you need:

  • New speaker rings R31C from speakerrepairshop
  • Glue
  • A mini hot air gun. Most gas operated soldering irons have a special tip which transforms it in a mini hot air gun. For instance this one
Start heating the rubber very gently. To hot or to close and the paper cone is burned. You need to adjust the heat/distance and only melt the glue:
hotair

Pull the rubber from the speaker cone. If you apply enough heat and pull in the direction of the radius of the speaker cone you won't damage the paper:
peelaway more peeling even more peeling

Also remove the rubber and the old glue on the metal frame with a sharp knife
It should like like this:
peeling done

Apply glue to the paper cone and the new rubber ring.
glueapplied

After the glue has dried for a minute or two drop the new rubber on the paper cone. You have to center it correctly on the first try. If not try moving it around. Finally apply pressure on the rubber ring and paper cone.

Cut a straw to 6,5 cm max.
straw

Insert it in the bottom of the woofer and place the woofer on a table with the straw inserted. If the straw is longer or has sharp edges you could damage the paper cone.
insertstraw

The paper cone and new rubber is now lifted.
straw inserted 2

Apply glue to the metal frame and the new rubber ring. The glue needs to dry for two minutes. 
Lift the woofer from the table. The cone drops and the rubber is glued to to metal frame. If you lifted the speaker correctly the speaker cone is now centered in the metal frame
Check the speaker carefully if the coil is moving free and not touching the magnet.
If not try to correct it.

Once everything is centered apply pressure with a coin to fix the bond.
coin

Finished and ready for reassembly:

finished

New site

Welcome to my new site. Completely revamped with a new photography friendly CMS called Koken and the Regale 2 theme.