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()