Links and Chains

The distance along a road (iron or tarmac) is referred to as the chainage, formally measured using a chain the length of a cricket pitch (22yards or 1/80th of a mile).

To calibrate the odometer of the dynamometer wagon, the raised level track of the Teesside Small Gauge Railway in Preston Park was surveyed with a metal tape measure and marks made every 99″, that is every eighth of a chain. The whole circuit was thereby measured as 16chains 65feet 3inches, although a mark was made 9″ further on to make a calibrated 17c.

The dyno wagon has a tone wheel with 31 slots in it attached to one of its axles. This is monitored with a light gate, thus making a square wave with 31 pulses per revolution. This is played into an input pin on an Arduino Teensy.  Each edge of this square wave triggers a CAN message, which is sent to another Teensy for counting; the count being displayed on a slightly retro looking 8x7segment LED display.

Three circuits of the 17chain track were made and the counts recorded as 74770; 74788; 74741.  These are all within 0.05% of their average.

The calibration therefore came out to be 0.1801″ per count. This puts the diameter of the wheels at 90.625mm which is close to the 90mm in the specification (plus a bit for the crud on the tyres).

Recalibrating the software, (with great thanks to the modern 32bit fixed point arithmetic) gives the display in chains, feet and inches.

The ground level track at Preston Park was thus measured from the platform to the loop, at 18c 46′ feet give or take half a fathom, whilst the raised level track at York was measured three times at 15c 61′ 0.0″ ; 15c 61′ 6.1″ and 15c 61′ 5.8″. Stopping at the same spot was tricky though so the 6″ may have been due to driver error.

Water Levels

In the midst of the heatwave, we have been running low on water for the garden and the occasional shower has not had much effect on the water barrel stocks.

To measure the level, I had in mind to use a Time of Flight laser range finder (such as the VL53LOX) which come nicely packaged on a PCB for arduino from ebay (£5.99 with free postage). This could be powered by a solar cell, read by an ESP32 (occasionally) and reported over the IoT wifi to an app on my mobile phone. I’d then be able to check the level from anywhere in the world.

Unfortunately I didn’t have one to hand.

I did however have a half full plastic tub of paint; a length of string, two pulleys and a nut splitter so in the space of half an hour or so knocked up a level gauge inspired by those on the side of water towers for steam trains.

Unfortunately I can only read it when standing next to it, but that is easier than getting my phone out, logging into wifi, finding the webpage…..

Lawnmower Fix

After a few years of hard work, the cheap and formally cheerful lawnmower decided it wanted to be put out to grass and packed up.

Before it headed to the great lawnmower rest home in the tip, I decided to fulfill its wish of donating its body to science and took a P2 screwdriver and a 13mm spanner to it.

The insides showed the ravages of many years of grazing but with a bit of a vacuum and brush up the brushes seemed fine and the wiring sound.

The finger of suspicion then turned to the switch and a few prods with a continuity detector found a non conducting but otherwise sound looking neutral wire.

It seems that mid insulation, a break had burnt through.

With the break cut out, the continuity was restored and many more years of happy mowing is anticipated.

Christmas is over

Before Christmas, my team bought me a novelty tie, which I agreed to wear every day on the run up to the holiday.

Now the season to be jolly is over, I turned to my power supply to see if i could pep it up a bit…

 This is at 3v… the click is me turning off the PSU  

At 6v ….
  
At 10V…

  
After which it didn’t want to play anymore..
 

Internet of House

The result is a graph of the temperatures in the house, emailed twice a day.


Room Temperatures
These are requested from the crontab schedule:

00 00 * * * /home/pi/house/Send_graphs
33 12 * * * /home/pi/house/Send_graphs
02 00 * * * cat house/Temps.txt >> house/cumlat.txt
03 00 * * * rm house/Temps.txt
* * * * * date >> /home/pi/house/Temps.txt
* * * * * python3 /home/pi/house/Read_temps.py3 >> /home/pi/house/Temps.txt

                                This executes the Send_graphs script below at midnight and 12:33

                                Send_graphs:

                                #!/bin/bash
                                cd /home/pi/house
                                python Email_graphs.py

                                Where the python script Email_graphs.py is :

                                #! /usr/bin/python
                                # Python script to email the graph of temperature data

                                #Config data for the smtp server.
                                SMTPserver = ‘xxx.com’
                                USERNAME = “xxxx”
                                PASSWORD = “xxxx”
                                destination = [‘phil.barber2@gmail.com’]
                                sender = ‘<Emerlie@xxxx.com>’
                                text_subtype = ‘plain’
                                content=”See Attached File”
                                # Import some libraries
                                import sys
                                import os
                                import re
                                import time
                                from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL)
                                from email.MIMEMultipart import MIMEMultipart
                                from email.MIMEBase import MIMEBase
                                from email.MIMEText import MIMEText
                                from email import Encoders
                                from subprocess import call

                                # Proces the data so that Gnuplot can develop a graph
                                # the data has been stored in Temps.txt that is cleared out once per day.

                                output_file = open(“Temps.dat”,’w’);
                                input_file = open(“Temps.txt”,’r’);
                                lasttime = 0.0
                                Aline = input_file.readline()
                                while Aline : 
                                # ( An empty string is considered false.) 
                                  if (Aline.find(“UTC”)>0) :
                                    lasttime = time.mktime(time.strptime(Aline[0:28],”%a %d %b %H:%M:%S UTC %Y”))
                                    output_file.write(‘\n’)
                                    output_file.write(time.strftime(“%H, %M , “,time.gmtime(lasttime)))
                                  else :
                                    End_of_line = Aline.find(‘\n’)
                                    output_file.write(Aline[10:End_of_line])
                                    output_file.write(” , “)
                                  Aline = input_file.readline()
                                input_file.close()
                                output_file.close()

                                # Use a gnuplot script to generate the graphs
                                call([“gnuplot”,”R1_graph.gnu”]) 

                                # Email the graph
                                msg = MIMEMultipart()
                                msg[‘From’] = sender
                                msg[‘Date’] = time.strftime(“%a, %d %b %Y %H:%M:%S %z”)
                                msg[‘To’] = ‘, ‘.join(destination)   
                                msg.attach(MIMEText(content))

                                try:
                                    attachment_file = ‘/home/pi/house/Temps_1.jpg’
                                    attach_file_handler = open(attachment_file,’rb’)

                                    attach_part = MIMEBase(‘application’,’octet-stream’)
                                    attach_part.set_payload(attach_file_handler.read())
                                    Encoders.encode_base64(attach_part)
                                    attach_part.add_header(‘Content-Disposition’, ‘attachment; filename=”%s”‘ % attachment_file.split(‘/’)[-1])
                                    msg.attach(attach_part)

                                    conn = SMTP(SMTPserver,465)
                                    conn.ehlo()
                                    conn.login(USERNAME, PASSWORD)
                                    conn.ehlo()
                                    conn.sendmail(sender, destination, msg.as_string())
                                    conn.close()

                                except Exception, exc:
                                    sys.exit( “mail failed; %s” % str(exc) ) # give a error message

                                This needs an SMTP server set up, and processes temperature data from a text file into a csv file, that Gnuplot reads to generate a jpg.

                                The csv file is of the form:
                                13, 48 , 25, 23.0, 45.1, 13.9 , 99, 15.8, 7.9, 12.8 , 
                                13, 49 , 25, 23.0, 44.9, 13.9 , 99, 15.8, 8.0, 12.8 , 
                                13, 50 , 25, 22.9, 44.8, 13.9 , 99, 15.8, 7.9, 12.8 , 
                                13, 51 , 25, 22.8, 44.7, 13.9 , 99, 15.8, 7.9, 12.8 , 
                                13, 52 , 25, 22.8, 44.6, 13.8 , 99, 15.8, 7.9, 12.8 , 
                                13, 53 , 25, 22.8, 44.8, 13.8 , 99, 15.8, 7.9, 12.8 , 
                                13, 54 , 25, 22.8, 44.7, 13.8 , 99, 15.8, 7.9, 12.8 , 
                                13, 55 , 25, 22.7, 44.6, 13.8 , 99, 15.8, 7.9, 12.7 , 
                                13, 56 , 25, 22.7, 44.5, 13.9 , 99, 15.8, 7.9, 12.7 , 
                                13, 57 , 25, 22.6, 44.5, 13.8 , 99, 15.8, 7.9, 12.7 , 
                                13, 58 , 25, 22.6, 44.3, 13.8 , 99, 15.8, 7.9, 12.7 , 
                                13, 59 , 25, 22.6, 44.0, 13.8 , 99, 15.8, 7.9, 12.7 , 
                                14, 00 , 25, 22.6, 43.8, 13.8 , 99, 15.8, 7.9, 12.7 , 
                                14, 01 , 25, 22.5, 43.6, 13.8 , 99, 15.8, 7.9, 12.6 , 
                                14, 02 , 25, 22.4, 43.6, 13.8 , 99, 15.8, 7.9, 12.6 ,

                                This is in the form of hh,mm, IP, T1, .. Tn, IP, T1, … Tn, where the last byte of the IP is recorded for each outstation. 

                                This csv is used by the following gnuplot script R1_graph.gnu  to generate the jpg.

                                set datafile separator “,” 
                                set term jpeg
                                set output “Temps_1.jpg”
                                set title “Room Temperatures in Stokesley from Emerlie”
                                set xlabel “time of day (UTC) ->”
                                set ylabel “Temperature deg C”
                                set xrange [0 : 24]
                                set yrange [0 : 25]
                                set grid
                                set xtics 3
                                set ytics 5

                                plot \
                                 “Temps.dat” using ($1*60+$2)/60:4 ls 19 lc rgb “green” with linespoints title ‘L1’ , \
                                 “Temps.dat” using ($1*60+$2)/60:6 ls 7 with linespoints title ‘H1’ , \
                                 “Temps.dat” using ($1*60+$2)/60:7 ls 19 with linespoints title ‘H2’ , \
                                 “Temps.dat” using ($1*60+$2)/60:8 ls 13 with linespoints title ‘H3’  

                                The CSV file is generated from an original txt file which is of the form:

                                Sat 3 Dec 00:10:01 UTC 2016
                                192.168.1.20, 14.6
                                Local : 99, 13.1, 6.9, 10.7
                                Sat 3 Dec 00:11:01 UTC 2016
                                192.168.1.20, 14.6
                                Local : 99, 13.1, 6.9, 10.7
                                Sat 3 Dec 00:12:01 UTC 2016
                                192.168.1.20, 14.6
                                Local : 99, 13.1, 6.9, 10.7
                                Sat 3 Dec 00:13:01 UTC 2016
                                192.168.1.20, 14.6
                                Local : 99, 13.1, 6.9, 10.7
                                Sat 3 Dec 00:14:01 UTC 2016
                                192.168.1.20, 14.6
                                Local : 99, 13.1, 6.9, 10.8
                                Sat 3 Dec 00:15:01 UTC 2016
                                192.168.1.20, 14.6

                                Which is generated by piping the result of a python(3) script to read all the temperatures from the outstations to a cumulative file.  This is executed every minute, from the crontab scheduler.

                                Read_temps.py3

                                import sys
                                import urllib.request
                                Tstart=0;
                                res = “mary had a little lamb”

                                def Read_remote_at(Meters_IP_Address):
                                  ” Read meter HTTP”
                                  u_m = ‘http://&#8217; + Meters_IP_Address 
                                  f=urllib.request.urlopen(u_m)
                                  res = str(f.read())
                                  f.close();
                                  Tstart=res.find(“Temperature”)
                                  if (Tstart >0):
                                    print(u_m[7:],end=””)
                                  while (Tstart > 0):
                                    print(“,” + res[Tstart+16:Tstart+21],end=””)
                                    res = res[Tstart+10:]
                                    Tstart=res.find(“Temperature”)
                                  print()
                                  return

                                def Read_local(devicename):
                                  try :
                                   filename =’/sys/bus/w1/devices/’ + devicename + ‘/w1_slave’
                                   f = open(filename, ‘r’)
                                   line = f.readline() # read 1st line
                                   crc = line.rsplit(‘ ‘,1)
                                   crc = crc[1].replace(‘\n’, ”)
                                   if crc==’YES’:
                                      line = f.readline() # read 2nd line
                                      mytemp = line.rsplit(‘t=’,1)
                                   else:
                                      mytemp = 99998
                                   f.close()
                                   return (int(mytemp[1])/float(1000) )
                                  except:
                                    return 99999

                                if __name__ == ‘__main__’:
                                  # Script has been called directly
                                  
                                  Read_remote_at(‘192.168.1.20′)

                                  T1 = ’28-031660d695ff’
                                  T2 = ’28-0316837908ff’
                                  T3 = ’28-05168435eaff’ 

                                  print (‘Local : 99, ‘ + \
                                  ‘{:4.1f}’.format(Read_local(T1)) + \
                                  ‘, {:4.1f}’.format(Read_local(T2)) + \
                                  ‘, {:4.1f}’.format(Read_local(T3)) \
                                  )

                                Finally, crontab schedules a daily cleanup of the txt file, but before this, it concatenates it to a long term store.

                                Internet of Thing

                                This is a meter, developed to show the temperature of the hot water tank.  The actual temperature is measured using a Raspbery Pi in the loft.

                                file_001     file_000

                                It is based on an ESP8266 Arduino device, and a dirty great ammeter from a diesel engine.

                                The meter is adjusted by a simple html call to the IP address:

                                http://192.168.0.14/Meter?Meter=560  (from my network only 😉

                                The Pi in the loft is programmed to call this site.

                                Continue reading