Sunday, September 29, 2013

Memory Leak?

My Pi runs with the following command in the crontab file

0 0 * * * sh memtest >>stats/memavail

Which means "check and record free RAM every midnight" and where memtest contains:

date "+%D %R"
grep MemFree </proc/meminfo

And here's the memavail data since 9/11:

MemFree:          368780 kB (after reboot)
09/11/13 00:00
MemFree:          206572 kB
09/12/13 00:00
MemFree:          199620 kB
09/13/13 00:00
MemFree:          194668 kB
09/14/13 00:00
MemFree:          191468 kB
09/15/13 00:00
MemFree:          381268 kB
09/16/13 00:00
MemFree:           82852 kB
09/17/13 00:00
MemFree:           15280 kB
09/18/13 00:00
MemFree:           15536 kB
09/19/13 00:00
MemFree:           16552 kB
09/20/13 00:00
MemFree:          368384 kB (after reboot)
09/21/13 00:00
MemFree:          182220 kB
09/22/13 00:00
MemFree:          174812 kB
09/23/13 00:00
MemFree:          170820 kB
09/24/13 00:00
MemFree:          168828 kB
09/25/13 00:00
MemFree:          167620 kB
09/26/13 00:00
MemFree:          166388 kB
09/27/13 00:00
MemFree:          164620 kB
09/28/13 00:00
MemFree:          164124 kB
09/29/13 00:00
MemFree:          163124 kB

So, does the free RAM just diminish until nothing will run? Or will there be a miracle garbage collection when things get tight? My little shell file (memtest) could also force a reboot when memfree got below an arbitrary value. But is it necessary?

Anyone know?

Friday, September 20, 2013

29: Perfect Hindsight

From what I know now I would have made several different hardware choices. For instance:

1. I initially blew off the Adafruit ribbon connector from the Pi's 26 pins to the breadboard. It didn't take long for things to get really messy (and it led to wiring mistakes).

2. Another way to cut the mess: lots of short wire lengths. I'm facing a big re-wire to get sane.

3. Here's a device that has caused me grief -- it won't stay connected:
This DHT22's pins are so fine that they don't make a reliable connection with female breadboard wires. I finally had to tin the pins (VERY carefully). A better choice (for a couple $ more) is the wired AM2302 version:

4. I certainly learned something, but controlling a solenoid with a transistor was a lot more trouble than using a Darlington array -- and the array will do 8 devices:

5., 6. I suppose every Pi beginner starts with buttons and LEDs. I mentioned (back many episodes) that I didn't know that polarity mattered with LEDs, but I got over that. However, the buttons I bought don't stay put on the breadboard. Half the time when I release the button it jumps out of its socket. Luckily, I've learned to control the Pi -- first from SSH and now from a Web page.

I also got some 3-wire spring connectors (hopefully to make reliable connection to stripped wires). That probably works but do they ever waste breadboard real estate.

Wednesday, September 18, 2013

Post 28: How I got my Pi to upload files to the Web

I first tried to "automate" FTP. But that command is oriented toward human (rather than programmed) input. That led me to CURL. I didn't bother to learn what the "c" stands for but the "url" part is obvious. So (in SSH) I typed--

  curl --help

And I got a "command not found"-type message. So then I blindly typed--

  sudo apt-get update # always a good idea

And

  sudo apt-get install curl

Ha! That worked too.

Then I set up my ".netrc" file. Which looks like this:

machine ftp.yourplace.com
login your-user-name-at-yourplace
password your-pw-there

And make it secure (from ls -l .netrc)--

-rw-r----- 1 yourpi yourpi (file length) Sep  3 16:47 .netrc

Then you can enter a curl command like this--

curl --netrc -T file-to-send ftp://ftp.yourplace.com/some-folder/

And if that works, you can make a bash command file like this--

#!/bin/bash
for i in your-list-of-files ...
do
 if [ -f $i ] ;
 then
  if [ $i -nt uploadtime ] ; # only send files that are "new"
  then
    curl --silent --netrc -T $i ftp://ftp.yourplace.com/.../
    echo $i
  fi
 fi
done
date >uploadtime # save the time stamp

Then add it to your crontab tasks (to run as often as you need). You need to know about crontab!

Anyway, that's (sort of) how my Pi's data gets to http://raspi-online.info/

Wednesday, September 11, 2013

Episode 27: Extending Sensors using Ethernet (CAT5) cable

I bought 4 RJ-45 breakout circuits:
So I hooked 2 of them up to my DHT22 temperature sensor with 50' of 24-gauge CAT5 cable between them:
And it worked.

The DHT takes 3 of the 8 wires, but one is ground (which could be shared).  So I could probably extend 4 devices with one pair of these interface cards. That's way better than using 3-wire electrical extension cords. My 4 plugs cost about $20 with shipping. The 50' CAT5 was $15.

Tuesday, September 10, 2013

There was an old lady Raspberry Pi who lived in a shoe shoebox...

undressed

covered up

My wife was tired of the messy-looking wires. So now the Pi resides in its box. From there, it updates its Web page every few minutes (see raspi-online.info). The states of the water valve and door switch are not currently being reported. The box has only raised the CPU temperature only a few degrees (I cut a dozen holes) but I'm going to add heat-sinks, anyway.

Friday, September 6, 2013

25: RaspBerry Pi — Farm Worker


Here's my current idea for the equipment layout:


The UPS will allow the Pi to ignore momentary power glitches and to shutdown gracefully if the outage lasts more than a few minutes. In case the UPS doesn't signal power failure, the photosensor shown above is a cheap solution.

Everything in the diagram adds up to no more than $300. But the trick to making it reliable will be in the software.

Tuesday, September 3, 2013

My Raspberry Pi will be Controlled from a Web Page

My Rpi now has a web page. It is still very crude and will only be available at my convenience.

The UNIX/Linux cron daemon (runs programs per a schedule) automatically sends sensor updates to the site.

See
raspi-online.info