Saturday, July 20, 2019

Greenhouse Computer Version 2

Work in progress...













Well, the previous greenhouse computer could report the temperature, barometic pressure, and humidity, but it didn't control anything, and the electric fan heater's thermostat wasted a lot of electricity during the previous winter, as it wasn't accurate, and the greenhouse got warmer than necessary.

The greenhouse needs to be kept above 5°C, to keep the citrus plants that over-winter in it alive, but not much warmer, and the fan heater doesn't have any decent form of regulation.

Anyway... Here comes Version 2 of the greenhouse computer. The three boards are, starting at the bottom of the stack,

  • A Raspberry Pi 3B+
  • A Relay card with four mains relays
  • and a Pi Sense HAT.
The problem you get with putting these units in a case is that the Pi warms up the air in the case, so the Sense HAT gives false temperature readings. In Version 1 of the computer, there was a fan blowing air from outside the case onto the HAT's sensors, and that's what I'm doing in Version 2. The fan has just gone in, but I still need to put trunking to direct its air stream over those sensors.

You can see a nice long camera lead on the left, so the camera can go in a separate case. The mains wiring feeds mains to a couple of sockets on the back of the case, one for the heater, and one spare. The relays switch the sockets on and off.

More to follow...

Friday, June 21, 2019

What was du Pont of that?

I sell stuff on eBay. It's mostly stuff we bought a while ago, own, and no longer want. Shortly after I sold an old pair of dive gloves to somebody, I got this email...


When I investigated, I found the complaint had been made by somebody at E. I. di Pont de Nemours and Company, who has nothing better to do with their time than find people using the word Kevlar in the description of a pair of old gloves with Kevlar in them, which was indicated by the use of the word Kevlar on a label attached to the gloves, and force eBay to take down the listing containing the word Kevlar.

Am I supposed to sell the gloves by saying they are "reinforced with something jolly strong whose name I can't mention"? It's not as if I was claiming to have invented Kevlar, and the manufacturer of the gloves was proud that they contained Kevlar.

Do not read this aloud. If you do, du Pont will probably claim you have made an unauthorised broadcast of their registered trade name, Kevlar.


Kevlar Kevlar Kevlar 

Wednesday, June 19, 2019

Nigel Farage's Lie Machine

A leaflet from "the EFDD Group in the European Parliament" was delivered here yesterday, and I suspect a lot of other people will have had a copy. Many will have been recycled, and quite a lot will have been enjoyed by the sort of people that believe Farage's lies.

Make no mistake. It's a pack of lies.

Allegedly, we need to "respect a free and fair national referendum".

That's not easy, as we haven't had one. Had it been free, five million people would not have been gerrymandered out of their vote. Had it been fair, it would not have been won by 

  • foreign interference, 
  • the disappearance of a million postal votes,
  • breaking the law on spending, and
  • a campaign that was nothing but lies.

The leaflet talks about "Project Fear", and as usual, these people pretend that Project Fear was something the Remain camp used to get support.


It was not. The Leave groups made it up. Whenever somebody pointed out that Brexit would inevitably lead to a particular bad result, they just claimed it was Project Fear, without bothering to provide any argument or evidence against the bad result of Brexit. And the news media never challenged them on that.


Lie 1.

George Osborne underestimated the number of jobs that would be lost, as you can easily tell, from the fact that that number has long since been overtaken, and we haven't even left yet.

The record high figure is, of course, a figment of the Tory government's increasingly bizarre ways of counting the number of people in work - somebody who gets paid to do an hour a week is counted as having a job. Anyone using the figure is at least as dishonest as the Tories.

The claimed number of vacancies, which is so conveniently just a little bigger than Mr Osborne's 800 thousand, is presumably derived from the number of farm labourers who haven't come here, and the number of EU nurses who have left, or some other such imaginative way of making up a number.


Lie 2.

Anyone with a prescription for Venlafaxine will know that shortages of drugs are already happening, even before we have left, even before the "just walk away" no deal scenario the Brexit fanatics now claim everyone knew they were voting for.

The worst part of this lie is that things like insulin cannot be stockpiled, because they have a limited shelf life. What seems "pretty sensible" to these liars is something that isn't even possible.



Lie 3.

Quite a clever lie, this one! Yes, the economy has indeed continued to grow, but the amount it grows by keeps decreasing, so that it is currently hardly growing at all. At the current rate of change, we will very soon be into the actual recession that was predicted.

As for remaining one of the strongest economies, the truth is that we have slipped down a couple of places in the list...

Whether you like Mr Osborne, or not, what he said was not "complete and utter rubbish".


Lie 4 to∞

Infinity and beyond, of course. Lies are all the Leave lot have, after all. Whether it's Alexander Boris de Pfeffel Johnson, with his £350 million a week (which wasn't the true amount) being saved and spent on the NHS (it won't be), or yet more of Nigel Farage's lies, the lies go on and on...

Analysing the rest of the lies in the leaflet would take all day, much of the night, and possibly longer. Meanwhile, the people who look after the money have noticed that Nigel Farage has been collecting rather a lot more than they think he is entitled to, and have started trying to get it back from him. And his clever scheme of getting what appear to be possibly illegal foreign donations in £500 pieces via payPal may well backfire on him...

Saturday, August 18, 2018

Recent python door cam code - ugly, but works.

Updated version of the code...
It deals with the occasional hangs in the camera capture process by
rebooting when they happen. A line in /etc/rc.local runs the program again.

# Program for PiDoorCam

# Detects motion, and when it spots some, takes a high resolution
# picture, and sends the picture to PiScreen

import io
import os
import picamera
import ftplib
import time
from datetime import datetime
from PIL import Image
import requests

camera = picamera.PiCamera()
picamera.PiCamera.CAPTURE_TIMEOUT = 30

# If we detect 100 pixels that changed by 30, we have seen movement.
#difference = 30
#pixels = 100
# Desensitise!
#difference = 30
difference = 50
pixels = 150

# May as well use the maximum resolution of the camera.
# This is for V1. V2 is 3280 x 2464.
width = 2592
height = 1944

# I copied this voodoo motion detection from somewhere. Changed the timeout
#  setting above to prevent the occasional failures to complete captures.
def compare():
   camera.resolution = (100, 75)
   stream = io.BytesIO()
   format = 'bmp'
   # Handle occasional 'Timed out waiting for capture to end'
   try:
      camera.capture(stream, format)
   except:
      print ("Camera timed out, reboot needed!")
      os.system("sudo reboot now")
       
   stream.seek(0)
   im = Image.open(stream)
   buffer = im.load()
   stream.close()
   return im, buffer

# Function to take a new high resolution picture, send it to PiScreen
# send it to my phone, and then delete it.
def newimage(width, height):
    when = datetime.now()
    filename = "door-%04d%02d%02d-%02d%02d%02d.jpg" % (when.year, when.month, when.day, when.hour, when.minute, when.second)
    camera.resolution = (width, height)
    camera.capture(filename)

    connected = True
    ftp = ftplib.FTP()
    ftp.connect("PiScreen")
   
    try:
        ftp.login("pi","******************")
    except ftplib.all_errors:
        connected = False
        print ("Failed to connect to server %s" % e)   
       
    if connected:
        ftp.storbinary('STOR '+filename, open(filename, "rb"))
        print ("Sent ", filename)

    ftp.quit()

# Code to send the Pushover message. Make picture smaller first.
    im = Image.open(filename)
    im.resize((324,243),Image.ANTIALIAS)
    im.save(filename)
   
    r = requests.post("https://api.pushover.net/1/messages.json", data = {
        "token": "***********************************",
        "user": "*************************************",
        "device": "***********",
        "sound": "intermission",
        "message": filename
    },
    files = {
        "attachment": (filename, open(filename, "rb"), "image/jpeg")
    })
# Check r for problems - maybe put a delay here?
    if r.status_code != 200:
        print("Pushover message failed.")
    else:
        print("Pushover accepted the message.")
       
# Now delete the file.
    os.remove(filename)
    # Delay to avoid being nasty to Pushover server.
    time.sleep(5)

# Main program.

camera.rotation = 180
print("Running door.py")
image1, buffer1 = compare()

newimage(width, height)

while (True):

   image2, buffer2 = compare()

   changedpixels = 0
   for x in range(0, 100):
      for y in range(0, 75):
         pixdiff = abs(buffer1[x,y][1] - buffer2[x,y][1])
         if pixdiff > difference:
            changedpixels += 1

   if changedpixels > pixels:
      newimage(width, height)

   image1 = image2
   buffer1 = buffer2



Code below is an older version, the "error handling" doesn't actually work.

# Program for PiDoorCam

# Detects motion, and when it spots some, takes a high resolution
# picture, and sends the picture to PiScreen

import io
import os
import picamera
import ftplib
import time
from datetime import datetime
from PIL import Image
import requests

camera = picamera.PiCamera()
picamera.PiCamera.CAPTURE_TIMEOUT = 30

# If we detect 100 pixels that changed by 30, we have seen movement.
#difference = 30
#pixels = 100
# Desensitise!
difference = 30
pixels = 150

# May as well use the maximum resolution of the camera.
# This is for V1. V2 is 3280 x 2464.
width = 2592
height = 1944

# I copied this voodoo motion detection from somewhere. Changed the timeout
#  setting above to prevent the occasional failures to complete captures.
def compare():
   camera.resolution = (100, 75)
   stream = io.BytesIO()
   format = 'bmp'
   # Handle occasional 'Timed out waiting for capture to end'
   try:
      camera.capture(stream, format)
   except:
      print ("Retrying camera.capture()")
      camera.capture(stream, format)
 
   stream.seek(0)
   im = Image.open(stream)
   buffer = im.load()
   stream.close()
   return im, buffer

# Function to take a new high resolution picture, send it to PiScreen
# send it to my phone, and then delete it.
def newimage(width, height):
    when = datetime.now()
    filename = "door-%04d%02d%02d-%02d%02d%02d.jpg" % (when.year, when.month, when.day, when.hour, when.minute, when.second)
    camera.resolution = (width, height)
    camera.capture(filename)

    connected = True
    ftp = ftplib.FTP()
    ftp.connect("PiScreen")
 
    try:
        ftp.login("pi","**********************************")
    except ftplib.all_errors:
        connected = False
        print ("Failed to connect to server %s" % e) 
     
    if connected:
        ftp.storbinary('STOR '+filename, open(filename, "rb"))
        print ("Sent ", filename)

    ftp.quit()

# Code to send the Pushover message. Make picture smaller first.
    im = Image.open(filename)
#    im.resize((648,486),Image.ANTIALIAS)
    im.resize((324,243),Image.ANTIALIAS)
    im.save(filename)
 
    r = requests.post("https://api.pushover.net/1/messages.json", data = {
        "token": "**********************************",
        "user": "********************************",
        "device": "************",
        "sound": "intermission",
        "message": filename
    },
    files = {
#        "attachment": ("image.jpg", open(filename, "rb"), "image/jpeg")
        "attachment": (filename, open(filename, "rb"), "image/jpeg")
    })
# Check r for problems - maybe put a delay here?
    if r.status_code != 200:
        print("Pushover message failed.")
    else:
        print("Pushover accepted the message.")
       
# Now delete the file.
    os.remove(filename)
    # Delay to avoid being nasty to Pushover server.
    time.sleep(5)

# Main program.

camera.rotation = 180
print("Running door.py")
image1, buffer1 = compare()

newimage(width, height)

while (True):

   image2, buffer2 = compare()

   changedpixels = 0
   for x in range(0, 100):
      for y in range(0, 75):
         pixdiff = abs(buffer1[x,y][1] - buffer2[x,y][1])
         if pixdiff > difference:
            changedpixels += 1

   if changedpixels > pixels:
      newimage(width, height)

   image1 = image2
   buffer1 = buffer2

Friday, June 22, 2018

The Wisdom of the Ancients - Part 94

I tried to find this one one Google, but there was no sign of it!

mpirun mca_oob_tcp_recv_handler  invalid message type: 43

Basically, it means you have not noticed you are trying to control a cluster of Raspberry Pi 3 B+ computers that are running Raspbian Stretch with a Raspberry Pi that has somehow still got Raspbian Jessie on it.

You're welcome!

Oyster, before I got all the bricks.