All posts by erickclasen

About erickclasen

This is my Blog for writing about technical items and my other thoughts. I also use it to experiment with WordPress.

Kashmiri Pumpkin Curry

  • Why Pumpkin?

    A pumpkin patch grew out of out compost pile and it was a ready to display for Halloween. But then what to do. It hung out until December and it was time to bring it in and do something before it rots. I saw a show about Kashmir and that is where pumpkins come from originally and ridged squash, in the vernacular that they used on the show, that must mean squash with ridges, like acorn squash. I figured there must be some good Kashmiri recipe out there for pumpkin. What else is going to be done with it, it is large and would make more than a pie, so it might as well get used in a new an different way.

    Ingredients

  • 2 onions, quartered
  • 2 garlic cloves
  • 4 cm (1½ inch) piece of fresh root ginger, peeled and sliced
  • 1 large red chilli, halved and deseeded
  • 1 teaspoon cumin seeds, roughly crushed
  • 1 teaspoon coriander seeds, roughly crushed
  • 5 cardamom pods, crushed
  • 1.4 kg (2¾ lb) pumpkin, deseeded and peeled
  • 2 tablespoons sunflower oil
  • 15 g (½ oz) butter
  • 1 teaspoon ground turmeric
  • 1 teaspoon paprika
  • 1 cinnamon stick, halved
  • 450 ml (¾ pint) vegetable stock
  • 150 ml (¼ pint) double cream
  • 50 g (2 oz) pistachio nuts, roughly chopped
  • small bunch of coriander, torn
  • salt and pepper

Directions

Finely chop the onion, garlic, ginger and chilli in a blender or food processor, or finely chop by hand, and mix with the crushed cumin, coriander and cardamom.

Slice the pumpkin into 2.5 cm (1 inch) wedges, then cut the wedges in half. Heat the oil and butter in a large frying pan, add the pumpkin pieces and fry for 5 minutes until lightly browned. Push the pumpkin to one side of the pan then add the onion mixture and fry until beginning to colour.

Add the turmeric, paprika and cinnamon, cook briefly then stir in the stock. Season and bring to the boil. Cover and simmer for 10 minutes until the pumpkin is almost cooked. Allow to cool, cover and chill until required.

When ready to serve, add half the cream, half the pistachios and half the coriander leaves. Reheat until piping hot. Drizzle with the remaining cream, and sprinkle with the remaining pistachios and coriander. Serve with naan breads and a tomato and onion salad.

 

Resource

http://www.aol.co.uk/living/food/kashmiri-pumpkin-curry/903/

Benchmark Generation 2 i5 -vs- Generation 3 i5

Once and a while I will benchmark a PC that I happen to get my hands on. I tested a laptop with a Gen 3 i5 and compared it to my desktop with has 2 Gen 2 i5….

erick@OptiPlex-790 ~/factor $ tail i5-3340M@3200Mhz-bmark.txt

Calculations Completed!
 Time: 9 seconds

Factor: Finished in about 10.000000 seconds.
 Pi: Finished in about 9.000000 seconds.

Factor to Pi Ratio 1.111111
 erick@OptiPlex-790 ~/factor $ tail i5-2500@3700.txt

Calculations Completed!
 Time: 9 seconds

Factor: Finished in about 10.000000 seconds.
 Pi: Finished in about 9.000000 seconds.

Factor to Pi Ratio 1.111111

It looks like a Generation 2 i5 running at 3700MHz can run calculations at the same rate as a Generation 3 i5 at 3200MHz. The benchmark is both a pi calculation and a factoring calculation. The ratios will vary from processor to processor sometimes. Especially across old -vs- new ones. But these seem to line up.

Comparison

It looks like the raw speed difference for a given clock speed, 3700/3200 = 1.15625x faster. In other words, the Gen 2 has to be running 1.15625x faster on the clock to get the same speeds.

Note: The MHz values are running one core at turbo speed.

Code

The code is something that I patched together. I wrote the factoring part years ago to run under MS-DOS and ported it to compile under GCC. I made it at a time that I was toying around with extracting factors of numbers and was an exercise in making speed efficient code. I always had some spare moments while waiting for other compiles to happen. At the time I was working on embedded code in industry, these compiles could take a few minutes with each change and up to 20 minutes when doing a scratch build. This is on machines of the Pentium 2 -4 era. When writing embedded code and compiling there were plenty of slices of time to experiment with other code.

The Pi part I snagged off the web a long time ago, not sure where, or I would reference it here. It is interesting to see how the speeds will vary between the Pi and Factor parts, therefore I compute a ratio of them. I fiddled with the constants so that the time that both parts run is about 10 seconds and around a 1:1 ratio on my current desktop i5@3300Mhz. Essentially the desktop is the reference normal against which I am comparing other machines.

 

 

#include <stdio.h> 
#include <float.h> 
#include <time.h> 
#include <stdlib.h> 
#include <sys/time.h> 
#include <unistd.h> 
 
 
    unsigned int x; 
unsigned int f = 0, stopn = 100000, maxFactor = 0; //4294967295 
   time_t curtime; 
 
     
    FILE *fp; 
 
 
long secstart, usecstart; 
long kf, ks; 
long *mf, *ms; 
long cnt, n, temp, nd; 
long i; 
long col, col1; 
long loc, stor[40]; 
 
int main(void) 
{ 
 
  float factor_time; 
  float pi_time; 
  float ratio; 
  factor_time = factor(); 
  pi_time = pi(); 
 
  ratio = factor_time / pi_time; 
   printf("\n\nFactor: Finished in about %f seconds. \n", factor_time); 
   printf("Pi: Finished in about %f seconds. \n", pi_time); 
 
   printf("\n\nFactor to Pi Ratio %f \n",ratio ); 
 
} 
 
 
int factor(void) 
{ 
    unsigned int i = 1; 
    unsigned int n; 
 
    time_t start, stop; 
    clock_t ticks; long count; 
 
     
    //scanf("%s",fname); 
    //scanf("%i",stopn); 
    //fopen("temp.txt","w"); 
    //stopn = argv[i]; 
 
 
    // Mark off the start time for the program.  
   time(&start); 
 
    for(n = 1;n < stopn;n++) 
    { 
        
    #if 1 
      // Inner loop, Walk through all values of numbers up to 1 more than the middle number. 
        for(x = 2;x < (n/2)+1;x++) 
        { 
          // Found a factor incriment f 
      //      if((n/x) - (int)(n/x) == 0) 
      if(n%x == 0) 
            { 
                f++; 
            } 
        } 
    #endif 
 
        //fprintf(fp,"%i    %i \n",n,f); 
    // If the value of the factor f is larger than the largest factor found, mark the occurance. 
    if(f > maxFactor) 
    { 
      printf("%i\t %i\t",n,f); 
 
      maxFactor = f; 
 
      // Get Current Time, print it out. 
      time(&curtime); 
      printf("%s", ctime(&curtime)); 
 
    } 
        // Reset the factor count for the next outer loop. 
        f = 0; 
        
    } 
 
    // Mark the stop time of the program. 
 
   time(&stop); 
    
   // How long did the program run and how much CPU time did it use. 
   //   printf("Used %0.2f seconds of CPU time. \n", (double)ticks/CLOCKS_PER_SEC); 
   printf("Finished in about %.0f seconds. \n", difftime(stop, start)); 
 
    return(difftime(stop, start)); 
} 
 
 
 
 
 
 
 
 
 
 
void shift(long *l1, long *l2, long lp, long lmod) 
{ 
    long k; 
 
    k = ((*l2) > 0 ? (*l2) / lmod: -(-(*l2) / lmod) - 1); 
    *l2 -= k * lmod; 
    *l1 += k * lp; 
} 
 
void yprint(long m) 
{ 
    if (cnt<n) 
    { 
        if (++col == 11) 
        { 
            col = 1; 
            if (++col1 == 6) 
                { 
                    col1 = 0; 
                    printf("\n"); 
                    printf("%4ld",m%10); 
                } 
            else printf("%3ld",m%10); 
        } 
        else printf("%ld",m); 
        cnt++; 
    } 
} 
 
void xprint(long m) 
{ 
    long ii, wk, wk1; 
 
    if (m < 8) 
    { 
        for (ii = 1; ii <= loc; ) 
        yprint(stor[(int)(ii++)]); 
        loc = 0; 
    } 
    else 
    { 
        if (m > 9) 
        { 
            wk = m / 10; 
            m %= 10; 
            for (wk1 = loc; wk1 >= 1; wk1--) 
            { 
                wk += stor[(int)wk1]; 
                stor[(int)wk1] = wk % 10; 
                wk /= 10; 
            } 
        } 
    } 
    stor[(int)(++loc)] = m; 
} 
 
void memerr(int errno) 
{ 
    printf("\a\nOut of memory error #%d\n", errno); 
    if (2 == errno) 
    free(mf); 
    _exit(2); 
} 
 
int pi(void) 
{ 
    int i=0; 
    char *endp; 
 
 
    stor[i++] = 0; 
 
    n = 22000; 
 
    mf = malloc((size_t)(n + 3L)*(size_t)sizeof(long)); 
    if (!mf) 
    memerr(1); 
    ms = malloc((size_t)(n + 3L)*(size_t)sizeof(long)); 
    if (!ms) 
    memerr(2); 
    printf("\nApproximation of PI to %ld digits\n", (long)n); 
 
    struct timeval tv; 
    struct timezone tz; 
        gettimeofday(&tv, &tz); 
        secstart=tv.tv_sec; 
        usecstart=tv.tv_usec; 
    cnt = 0; 
    kf = 25; 
    ks = 57121L; 
    mf[1] = 1L; 
    for (i = 2; i <= (int)n; i += 2) 
    { 
        mf[i] = -16L; 
        mf[i+1] = 16L; 
    } 
    for (i = 1; i <= (int)n; i += 2) 
    { 
        ms[i] = -4L; 
        ms[i+1] = 4L; 
    } 
    printf("\n 3."); 
    while (cnt < n) 
    { 
        for (i = 0; ++i <= (int)n - (int)cnt; ) 
        { 
            mf[i] *= 10L; 
            ms[i] *= 10L; 
        } 
        for (i =(int)(n - cnt + 1); --i >= 2; ) 
        { 
            temp = 2 * i - 1; 
            shift(&mf[i - 1], &mf[i], temp - 2, temp * kf); 
            shift(&ms[i - 1], &ms[i], temp - 2, temp * ks); 
        } 
        nd = 0; 
        shift((long *)&nd, &mf[1], 1L, 5L); 
        shift((long *)&nd, &ms[1], 1L, 239L); 
        xprint(nd); 
    } 
    printf("\n\nCalculations Completed!\n"); 
    gettimeofday(&tv, &tz); 
    printf("Time: %ld seconds\n",tv.tv_sec-secstart); 
    free(ms); 
    free(mf); 
    return(tv.tv_sec-secstart); 
}

USB Stick Fix for NTFS filesystem on Raspberry Pi

I’ve used USB sticks on the Raspberry Pi before, many times. So I plugged one in for some extra storage. It let me write once and then went into r/o mode. What the hell! Pulled it, plugged it into the PC, no problem. Plugged it into a Windows 7 machine, it complained about drive errors and fixed it. Try again, no luck. So I gave up for a while, it was full of Music that I play through the Sockso Music Server, so no big deal, but I really do want to use it for external storage as the SD card will fill up eventually. Plus I would like to use it as more storage for ftp as well and possibly for Sparkleshare which I intend to install.

One more look

It turns out that at some point while fiddling with the USB drive, I formatted it NTFS. I believe that I tried to format it ext4 and then ext2, neither worked. So I used a WIndows machine to make it NTFS, so it would work.

The issue is that the Rasp Pi does not come with NTFS support out of the box. So I needed to  install ntfsprogs to get it to work OK….

sudo apt-get install nfsprogs

Otherwise it immediately goes to read only. I have not tested but I assume nfsprogs also installs tools to check NTFS file-systems.

To mount my USB stick, I Need to execute …

sudo mount -t ntfs -o rw,uid=erick,gid=erick /dev/sda1 /media/sda/

Symlinks for Sockso Music Server

I have a symlink for music in my Music dir (/home/erick/Music. Set it to, main-collection -> /media/sda/Music/ , in this manner it points to the music collection on the usb stick and Sockso happily finds the music. Sockso does not like spaces in filenames!

 

 

Using mount with bind to access usb drive via vsFTP

I have a USB stick plugged into my Raspberry Pi for external storage, mostly to put music on for the Sockso Music Server to get at. But I wanted to use it a bit more for generic storage. FTP is great, you can get to it from any machine and the command line for it is the same on Win or Linux. So I can walk up to any machine, not have to install a thing and reach into a folder with FTP.

For instance, I have an infected Windows Machine, I don’t dare stick a USB stick in it. Instead I go to the command line, ftp to the Raspberry Pi and grab the tools I need from there.

The Issue

The issue was that I tried to symlink from the ftp directory to the USB drive. vsFTP will not follow symlinks for security reasons.

The Solution

Mount the directory you want under the FTP directory using bind. /media/sda is the USB stick mount point and the whole thing gets mounted under the FTP dir using…

sudo mount --bind /media/sda/ /home/ftpuser/usb-drive/

Resources

FTP on Raspberry Pi. An easy way to make shared folders

Alternatives to FTP

https://radu.cotescu.com/vsftpd-and-symbolic-links/

avconv replaces ffmpeg for Video/Audio Conversion

Recently I wanted to convert an AVI file to an m4v on Linux Mint 17.3. I tried to use ffmpeg, it’s not there. I can’t isntall it…hmmm. So I did some digging, it has been replaced by avconv. To get avconv….

sudo apt-get install libav-tools

To use

Online, I read that there are some syntax differences between ffmpeg and avconv, so I was reluctant to just symlink pointing ffmpeg to avconv and have scripts break.

But I did a quick test taking a good guess…

avconv -i timelapse-wx-station-4-08-to-7-12-2016.avi timelapse-wx-station-4-08-to-7-12-2016.m4v

…and, it worked. Got me a much smaller file than the AVI and worked it’s magic in a short minute or two.

Video of Weather Station from April 8,2016 to July 12,2016

This was what I was testing out with the conversion. Video taken by using fswebcam to gather a still shot of my weather station once per hour on the Raspberry Pi. Once per day the shots are rolled up into an AVI video and stored in a tmp folder which is mounted in RAM. Well the RAM folder does fill up after a while and I copied the file off and saved it on my desktop. This video shows the weather changing from spring to summer.

Resources

http://askubuntu.com/questions/432542/is-ffmpeg-missing-from-the-official-repositories-in-14-04

 

Pentium 3 without holder and Pentium 4 chip

A look at a Pentium 3 at 500MHz and Pentium 4 at 3.0GHz

Recently I gutted a few old PC’s. The physical difference between the Pentium 3 (P3) from 1999 and Pentium 4 (P4) from 2005 were stark. It made me think of the way computers have progressed in terms of performance and power usage.

Pentium 3

The Pentium 3 that I removed uses a Slot 1 connector. basically it sits on a board that gets inserted into a slot on the motherboard. The little daughter board reveals a bunch of support hardware once the black cover is removed. There are a couple of chips that look like they might be for the RAM Cache. Looking this up in Wikipedia confirms this thought, “The L2 cache is off-die and runs at 50% CPU speed.” It also states a TDP of 28W. No wonder it can get away with a small fan and heatsink.

https://en.wikipedia.org/wiki/List_of_Intel_Pentium_III_microprocessors#.22Katmai.22_.28250_nm.29

Back of Pentium 3 and 4
Back of Pentium 3 and 4

Pentium 4

On the other hand the P4 HT 630 is a LGA 775 type of socket, a bunch of balls on the bottom that make contact to the socket on the motherboard, 475 of them! This socket design was one of the last for the P4. The P4 is a Prescott 2M and has a TDP of 84W. Hence the big fan and heat sink.

https://en.wikipedia.org/wiki/List_of_Intel_Pentium_4_microprocessors

In contrast, a few years ahead in 2009, a more modern computer, with more processing power would have a processor that uses about 40-50W TDP. So heat-sinks and fans have gotten smaller. Along with the power supplies, I had a Dual Xeon Circa 2004 that had a 1000W power supply, it was fast for it’s time, but also a space heater when it was running hard.

Simple Benchmarks

Running a Pi Benchmark written in C, out to 256000 digits. Lower is better.

1999: Old P3 at 700 MHz Time: 13026 seconds TDP about 28W

2004: P4 at 2400 MHz Time: 3741 seconds TDP 84W

2009: Intel(R) Celeron(R) M CPU 520 @ 1.60GHz Time: 2747 seconds TDP 30W

2011: Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz  Time: 986 seconds TDP 65W

 

P3 and P4 Heatsinks
P3 (left) and P4 (right) Heatsinks
P3 fan center, on top of P4 fan
P3 fan center, on top of P4 fan

 

 

Sockso Music Server on Linux

The Sockso Music Server is very functional and quite easy to set up in standalone or daemon mode. It is cross platform as it only depends on a Java runtime environment being installed on the target computer.

Recently I loaded it on my desktop which runs Lubuntu 14.04. I tested it out on the desktop before loading it onto my Ubuntu  server PC, which holds my music repository.

  • I will outline installing the Java run time environment needed to run Sockso on an Ubuntu machine
  • The Sockso install procedure
  • Getting it to run as a daemon
  • Getting it to find your music
  • At the bottom of the page I will have some links to resources that I followed and will provide information for running Sockso on other platforms.

The Sockso install procedure

It is not so much an install like compiling/installing, apt-get or adding a package. It is a simple old school download and drop files in a directory install.

  1. Download the Sockso zip file.  You can do steps 2 and 3 while waiting for  the download!
  2. Create /usr/share/sockso directory as root or via sudo so all files are set to root:root. ( sudo mkdir /usr/share/sockso )
  3. Create Sockso data directory /var/sockso as root or via sudo. ( sudo mkdir /var/sockso )  If sockso is terminated uncleanly, the files in this directory can get corrupted and it will need to be rebuilt
  4. Extract the files to /usr/share/sockso/ ( sudo unzip sockso-1.5.3.zip -d /usr/share/sockso/ ) I am not 100% on my unzip usage, so this command actually made a sockso-1.5.3 folder under /usr/share/sockso. Then I needed to use sudo mv .. to move all the files and dirs up one level.

 

Install Java

On my server that runs headless I performed the following after I typed in java on the command line and it told me that it was missing. It usually resides at /usr/bin/java in a Debian/Ubuntu type of file system. If it is installed it will dump out a help file. Using the command which java will also tell you if it is installed…

The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.6-jre-headless
 * openjdk-6-jre-headless
 * gcj-4.5-jre-headless
 * openjdk-7-jre-headless
Try: sudo apt-get install <selected package>

I went for version 6 headless for starters. I am not sure what the difference between all the versions are, but version 6 worked for me.

erick@ubuntuserver:/tmp$ sudo apt-get install openjdk-6-jre-headless
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  ca-certificates-java icedtea-6-jre-cacao icedtea-6-jre-jamvm java-common
  libnspr4 libnss3 libnss3-1d openjdk-6-jre-lib tzdata-java
Suggested packages:
  default-jre equivs libnss-mdns sun-java6-fonts ttf-dejavu-extra
  fonts-ipafont-gothic fonts-ipafont-mincho ttf-wqy-microhei ttf-wqy-zenhei
  ttf-indic-fonts-core ttf-telugu-fonts ttf-oriya-fonts ttf-kannada-fonts
  ttf-bengali-fonts
The following NEW packages will be installed:
  ca-certificates-java icedtea-6-jre-cacao icedtea-6-jre-jamvm java-common
  libnspr4 libnss3 libnss3-1d openjdk-6-jre-headless openjdk-6-jre-lib
  tzdata-java
0 upgraded, 10 newly installed, 0 to remove and 5 not upgraded.
Need to get 44.2 MB of archives.

 

…and so on as it installed.

Reading Java Version

If you already have java and want to view the version…

java -version

…will get you the version, such as listed on my desktop PC…

erick@Precision-WorkStation-530-MT:/var/sockso$ java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (IcedTea 2.6.3) (7u91-2.6.3-0ubuntu0.14.04.1)
OpenJDK Client VM (build 24.91-b01, mixed mode, sharing)

Test run

Before making it run as a daemon I wanted to test drive it. So the following command will start it up…

sudo sh /usr/share/sockso/linux.sh --nogui --datadir /var/sockso

When you terminate it, try to shut it down clean via a sigterm when you kill the process. I have read that killing it uncleanly can screw up the data directory ( /var/sockso ). Then you have to empty the directory and rebuild it’s contents. I haven’t had it screw up the directory yet.

Running Sockso as a daemon

Running Sockso as a daemon is an advantage when you are running on a server. It will startup when the machine starts and the machine will take care of closing it down cleanly upon shutdown.

Perl script for running sockso as a daemon

After moving the Sockso files to the proper location there will be a Perl file at /usr/share/sockso/scripts/init.d/sockso

Copy the sockso run file written in perl from…

 /usr/share/sockso/scripts/init.d/sockso

…to…

/etc/init.d/sockso

…using…

sudo cp /usr/share/sockso/scripts/init.d/sockso /etc/init.d/sockso

 

Edit the file and change the directory at the top of the file to point to where sockso is installed ( /usr/share/sockso ).

Also make it executable.

sudo nano /etc/init.d/sockso

sudo chmod +x /etc/init.d/sockso

Now that it is in the init.d directory, the following should work…

sockso (start|stop|restart)

Remember to change the directory at the top of the sockso to point to the /usr/share/sockso dir.

 

Starting Sockso on boot

Follow the Steps 4,5,6 on this blog post…

https://samiux.wordpress.com/2009/07/17/howto-sockso-1-1-8-music-server-on-ubuntu-9-04-server/

I have a copy here as a PDF –> sockso-start-on-boot , just in case the link above disappears.

 

Sockso Command Prompt

Sockso comes with it’s own command prompt to administer it. help will list the commands. You can use the Sockso command line to add music to Sockso’s collections, add and delete users and perform other maintenance to it.

There is also a management webpage where you can perform the same functions as via the command line.

Finding Music

There is a command line mode for sockso where you can point it to certain directories to index music from.

Run sockso to bring up it’s command line. At it;s command line use coladd and then the path to the folder that your music is in to add it. It takes a while to do this, it is indexing it into a database so be patient. You can add multiple directories into it’s collections. If you add music to a directory in the collection, sockso will find it and add it. By default it scans directories in it’s collections every 30 minutes. I’ve tested it and it is pretty cool, dump in some music and a little while later, it’s there like magic.

coladd /home/username/Music

collist will list all the collections. coldel deletes collections.

colscan will force a scan for new collections that have been added.

Symbolic Links to Music Folder

The sockso coladd command has issues with spaces in directory names. What I have done is made a bunch of symbolic links using ln -s directory of music directory-of-music. This makes it easy to see where all the music is and sockso just has to deal with my Music directory and if I add or remove music it will figure it out on it’s own. I show an example below in the Raspberry Pi section.

Sockso on Raspberry Pi

I just ( April 2016 ) installed Sockso on my Raspberry Pi. I got the idea of sticking a USB stick into one of it’s open ports and dump my music repository on it. Them with sockso I can get to it whenever I want. Previously I had it set up on my main server that I have to use Wake on LAN to start up when I am not at home. Having Sockso on the Rasp Pi allows me to get at it instantly and saves energy by not having to run a full fledged server just to play music remotely.

Below is a tree of the Music directory that I created under my home directory. As can be seen there are symlinks without spaces that point to locations on the usb stick, mounted at /media/sda.

erick@raspberrypi ~/Music $ tree -L 1
.
├── main-collection -> /media/sda/music
└── renee-ipod-music -> /media/sda/Renee's iPod/iTunes_Control/Music/

The USB stick is formatted it’s default way that it came, FAT32. I use pmount /dev/sda1 /media/sda to mount it. In this was it is mounted not as root, it is mounted by my user, so all files are easily accessed by my own user, locally and remotely using NFS or SSHFS. In this way I can add and remove files easily.

 

 Users

In Sockso there is a concept of users. You can have multiple people logged in and have personalized settings. You can even authorize uploads by setting that option.

Adding users at the Sockso command line works similar to adding users in Linux.

useradd NAME PASS EMAIL ISADMIN 1/0     Adds a new user

Commands:
userlist                                Lists the users
useradd NAME PASS EMAIL ISADMIN 1/0     Adds a new user
userdel ID                              Deletes a user
useradmin ID ISADMIN 1/0                Sets a user to be admin/non-admin
useractive ID ISACTIVE (1/0)            Toggles users between being active or not
coladd PATH                             Adds a folder to the collection
coldel PATH                             Removes a folder from the collection
collist                                 Lists the folders in the collection
colscan DIR (optional)                  Start a collection scan
propset NAME VALUE                      Sets a property
propdel NAME                            Deletes a property
proplist FILTER                         Lists properties
version                                 Show version information
exit                                    Exit Sockso


 

Resources

Where to get Sockso, it’s official site

http://sockso.pu-gh.com/

This site is a bit dated but still helpful.

https://samiux.wordpress.com/2009/07/17/howto-sockso-1-1-8-music-server-on-ubuntu-9-04-server/

Sockso Read Me

Requirements
————

Sockso should come packaged with everything it needs to run,
all you have to do is have Java installed on your computer.
You can download the latest Java version for free from
the Sun website at: http://www.java.com

To run Sockso under Windows just double click “Run Sockso”.
Easy!

“Linux”
——-

If you’re running Linux or something similiar then you may
just be able to double click the “linux.sh” shell script.
If this doesn’t work for you then you can run this script
from a terminal with:

$> sh linux.sh

Feedback
——–

If you’ve used Sockso then I’d love to hear what you think, so
please send me some email at: rod(at symbol)pu-gh(dot)com

Running as daemon
—————–
Usage: sockso (start|stop|restart)

 

 

 

 

 

sSMTP Installing and Configuration and Use Tips

Recently I was looking at creating a method of sending a warning email when ever my house temperature went below a threshold. I remembered that sSMTP was a simple way to send automated emails and CRON emails. I have some simple notes on what I did.

Installation

Very easy, just use apt-get from the command line…

sudo apt-get install ssmtp

Configuring

The configuration file (/etc/ssmtp/ssmtp.conf) can be edited using any test editor you typically use.

 

Config at /etc/ssmtp/ssmtp.conf

Below is my config file with the critical info blocked out. Lines in Red are what I modded to get ssmtp working for me.

The key pieces to get it working for me at least were…

hostname = My ISP’s domain

root = my complete email that I use at the ISP

mailhub = I looked it up in Thunderbird, it is the smtp.myispsdomain.net part.

AuthUser=my complete email that I use at the ISP. It might be different for you. Years ago it used to be just the user name part of email without the domain.

AuthPass = The password that goes along with my email.

I commented out the defaults for the ones that existed in the code.

The config file is a bit ugly after I touched it but I was trying to get this up and running quick and didn’t clean it up. But, hey it works!

 

#
 # Config file for sSMTP sendmail
 #
 # The person who gets all mail for userids < 1000
 # Make this empty to disable rewriting.
 #root=postmaster  <--- comment out
 
# The place where the mail goes. The actual machine name is required no
 # MX records are consulted. Commonly mailhosts are named mail.domain.com
  #mailhub=mail <-- comment out
 
# Where will the mail seem to come from?
 #rewriteDomain=
# The full hostname
 #hostname=raspberrypi <--- I was testing and kill this, failed to work
 # hostname has to be the mail domain! Or else it complains about
  # the raspberrypi part! The STMP server at frontier does that is.
  hostname=myispdomain.net
# Are users allowed to set their own From: address?
 # YES - Allow the user to specify their own From: address
 # NO - Use the system generated From: address
 #FromLineOverride=YES <-- Commented out and set below, I was testing!
# New Code put here 11302015
  root=me@myispdomain.net
  mailhub=smtp.myispdomain.net
AuthUser=me@myispdomain.net
AuthPass=myemailpassword
FromLineOverride=YES
#UseSTARTTLS=YES <-- Tried this, I didn't need it for my ISP.

CRON Email

Once installed if you or root on the machine have any CRON jobs, you will start to get email from them. You can stop this by appending …

> /dev/null 2>&1

to the end of the commands that are being run by CRON. Which will cut back on the emails that you will receive.

 Testing

I installed mail utils to allow sending simple messages…

sudo apt-get install mailutils

Then I sent a message via the command line…

echo "Test" | mail -s "Test Subject" me@myispsdomain.net

…and I was able to see it work OK.

Send files via email

If you want to send files you have to install mpack.

sudo apt-get install mpack

 

Then you can send files to your email like this…

mpack -s "Test" /tmp/web/log.txt me@myispsdomain.net

 Command Line Usage

If you execute ssmtp with an email address it will let you create an email from the command line. Which is good for quick emails to for example remind yourself of something, or send a snippet of code to yourself. You edit the email in the form of the example below and hit Ctrl-D when done and then it will send out.
ssmtp recipient_email@example.com
The following is an example right off the command line. Note the one line of space after the Subject, this is a must have…
erick@raspberrypi ~ $ ssmtp me@myispdomain.net
To:me@myispdomain.net
From:me@myispdomain.net
Subject:This is a test of ssmtp from the command line!

Hello there this is a test of the ssmtp from the command line tool. It could be used to send a reminder or small snips of code. Use Ctrl-D when you are done.

It is called up by using ssmtp emailtosendto@domain.com

Bye,
Me

Example of Sending CPU Temp Warning Emails

When I am away from home I can infer if my house is running to cold, which may indicate a problem with the furnace. The Raspberry Pi is light loaded, usually just idling, so the CPU temperature tracks the room temperature, with an offset. When I am away, I set the house thermostat at 47 degrees F. If it drops below this value the CPU temperature of the Raspberry Pi will drop below 34 degrees Celsius. So I can just have it send me an email if this happens. Then I can double check a log that is created of the temperature reading to see what is going on. Also I run a webcam pointed at an actual thermometer for a sanity check, this is logged by using fswebcam to take an hourly snapshot. So I have my bases covered for the most part. Obviously if the power is out, I am in the dark about the temperature, because the whole thing is down! Solving that is a future project.

Below is the snippet of code from a shell script that sits in /etc/cron.hourly that handles the warning emails that are sent to 2 addresses. variables mailaddr and mailaddr2.

temp is the CPU temperature in Celsius as an integer stripped using cut from the thermal_zone0 reading.

minimum and maximum are my temperature thresholds. I don’t care much about maximum but I have it set at 65 Deg. C. just in case.

# Read the temp and cut it to grab leftmost 2 characters, integer Temp
temp="`cat /sys/class/thermal/thermal_zone0/temp | cut -c1-2`"
#echo $temp

# Mail if about or below the limits
if (( $temp > $maximum )); then
   #echo "above"
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi HIGH CPU Temp > $maximum" $mailaddr
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi HIGH CPU Temp > $maximum" $mailaddr2

elif (( $temp < $minimum )); then
   #echo "below"
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi LOW CPU Temp < $minimum" $mailaddr
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi LOW CPU Temp < $minimum" $mailaddr2

fi

Boot Email

I want to know if an when the Raspberry Pi I run 24/7 ever reboots due to a power outage, so I have it send me an email. The line of code below handles it and is in the root crontab. I have it sleep for 180 seconds first, then send the email. This allows the cascaded routers which I have the Pi connected to and the cable modem, time to come on line.

@reboot sleep 180 && echo "Rasp Pi Rebooted" | mail -s "Rasp Pi Reboot!" me@myispsdomain.net

I also log boots in a file that I can view online, just to keep track in one record.

@reboot date >> /var/www/bootlog.txt

Keeping track of boots helps for instance if I am away from home and the power goes out. If I get the email that the Pi rebooted, I can check to see how long the power was down and what the temperature of the house is to see if all is well.

Every hour I take a time/date stamped webcam snapshot of a thermometer so I can just look to see how many are missing and have a rough estimate of how long the power was out and how cold the house got and verify that it is getting warmer because the furnace is on!

In the future I will connect a BME280 sensor to the Raspberry Pi that will be able to read ambient room temperature directly, along with humidity and barometric pressure. So I won’t have to infer the house temperature via the CPU temperature.

Resources

This is the page I used to configure ssmtp on the Rasp Pi.

http://www.raspberry-projects.com/pi/software_utilities/email/ssmtp-to-send-emails