1

I have my pi set up to text my phone (XXXXXXXX@vtext.com) through a google account when the CPU reaches or exceeds 45 degrees Celsius. I would like to be able to message back to the account and have the pi execute various scripts based on the content of the message. For instance, I may type "Put the fan on high." and it will execute a script that raises the fan speed. Or if the fan is already on high, I would like to be able to type "Shutdown." and have the pi shutdown. I have the pi checking the account via POP, the only problem is it shuts down every time no matter what I type, I can't figure this one out. This is way beyond my python knowledge.

import poplib
import os
from email import parser

pop_conn = poplib.POP3_SSL('pop.gmail.com')
pop_conn.user('XXXXXXXXXXXXXX')
pop_conn.pass_('XXXXXXXXXXXXXX')
#Get messages from server:
messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)]
# Concat message pieces:
rebootMessage = ["\n".join(Reboot[1]) for Reboot in messages]
fanMessage = ["\n".join(PutFanOnHigh[1]) for PutFanOnHigh in messages]
#Parse message intom an email object:
rebootMessage = [parser.Parser().parsestr(Reboot) for Reboot in messages]
fanMessage = [parser.Parser().parsestr(PutFanOnHigh) for PutFanOnHigh in messages]

#If parsestr returns True for the current element (i.e. it's the string you're looking for)
for rebootMessage in messages:
  os.system('sudo /storage/SKYNET/remoteReboot.sh')
#If parsestr returns True for the current element (i.e. it's the string you're looking for)
for fanMessage in messages:
  os.system('sudo /storage/SKYNET/fanSpeedHigh.py')
pop_conn.quit()
  • Why not automate the process...? Write a script which measures the temperature and responds by turning on/off a fan at a certain temperature. This way you don't have to send commands from your phone – nagyben Apr 6 '14 at 15:36
  • If the fan is already on high, I would like to be able to shut it down as well. I will also use this code as a base for other remote controls. – SuperAdmin Apr 6 '14 at 18:32
  • So how often does your program check the email? – nagyben Apr 6 '14 at 18:36
  • As of now it doesn't. I will set up crontabs to run this script as frequent as I deem necessary. – SuperAdmin Apr 6 '14 at 18:40
  • This question appears to be off-topic because it is about programming. it would probably be more useful on stackoverflow – kolin May 12 '14 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.