Friday, August 26, 2016

103: Keeping a Rpi Up and On Line!
-- 3 Weeks Later --

What I've learned since this post:
1. When I thought my Pi was down it was only the WIFI that had stopped working (and no blinking of the USB WIFI dongle).
2. The steps I outlined below didn't work, longer term.
3. I swapped my generation 1 Pi B to my new gen 3. Still up: 2 weeks without a failure and without the steps listed below. However, its WIFI dongle is different. I need to swap them to see whether the problem is the dongle.

This didn't help (nor hurt):
I have a Pi powered through UPS that is programed through cron to monitor 2 Particle Photons that are doing real work. But, even though scheduled tasks happen every few minutes the dumb Pi seemed to go off line (sleep?) after a day or so. So I went looking for voodoo incantations to correct this problem. Here are 2 that I tried:

In /etc/kbd/config changed the line--
POWERDOWN_TIME=30 to value 0 (= never)

In /etc/lightdm/lightdm.conf after [SeatDefaults] added--
xserver-command=X -s 0 -dpms

One (both?) of these seems to have worked. 'No idea which -- or if they are black magic.

Pssst! Linux is a mess.

Friday, August 5, 2016

102: About My Grayscale Image Blog Page (#34)

The raspistill command for the Pi camera has 100-ish command line options but (oddly) no way to produce a black and white image file. It took me about 10 minutes to come up with a kludge to convert RGB to grayscale. Then I made a blog post about it.

Here's the mystery: With over 100 posts in this blog what is the enduring allure of post #34? Over 6% of my page views still go to that 2 year old entry. And here I thought I'd written about seemingly more important issues.

Anyway, here's a more interesting snippet of Python for a security cam app:

import subprocess
import os
import StringIO
from PIL import Image

threshold = 10 # interesting pixel value diff
numDiffs = 20  # number of diff pixels to assume motion
wide = 120     # size of test images (arbitrary)
high = 90

# Capture a small test image (for motion detection)
def captureImage():
  command = "raspistill -w %s -h %s -t 5 -e bmp -o -" % (wide, high)
  imageData = StringIO.StringIO()
  imageData.write(subprocess.check_output(command, shell=True))
  im ="L") # convert to B/W!
  buffer = im.load()
  return im, buffer

def compareImage(buff1, buff2): # latest vs. previous image
  changedPixels = 0
  for x in xrange(0, wide):
    for y in xrange(0, high):
      pixdiff = abs(buffer1[x,y] - buffer2[x,y])
      if pixdiff > threshold:
        changedPixels += 1
  return (changedPixels > numDiffs) # True return indicates motion

... (code that calls captureImage & compareImage)