My grandson and I built a weather station on the terrace. He wrote the Python, I wrote the SQL, and the rain did the rest.
Contents
Dear friends,
Some of you have read my long stories about the bank. This one is shorter, and happier, and I hope you will forgive an old man for being a little proud.
My grandson Vignesh is fourteen. He lives with us in Chennai while his parents work in Bengaluru, and for most of last year our relationship consisted of me asking him to put his phone down and him explaining to me, very patiently, that Python is better than COBOL. I do not dispute this. I only dispute his tone.
In July his school announced a science exhibition. He came to me (this alone was remarkable) and asked if I would help him build "something with that Raspberry Pi you keep on the terrace". That Pi had been sitting in a plastic box for a year, running nothing but a clock.
What we built
Over three months of Saturday mornings, with filter coffee for me and Horlicks for him (he denies the Horlicks):
- A Raspberry Pi 4 in a ventilated box in the shade under the water tank on the terrace.
- A BME280 sensor for temperature, humidity and pressure, on the I2C pins. Vignesh soldered the header himself. I held the torch. We both burnt our fingers, him once and me twice.
- A tipping bucket rain gauge, bought online for about Rs. 2,000. Every time its little bucket fills with rain and tips, it closes a magnetic switch, and the Pi counts it. Each tip is 0.2794 mm of rain, because it is an old American design and the number is really 0.011 inches. Vignesh wanted to know why such a strange number. I told him that is what happens when you let Americans design rain gauges. He found this very funny and repeated it to his teacher, who did not.
- Python to read the sensors every five minutes (his part). With the gpiozero library, the rain counter was only a few lines:
from gpiozero import Button
tips = 0
def tipped():
global tips
tips += 1
gauge = Button(17, pull_up=True, bounce_time=0.05)
gauge.when_pressed = tipped
- SQLite to store the readings (my part, and I was firm about this). He wanted to write everything to a text file. I gave him a lecture on data integrity which he says was forty minutes, and which I maintain was twenty. We agreed on this table:
CREATE TABLE reading (
taken_at TEXT PRIMARY KEY, -- ISO time in UTC, one row per 5 minutes
temp_c REAL NOT NULL,
humidity REAL NOT NULL,
pressure REAL NOT NULL,
rain_tips INTEGER NOT NULL DEFAULT 0
);
And then the query I am proudest of, daily rainfall in millimetres, which he now calls "Thatha's query":
SELECT date(taken_at, '+5 hours', '+30 minutes') AS day_ist,
ROUND(SUM(rain_tips) * 0.2794, 1) AS rain_mm,
ROUND(MAX(temp_c), 1) AS max_c,
ROUND(MIN(temp_c), 1) AS min_c
FROM reading
GROUP BY day_ist
ORDER BY day_ist DESC;
(The '+5 hours', '+30 minutes' is because we store UTC, and in India the day begins five and a half hours earlier. Vignesh asked why we do not simply store Indian time. I told him about a night in 1998 when a vendor's system running in two time zones posted interest on the wrong day for nine thousand accounts, and he has stored UTC ever since.)
The exhibition
The exhibition was last Saturday. By luck we had a tremendous thunderstorm the week before, and on the Wednesday the station recorded 71 mm in one afternoon. Vignesh printed a graph. He made a poster that said "Real Chennai Rain, Measured on Our Terrace".
I went along, because he asked me to. I sat at the back. When the judges came to his table, he explained the sensors, the Python and the rain gauge, and then he said, and I am quoting exactly because I wrote it down in the car afterwards:
"The database part was done by my Thatha. He wrote software for banks before the internet. He says if the data is wrong, nothing else matters."
Then he pointed at me. At the back. The judges turned around, and I did not know what to do with my hands.
He got second prize. He says first prize went to a robot that "did not even work properly". I have told him that this is also how it is in industry.
What I want to say
For thirty-four years I wrote software that nobody saw. Batch jobs at 2 am, files moving from one machine to another, interest calculated correctly on accounts belonging to people who never knew my name. That was fine. That is the job. But I did not expect, at sixty-two, to be pointed at in a school auditorium by a fourteen-year-old who until July thought I was mainly a person who tells him to put his phone down.
The weather station is still running. Last night it rained 18 mm. Vignesh checked it on his phone before school this morning, using Thatha's query, and told me at breakfast. He did not put his phone down. For once I did not ask him to.
Avvaiyar wrote "Ilamaiyil kal": learn while you are young. She said nothing about learning when you are old, so I am adding that part myself. He taught me gpiozero. I taught him a primary key. I think we both came out ahead.
With regards,
S. Ramanathan
Get the best of #touch-grass weekly
One email each Monday with the most useful posts. No spam; unsubscribe in one click.
Comments
Sign in to join the conversation.
Sign in to comment