Monitoring Internal MH Temperature and Sending Alarm Email (1 Viewer)

DBK

LIFE MEMBER
Jan 9, 2013
18,004
47,946
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
In this thread: https://www.motorhomefun.co.uk/forum/threads/what-can-you-see.181922/
I reported some early progress monitoring the internal temperature of the MH and displaying the information on a website which could be accessed from a mobile phone.

The work has moved on a bit and changed. The graphs were interesting and if I wanted to set up a remote weather station (which was the original idea :)) then this method would be fine. But what I want to do first is monitor internal temperature to ensure our dog doesn't cook if we have to leave him in there and if the temperature rises too high for the system to warn me. Of course, we shouldn't put our dog in that position in the first place but if we can at least be sure the temperatures are not too high in the MH it will give a degree of reassurance.

I tried first a method where it sent me a tweet if the temperature went above a set threshold. This sort of worked but the tweet didn't arrive for hours so that was not a lot of use!

The ideal would be for it to send me an SMS text message and Vodafone used to have a service where you could send an email and they would re-send it as an SMS message. Sadly they discontinued this service some time ago although some providers, and I think T-Mobile are one of them, still offer it.

But I'm with Vodafone so I will have to stay with emails.

The current hardware looks like this:

DSC_0515.JPG


The white thing sticking out of the side is the wireless dongle which allows the Pi to connect with the MiFi. Later Pi models have wireless (and bluetooth) built in.

The thing with the array of white squares sitting on top of the Raspberry Pi is the SenseHat which for this job is way over the top. It has numerous sensors including a magnetometer, gyroscope, accelerometers as well as the pressure, humidity and temperature sensors I used. It is an interesting bit of kit but suffers from a major weakness - being mounted above the Pi it sits in the warm air rising up from the CPU and other components so the accuracy of the temperature and relative humidity readings are wrong.

There are ways to reduce the effect and in my code I've used one of them which is to measure the CPU temperature and use it to compensate. The result isn't perfect but it is within a couple of degrees or so in my testing which is good enough as the threshold temperature at which it issues an email can be set to take this into account.

As it stands now the device measures the temperature every minute and if it goes above a temperature set by me, say 35C it will send me an email then another after thirty minutes and so on until I return and switch it off. The program can be set to run automatically when the USB cable powering the Pi is plugged into a USB socket.

The email I get looks like this:

From: Murvi (or whatever your MH is called :))

To: my email address


Subject: High temperature warning! Temperature = 26.8C

To get the email above I set the temperature threshold down to 25C so it would generate the message.

So it works, but it isn't cheap so I have started on a Mk 2 version which will use a Raspberry Pi Zero W which costs only around £10 and to sense the temperature I will use a digital temperature sensor like this, which I've used before with the Pi and cost less than a fiver. I might get it finished before we go away in a week and if so I'll report back.



For the geeks the Python code I'm using is as follows. The code following WHILE & IF statements should be indented but this doesn't seem to work on the Forum although indents are essential in Python. It is also set up for Gmail, the settings for other providers will be different. To get it to run I had to alter my Gmail settings to allow less secure apps to run. Without this the Gmail server won't accept the email.

The lines starting with "print" are not required, they just print the result in the terminal window and were useful for me to see what was happening when debugging it. These and of course the humidity and pressure lines are also not required when this is run purely as an alarm. I've left them in just for completeness. :)

An option would be to get the program to send an email every, say, thirty minutes which simply showed the internal temperature. The emails could be in two formats, an information one and a second one with the warning of high temperatures. I will look at this for the Mk 2. :)

For better security it is probably best to create a new email account for this because if the device was ever stolen my email password could be found on it. I'll have a look at this in slower time too.

#!/usr/bin/python

from sense_hat import SenseHat
import time
import sys
import os
import smtplib
import subprocess

# Set warning temperature
warningtemp = 35

# Set interval in minutes between warning emails
warninginterval = 30

# initialize counter and email warning flag

counter = 0
warning = 0

# Read SenseHat Data
sense = SenseHat()
sense.clear()

while True:
output = subprocess.check_output("cat /sys/class/thermal/thermal_zone0/temp", shell=True)
cpu = int(output)/1000 # Get CPU temperature
cpu = round(cpu, 1)
tempraw = sense.get_temperature() # Get temp from SenseHat
tempraw = round(tempraw, 1)
temp = (tempraw - (cpu - tempraw)) #Modify the temperature to compensate for the CPU temp
temp = round(temp, 1)
print "Temperature: " + str(temp)+"C" # Not required
humidity = sense.get_humidity() # Not required
humidity = round(humidity, 1) # Not required
print("Humidity :",humidity) # Not required
pressure = sense.get_pressure() # Not required
pressure = round(pressure, 1) # Not required
print("Pressure:",pressure) # Not required

# Test if over-temp

if temp > warningtemp and warning == 0:

# Set warning flag

warning = 1

from email.mime.text import MIMEText

USERNAME = "my email address"
PASSWORD = "my email password"
MAILTO = "my email address"
msg = MIMEText('High temperature warning! Temperature = '+str(temp)+'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()

# 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 > 100:

counter = 0

# Delay everything for a minute

time.sleep(60)
 
Last edited:

munkey_bwy

Free Member
May 17, 2018
67
45
Holbeach
Funster No
53,934
MH
Rapid 690 low profile
Exp
Since 2007
Very nerdy and nice. Can you not more the piehat away from the pi with a GPIO extension cable? I'm sure that they are available.
 
OP
OP
DBK

DBK

LIFE MEMBER
Jan 9, 2013
18,004
47,946
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
Very nerdy and nice. Can you not more the piehat away from the pi with a GPIO extension cable? I'm sure that they are available.
Yes that would work and if I want to try this as the basis for a weather station it would be essential but it then becomes a bit unwieldy and impractical. Ideally I want to have a one small box which I can stick on the MH interior wall which will have a small sensor sticking out of it. Hopefully, this is what the Mk 2 version will look like. :)

Subscribers  do not see these advertisements

 
Jan 19, 2014
9,358
24,688
Derbyshire
Funster No
29,757
MH
Elddis Accordo 105
Exp
since 2014
Ok if you enjoy doing it, which I suspect you do (y). If we had an animal, I think I'd leave the roof open and a fan on....

Or... A more modern solution is leave it fastened up all day outside barking :cool: sorted
 
  • Like
Reactions: TCG
OP
OP
DBK

DBK

LIFE MEMBER
Jan 9, 2013
18,004
47,946
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
Ok if you enjoy doing it, which I suspect you do (y). If we had an animal, I think I'd leave the roof open and a fan on....

Or... A more modern solution is leave it fastened up all day outside barking :cool: sorted
A good point of course, ideally the dog shouldn't be left in the MH and it doesn't happen often. But we do sometimes have lunch out, which is the hottest time of the day.
And yes, this is just a hobby thing!
 

TCG

Jul 6, 2017
1,357
2,041
Salford Priors
Funster No
49,363
MH
Autotrail Delaware
Exp
2016
A good point of course, ideally the dog shouldn't be left in the MH and it doesn't happen often. But we do sometimes have lunch out, which is the hottest time of the day.
And yes, this is just a hobby thing!
As we do. But we just leave the air con on (y) or better still, if in France just take the dog with us
 
OP
OP
DBK

DBK

LIFE MEMBER
Jan 9, 2013
18,004
47,946
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
A text is something which on my phone is very obvious when it arrives. So a text is still a very good idea and better than an email I think but I got lost looking for free providers who would turn an email into a text. As I mentioned above Vodafone don't do this anymore.

In theory it ought to be possible to use the Huawei MiFi the Pi is connecting to to send a text, it can using the app, but I couldn't find anything understandable by me how to do this from the command line.
 

The Dotties

Free Member
Jan 31, 2015
1,872
4,022
Gloucester
Funster No
34,955
MH
In between
Exp
Ex Newbie
@DBK .

I can do this a much easier way.
Wait for you to test it out, then ask when you are going into production :LOL:

Subscribers  do not see these advertisements

 
OP
OP
DBK

DBK

LIFE MEMBER
Jan 9, 2013
18,004
47,946
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
I've worked out how to do indents on the forum, so here is a simplified version of the code above. It is what will be used on the alarm only Mk 2 version. :)

#!/usr/bin/python

from sense_hat import SenseHat
import time
import sys
import os
import smtplib

# Set warning temperature
warningtemp = 35

# Set interval in minutes between warning emails
warninginterval = 30

# initialize counter and email warning flag

counter = 0
warning = 0

# Read SenseHat Data
sense = SenseHat()
sense.clear()

while True:

temp = sense.get_temperature()
temp = round(temp, 1)​

# Test if over-temp

if temp > warningtemp and warning == 0:​

# Send warning email

from email.mime.text import MIMEText​

USERNAME = "my email address"
PASSWORD = "my email password"
MAILTO = "my email address"
msg = MIMEText('High temperature warning! Temperature = '+str(temp)+'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 flag to record 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)​
 
OP
OP
DBK

DBK

LIFE MEMBER
Jan 9, 2013
18,004
47,946
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
Just a thought Air Con!
Indeed, and when the power fails and it stops?

But this is just a hobby thing as of course my lash up could also fail. :)

However, the concept is sound. The sensor I've used could also detect movement and either report the dog bouncing around or someone nicking the vehicle. :) Add an audio sensor and it could even report the dog barking - or a baby crying if you needed to monitor that. :)

Subscribers  do not see these advertisements

 

hilldweller

LIFE MEMBER
Dec 5, 2008
605
36,109
Macclesfield
Funster No
5,089
MH
Zilch Mk1
Exp
From Aug 2007
So a text is still a very good idea and better than an email I think but I got lost looking for free providers who would turn an email into a text.

It's so easy and cheap, look up SIM900.

I got fed up with the ipaddress problems for plain data/control and went the text way. The SIM900 modules are just so easy to use and using giffgaff for free texts cheap. And of course it works world wide wherever you can receive a text.



void sendStatus()
{
lcd.setCursor(0,1);
// 0123456789012345
lcd.print("STR");

Serial.println("AT + CMGS = \"" + destinationNumberBrian + "\"");
delay(1000);
Serial.print("Stat:");

if ( digitalRead( intruderPin ) == LOW ) Serial.print("Intruder ");

if ( reported ) Serial.print("Reported ");
else Serial.print("Not Reported ");

if ( digitalRead( setPin ) == LOW ) Serial.print("Alarm Set ");
else Serial.print("Alarm UnSet ");

Serial.write((char)26); // ctrl+z
delay(1000);

Serial.println("AT+CMGD=1,4"); // delete all SMS, returns OK
reported = false; // clear report lockout

delay(5000); // time to read STR
lcd.setCursor(0,1);
// 0123456789012345
lcd.print(" ");
}
 
OP
OP
DBK

DBK

LIFE MEMBER
Jan 9, 2013
18,004
47,946
Plympton, Devon
Funster No
24,219
MH
PVC, Murvi Morocco
Exp
2013
Many thanks for that Brian, the module is essentially a mobile phone so it makes it's own connection and therefore can send texts. That is certainly a very good alternative. :)

There is one for the Raspberry Pi too, though this one I found first is a SIM800 but would do the same job I expect. I found this description which covers it: https://learnaddict.com/2018/02/17/...sages-with-raspberry-pi-and-sim800-gsm-board/
One option would be I could send text messages to it to alter things like the threshold temperature it issues an alert at. :)

sim800-gsm-gprs-add-on-v20-raspberry-pi-hat.jpg

Subscribers  do not see these advertisements

 

hilldweller

LIFE MEMBER
Dec 5, 2008
605
36,109
Macclesfield
Funster No
5,089
MH
Zilch Mk1
Exp
From Aug 2007
One option would be I could send text messages to it to alter things like the threshold temperature it issues an alert at. :)

The world is your oyster. You could even turn on a fan to cool dog. Add a wire or two and you have an alarm that will text you. Add a GPS module and you have a tracker.

I don't know the difference with the 800 I just assumed 900 was better.

As you may have guessed the code I posted is Arduino C++. I've done some work with the Pi but for simple control the Arduino is so very cheap and a joy to use and I know C better than any other language so it suits me. Your project to me:
£5 Arduino Uno, £5 i2c LCD, £3 DS3231 Clock/Temp, £20 SIM900, from UK stock. £33.
Add GPS £6 and for £40 you have dog control, alarm, GPS tracker. Eat yer heart out Eddie.
 
3

34127

Deleted User
I have used a cheap GPS tracker and temperature monitor with alarm output. I have fed the temp alarm to the tracker alarm input. The tracker has only one alarm input but you feed many different types of alarm using diodes. If an alarm goes off you don't know what the alarm is until you go back to the vehicle but any alarm would need investigating so therefore no need to know when you receive the alert.
The tracker sends a warning to my mobile and total cost for tracker and temp monitor was approx £40.

Subscribers  do not see these advertisements

 
Oct 7, 2019
173
474
Funster No
65,001
MH
Burstner td590 lyseo
Exp
campervan for 5 years, motorhome since May 19
Two other solutions you may or may not have considered.

Firstly an inet box will send you a text at whatever temperature you request it to and has the added bonus of being linked to your heater/air conditioning and allows you to do something about it, apart from ending lunch early and returning to your motorhome.

Secondly, have a look at Arlo go cameras, these are self powered cameras with their own sim card capable of being positioned anywhere.
You could set up a thermometer in sight of the camera to monitor temperature and also be able to see and hear the dog.
You would also be able to speak to the dog as well, no auto texts though.

It can also be set up to alert you of movement inside the vehicle and works at night too via infra red.

Probably not as cheap as your solution but in the case of the Arlo go camera it could also be used as home security/baby monitor/car security etc etc.

In fact with a bit of imagination its uses are practically endless.

Just a thought

Graydo
 

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