MyRaspberryAndMe

Tinkering with Raspberry (and other things)


Mac OS – El Capitan bluetooth discoverabilty

I recently upgraded my Mid 2011 Mac Mini to El Capitan and had to discover that when Bluetooth was switched on, the machine stayed discoverable via Bluetooth. Living in the middle of a big city this is a gerat security risk. I just don’t want everybody in the neighborhood to be able to see my Mac.

There are numerous instructions on the internet on how to disable the bluetooth visiblity via terminal commands (e.g. at krypted.com) but none of that did work. So I decided on checking the alternatives. And succeeded, thus this blog post. Continue reading

Advertisements


5 Comments

Owncloud 6 + lighttpd 1.4.31 + Raspberry Pi (Wheezy)

This workaround patches lighttpd to “understand” the HTTP_PATCH method so Owncloud 6 can be used on a Raspberry Pi running Wheezy.

I am using a dedicated Raspberry Pi with Owncloud and lighttpd for my contatcs and calendar entries. This works fine with Android (with the cardDAVSync and calDAVSync apps) and out of the box with any iOS devices using caldav and carddav.

Recently I upgraded from Owncloud 5 to version 6, mostly because I wanted the new automatic birthday calendar feature. Then I realized that I was not able to change any entries. Creating and deleting entries worked fine, only updating/changing was affected. After some digging around I found an entry in the owncloud forums and a short remark in the installation instructions (for version 5. Not in the version 6 instructions…) reading:

Note for Lighttpd users on Debian stable (wheezy):
Recent versions of Owncloud make use of the HTTP PATCH feature, which was 
added to Lighttpd at version 1.4.32 while Debian stable only ships 1.4.31.
The patch is simple, however, and easy to integrate if you’re willing to 
build your own package.

There are instructions for patching lighttpd on Debian so I thought that this should work on the Raspberry Pi also. Well, it did not. I ended up with a completely screwed system and (even worse) an incompatible libc-version which made some more fiddling necessary. I cannot guarantee that I didn’t something wrong, but I found a workaround that is working flawlessly on my system.

This workaround involves some modifications to source files and building a debian install package. It also assumes that you have a working and properly configured lighttpd and Owncloud installation on your system! If you have never compiled/built software on a linux machine please be warned. I can not be held responsible if anything goes wrong and you end up with a non-working Raspberry Pi. That said, here’s what we are going to do:

  • make backups of all lighttpd configuration files
  • get the lighttpd 1.4.31 sources and patch them
  • build a .deb-package from the source
  • install patched lighttpd package over existing installation using dpkg
  • copy some missing files from saved backup to new locations

If you are still with me at this point, keep on reading… Continue reading


Quick Tip: crontab and python

Often running a python script via crontab does not work as expected. The most common problem is with permissions, I am sure everybody is aware of.

Here are some other reasons why calling a python program from crontab may fail:

  1. The last line in the crontab file needs to be a newline
  2. Scripts called from within crontab may not contain a “.” (dot) character. This is weird and almost unknown to most users.
  3. crontab scripts may not have all PATH environments you have while testing your python program

 

So what to do about it? Here’s an easy solution:

Suppose you have added an import-path to your python installation like I did in this quick-tip. We are going to “wrap” the call to “ourprogram.py” in a bash script and name that script “ourprogram_starter”. No dots, crontab is happy. In this script we export the PATH variable so that crontab and the “ourprogram_starter” can find all our custom modules.

#!/bin/bash
export PYTHONPATH="$HOME/some_Directory_Name"
python /full/path/to/ourprogram.py

Make sure that this file is executable and you’re good to go. Now crontab can call this script which sets all needed environment variables and then calls the python program.


2 Comments

Quick Tip: Adding a directory to Python’s module search path

Over time I have written some Python modules/classes that I am using in more than one little project. As these are single files mostly, I did not bother about writing “real” modules with “setup.py” and all that stuff. I do not want to install these files in Python’s default library directory, either.

So I did what one should never ever do 🙂 I copied the files into the project directories as needed. This quickly gets out of hand if you are doing some updates to one of the classes. In order to get some robust structure into my workplace on the Raspberry Pi I did some research and reading about installing Python modules and came up with the most simple solution I can think of: adding my own directory to Python’s search path.

In the Python documentation everything I did can be found, of course. As I did miss it during several reads, I am posting my way of doing it here. To remind me and to, hopefully, help others.

First, a directory to put all the modules to be reused into needs to be created:

mkdir some_Directory_Name

Now we need to add an environment variable that gets set when you log in. Go to your home directory and edit the file “.profile”:

cd
nano .profile

At the end of the file add the following lines:

if [ -d "$HOME/Workplace/Python/MyModules" ] ; then
    export PYTHONPATH="$HOME/some_Directory_Name"
fi

That’s pretty all there is to do. The next time you log in the variable PYTHONPATH is set and used by Python. The if-statement checks for the existence of the given directory. The environment variable will only be created if the directory exists.

You can check this. Do not log out yet, but start Python and do the following (screenshot for better readability:

Bildschirmfoto 2013-12-04 um 14.57.10

This gives you the directories where Python looks for files when you are using the import-statement. Now to have our changes take effect, we could log out and in again, or we re-read the .profile with:

. ~/.profile

There needs to be a space between the first dot and the tilde character. If you are now starting Python again and do the exact same thing you should see your path somewhere in the output from sys.path:

Bildschirmfoto 2013-12-04 um 14.57.59

I have highlighted my personal search path in the above picture.

That’s all for this quick tip.


4 Comments

Real Time Clock (reloaded)

I could not stop thinking about the RTC and the Raspberry. In my personal setup, the RTC is not always connected to the Raspberry, so it would not make sense to throw away the fake hardware clock and rely on the RTC only. I needed a solution that was most flexible and with the smallest possible overhead.

The solution I came up with is to have a script check for the RTC on startup and create the device only when the RTC is there. This means tinkering around with “autostart” functionality and I am not going to edit rc.local, but do it the more correct and formal way. So if you want to learn how to run scripts on boot/reboot read on! Continue reading