Monitoring MH Internal Temperature and Sending Email Alert - Mk 2 (1 Viewer)

DBK

LIFE MEMBER
Jan 9, 2013
17,969
47,804
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
In a recent thread I described my efforts to build a Raspberry Pi temperature sensor which would monitor the internal temperature of the MH and send me an email if it rose too high. The purpose was to know how hot it was in the vehicle if we had to leave our dog in it.

The system worked but the hardware was more expensive than necessary so I set out to make a cheaper version using a Raspberry Pi Zero W:

DSC_0527.JPG


These cost about £9.50 but you do have to buy and solder on the 40 pin header. It is quite small and you can judge the size by the Micro SD card you can see on the left in the photograph above. The "W" in the name stands for "Wireless" which together with Bluetooth is built into the device. The original version which is still available does not have wireless or Bluetooth.

To measure temperature I bought a waterproof version of a DS18B20 so called "one wire" sensor. The name is a bit of a misnomer as it has three wires coming out of it, but two are for power and only one wire is used for the data. A pack of 5 sensors cost £6.00.

I attached the sensor and the 4.7KΩ resistor onto a small circuit board above the Pi Zero.

DSC_0528.JPG


Please ignore the quality of the soldering - I made a mistake and had to unsolder everything and put things back in the correct place. :)

The program is set to run in the background as soon as the device is powered up, sending me an email immediately and then every 30 minutes or at any interval I choose. At the moment I've set the warning temperature to 20C so I can see what it happening but by setting the warning limit higher it wont send an email unless the limit is exceeded.

I fitted it all into a purpose made case (which cost more than the basic Pi Zero :)) and here it is sitting in the MH.

DSC_0530.JPG


If you don't want to lash out on a proper case a bit of Tupperware could be adapted or you could make your own using something like foam board.

The emails look like this - these show them coming frequently but that was because I was fiddling with it and turning it on and off.

Screenshot_20180901-154210.png


The total cost of everything was about £20 but it is worth getting a Pi Zero kit at a little under £30 initially as it will come with the various adaptors needed to connect it to a keyboard and TV screen.

This device uses the MiFi in the MH to connect but if there is a Mk 3 version later it will probably use a GSM/GPRS module so it make its own calls using a cheap PAYG sim card as @scotjimland suggested.

The Python code I used is as follows. The email settings are for Gmail and will be different for other providers. The "28-01131e6729ff" number you can see is the unique identifier for the temperature sensor. Different sensors will have different numbers.

#!/usr/bin/python

import time
import sys
import os
import smtplib
import subprocess

# Set warning temperature
warningtemp = 20

# Set interval in minutes between warning emails. 28 works out every half an hour
warninginterval = 28

# initialize counter and email warning flag

counter = 0
warning = 0

# Set up the temperature sensor and read the temperature

os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

temp_sensor = '/sys/bus/w1/devices/28-01131e6729ff/w1_slave'
def temp_raw():
f = open(temp_sensor, 'r')
lines = f.readlines()
f.close()
return lines​

def read_temp():
lines = temp_raw()
while lines[0].strip()[-3] != 'YES':
time.sleep(0.2)
lines = temp_raw()
temp_output = lines[1].find('t=')
temp_string = lines[1].strip()[temp_output+2:]
temp_c = float(temp_string) / 1000.0
return temp_c
# Main loop
while True:

# read the temperature
temp_string = str(read_temp())​

# Test if over-temp and an email has not been recently sent

if temp_string > warningtemp and warning == 0:
print ("temperature: " , temp_string)​

# Send email

from email.mime.text import MIMEText​

USERNAME = "myemail"at"gmail.com"
PASSWORD = "email-pwd"
MAILTO = "myemail "at" gmail.com"
msg = MIMEText('Internal temperature = '+str(temp_string)+'C')
msg['Subject'] = 'From Murvi'
msg['From'] = USERNAME
msg['To'] = MAILTO​

server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo_or_helo_if_needed()
server.starttls()
server.ehlo_or_helo_if_needed()
server.login(USERNAME,PASSWORD)
server.sendmail(USERNAME, MAILTO, msg.as_string())
server.quit()

# Set warning flag to show an email has been sent
warning=1​

# Increment counter

counter += 1​

# Test if it is time to send another warning email

if counter > warninginterval and warning == 1:​

# If so then reset everything

counter = 0
warning = 0​

# Stop counter getting too big and potentially generating an error.

if counter > 1000:​

counter = 0​

# Delay everything for a minute

time.sleep(60)​
 
Last edited:
OP
OP
DBK

DBK

LIFE MEMBER
Jan 9, 2013
17,969
47,804
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
I don't understand a word of it ......................... but I think you're a very clever man. (y)(y)(y)
Not clever really, all the code etc is available on the interweb thingy. It is just a matter of adapting it and sticking it together so the joins are not too obvious. :)

Subscribers  do not see these advertisements

 
Apr 27, 2016
6,800
7,837
Manchester
Funster No
42,762
MH
A class Hymer
Exp
Since the 80s
These cost about £9.50 but you do have to buy and solder on the 40 pin header.
You can buy one of these with the 40 pin header already soldered on. It's called the Raspberry Pi Zero WH. The "H" indicates the the header is soldered on.
 
  • Like
Reactions: DBK

JackieP

Free Member
Mar 10, 2010
666
1,400
Isle of Man
Funster No
10,567
MH
A Class
Exp
Since 2006
What an amazing thing to put together. Well done you and thanks for the steps along the way. Not sure I could do it either but I have huge admiration for someone who can.

I hardly ever leave the dog in the van but if I do then I do find they I get stressed worrying about the build up of heat while I’m away. I often rush back only to find it perfectly comfortable and Dugal fast asleep in his bed.
 

The Dotties

Free Member
Jan 31, 2015
1,872
4,022
Gloucester
Funster No
34,955
MH
In between
Exp
Ex Newbie
Two words spring to mind.
Dragons Den.
Brilliant.
I know that’s 3, but ‘Brilliant ‘ doesn’t count.
Bugger. Now what have I done.:)

Subscribers  do not see these advertisements

 

Sportsnapper

Free Member
Sep 3, 2016
107
57
Reading
Funster No
44,934
MH
Hymer Exsis
Exp
Since 2004
Nice - though I feel even a Pi zero is a little overkill for temp monitoring. I've been wondering what I can add to ours in terms of automation and monitoring but using esp8266/NodeMcu devices. I'd hooked them up to a NodeRed server running on a Pi3. But I'm too bust atm getting some of the bigger & perhaps more 'important' things sorted out (more lights etc.)
 
Sep 17, 2017
5,334
9,941
Birmingham, UK
Funster No
50,575
MH
A-Class
Exp
2017
I'm going to have a go at this. Got the Pi on order. Further ideas are:
  • Two temperature sensors using 1-wire bus. One inside, one outside.
  • Log the data in a simple database for graphing, etc.
  • Connect to my my solar setup to see if I can gather better data than the monitor I've got is currently providing. Apparently I just need a serial connection.
 
OP
OP
DBK

DBK

LIFE MEMBER
Jan 9, 2013
17,969
47,804
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
I'm going to have a go at this. Got the Pi on order. Further ideas are:
  • Two temperature sensors using 1-wire bus. One inside, one outside.
  • Log the data in a simple database for graphing, etc.
  • Connect to my my solar setup to see if I can gather better data than the monitor I've got is currently providing. Apparently I just need a serial connection.
Best wishes, I'll be interested to hear how your solar monitoring goes and how you intend to do it. :)

Subscribers  do not see these advertisements

 

Sportsnapper

Free Member
Sep 3, 2016
107
57
Reading
Funster No
44,934
MH
Hymer Exsis
Exp
Since 2004
@Guigsy - rather than installing a DB, you could use a service - @DBK did some testing with Thinkspeak here https://www.motorhomefun.co.uk/forum/threads/what-can-you-see.181922/ - though he didn't say how he was updating it? I did a similar experiment a year or so ago, using the ESP8266 and the same sensor then updating Thingspeak via HTTP. here's an example - though I've not tried this, it's similar to code I've used in the past. https://randomnerdtutorials.com/esp8266-daily-task-publish-temperature-readings-to-thingspeak/
Though you've whetted my appetite to try this again, I even think I've got a 12v to 5v converter spare
 
Mar 23, 2012
9,447
31,630
sleights
Funster No
20,245
MH
c class
Exp
1
Ive got a couple of Pi's sitting around not being used wonder if I could use them for this it would come in usefull. I was originally going to use them for a low power pc alternative for e-mails but that was 3 years ago they are just gathering dust atm
 
OP
OP
DBK

DBK

LIFE MEMBER
Jan 9, 2013
17,969
47,804
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
@Guigsy - rather than installing a DB, you could use a service - @DBK did some testing with Thinkspeak here https://www.motorhomefun.co.uk/forum/threads/what-can-you-see.181922/ - though he didn't say how he was updating it? I did a similar experiment a year or so ago, using the ESP8266 and the same sensor then updating Thingspeak via HTTP. here's an example - though I've not tried this, it's similar to code I've used in the past. https://randomnerdtutorials.com/esp8266-daily-task-publish-temperature-readings-to-thingspeak/
Though you've whetted my appetite to try this again, I even think I've got a 12v to 5v converter spare
The Thinkspeak graphs worked but I realised for what I was trying to do a simple email was better. In theory you can get alerts from Thinkspeak but I couldnt get it to work. l think you can only get this if you pay for their subscription membership, which was around $1K a year!

Subscribers  do not see these advertisements

 
Sep 17, 2017
5,334
9,941
Birmingham, UK
Funster No
50,575
MH
A-Class
Exp
2017
I'm not decided if I want an onboard or cloud database yet.

Advantages of going via the cloud is that I've got remote access. Also that the data and it's less likely to be corrupted when the Pi gets a power spike and nukes the SD card (unlikely, but possible). There are probably a few services out there that do most of what I need, probably meaning I can get it working very quickly.

Disadvantage of sending to the cloud is that I'll always need an internet connection or the data will probably be lost. Also, as @DBK pointed out, the free ones never quite do all that you need.

I've got 250w of solar panels and an MPPT charger, so I'll be interested to see if that's enough to keep the Pi, MiFi and tracker working all winter long. I know they'll only needs a few dozen watt-hours of juice per day but if the van is in the shade, in the depths of winter, will I get anything? At least I'll be able to monitor it.

I'm powering the Pi via a Pimoroni Wide Input Shim, so it should cope with the massive fluctuations in voltage. I've just got to make sure I disconnect it if the input voltage is going critically low because it looks like it'll quite happily pancake the battery.

I was also thinking about trying to find a 1-wire light sensor to monitor daylight. With my current solar setup, often I don't seem to be generating a lot of power. I'm never quite sure whether that's because the battery charge is already pretty high, or it's not as bright as my eyes think it is. It'd be useful extra metric to have.
 

Sportsnapper

Free Member
Sep 3, 2016
107
57
Reading
Funster No
44,934
MH
Hymer Exsis
Exp
Since 2004
@Guigsy - that's a nice little board - not seen that before (but I'm not doing much with Pis atm). Wish I'd seen that before they had their 10% off day!

Subscribers  do not see these advertisements

 
OP
OP
DBK

DBK

LIFE MEMBER
Jan 9, 2013
17,969
47,804
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
Is this to tell you time to phone the fire brigade :)
That had occurred to me! But it would be very easy to alter the code so it sent an immediate email if the temperature rose above say 50°C.

Other options include a sensor to report if the vehicle moves. A camera could also be included to take a photo of the inside of the vehicle and email the image to me. This could be used as a security thing - taking a photo of any intruders. :)
 

Sportsnapper

Free Member
Sep 3, 2016
107
57
Reading
Funster No
44,934
MH
Hymer Exsis
Exp
Since 2004
I was wondering about a GPS tracker. Not for security, but so that I know where I've been (don't laugh). Our first ever Garmin Quest used to save tracks, so we could look at our journeys and see how long it took us to get somewhere, actual routes etc. Couldn't see the screen it was so small, but a great device. Now I use Co-pilot on my phone, but it doesn't keep a track. This would be one way of doing it.

Subscribers  do not see these advertisements

 

hilldweller

LIFE MEMBER
Dec 5, 2008
605
36,108
Macclesfield
Funster No
5,089
MH
Zilch Mk1
Exp
From Aug 2007
This would be one way of doing it.

Maybe re-inventing the wheel. On a bike forum I watched a bike being ridden across the USA just using a mobile phone and app. Full on screen make all beautifully marked up.

Logging GPS data is trivial, presenting it nicely takes more effort.
 

Sportsnapper

Free Member
Sep 3, 2016
107
57
Reading
Funster No
44,934
MH
Hymer Exsis
Exp
Since 2004
Missed the point. Yes, I could use my Bike Garmin to record all my M/H journeys, wouldn't be integrated with anything else, nor would be an interesting thing to do. Wheels are continually being re-invented, and they get to become better all the time.

Subscribers  do not see these advertisements

 

Geo

Trader - Funster
Jul 29, 2007
11,757
14,563
Mansfield,Notts
Funster No
35
MH
Autotrail Tracker FB
Exp
45 +years with breaks
I have a Border Collie
He will open the windows if he gets hot
But I was impressed

Subscribers  do not see these advertisements

 
OP
OP
DBK

DBK

LIFE MEMBER
Jan 9, 2013
17,969
47,804
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
I have a Border Collie
He will open the windows if he gets hot
But I was impressed
Our mutt doesn't know what a window is other than he doesn't understand why he can't jump through the holes in the walls in the house to attack the postman. :)
 

Sportsnapper

Free Member
Sep 3, 2016
107
57
Reading
Funster No
44,934
MH
Hymer Exsis
Exp
Since 2004
@Guigsy - that's a nice little board - not seen that before (but I'm not doing much with Pis atm). Wish I'd seen that before they had their 10% off day!
I was wrong, Pimorni have 10% off if you use the code YARR at checkout, ends Friday
"Shiver me timbers! It's International Talk Like a Pirate today and we're giving you scurvy sea dogs 10% off when you spend over £10 (exc. shipping) until midnight this Friday 21st September (BST)"
 
Aug 26, 2008
4,721
24,577
B&NES
Funster No
3,823
MH
Van Conversion
Exp
since 2007
The OP tech solution is brilliant. I hope one day soon we can buy a clever gadget like that off the shelf. (y)

Meanwhile, I check where the nearest trees are, and use compass bearings to select a shady pitch that stops the van from overheating in the full sun. The recent heatwave (lovely, I really enjoyed it :)) became a challenge for leaving pets in the unattended van when we went out. Otherwise the internal temperature, which I measured when it was standing on my drive without any shade, reached over 40C. :eek:

Subscribers  do not see these advertisements

 
Sep 17, 2017
5,334
9,941
Birmingham, UK
Funster No
50,575
MH
A-Class
Exp
2017
My Pi Zero W and other hardware has arrived. I think I'm going to permanently solder on the power shim board and the board to get the temperature. I'm hoping to hook up to my solar controller via a USB serial converter. I've also got an Inky Hat for low power display and a button shim so I'll be able to navigate between screens.

I'm going to log everything in an onboard database (SQLite or maybe InfluxDB) and run a simple web server for graphing and more complicated interactions. I'm now thinking about architecture. I've got a number of independent functions like temperature measurement, solar controller data scraping and display. The question is, do I just write a bunch of separate Python scripts that individually interact with the database (open database, dump/pull data, manipulate data), or do I put all the database interaction and heavy lifting in the web app and just make the individual scripts really simple as they just talk to the hardware and then call to the web server?

The fun of hacking...
 

Join us or log in to post a reply.

To join in you must be a member of MotorhomeFun

Join MotorhomeFun

Join us, it quick and easy!

Log in

Already a member? Log in here.

Latest journal entries

Funsters who are viewing this thread

Back
Top