DBK
LIFE MEMBER
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:
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)
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:
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: