Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - mexicanto

Pages: 1 2 [3] 4
31
I have another PY script that loads at startup, with the VC.Loaded event, and this is for
the initialization of COM port for arduino

attached is the code

Thank you

32
Thanks Nime5ter for your help

My goal is, because i have an arduino attached to the PC:

Arduino with a water sensor in the water bowl of my dog, if the water is too low
smtp sends me a mail with a warning about the low water (that part is checked and working)

I send back a mail to myself with the subject "VC"
and the body of the mail, something like "Water Dog"
and the arduino triggers an action to open a valve to serve water to the dog
(half part completed)

depends on the body of the replay mail, it could be:
Water Dog
Food Dog
Turn On Heater
Turn Off Heater
etc

Thanks again


33
The PY script is from here:
http://voxcommando.com/forum/index.php?topic=1679.msg14606#msg14606

the change i did to the PY script, was change any reference to "GmailStartu.py"

the XML:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.7-->
<commandGroup open="True" name="Gmail notifier alert" enabled="False" prefix="" priority="0" requiredProcess="" description="">
  <command id="272" name="Alert received" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Alert received.</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.AddText</cmdType>
      <params>
        <param>Subject: {1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="True">
      <ifType>(A)==(B)</ifType>
      <ifParams>{2}&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Subject. {1} . Message. {2}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>OSD.AddText</cmdType>
          <params>
            <param>Message: {2}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <event>newMsgVC</event>
  </command>
  <command id="358" name="Gmail Startup" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <params>
        <param>PY\GmailStartup.py</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
</commandGroup>

34
This is the .PY script (i uploaded before, but i forgot to erase my user name and password)

Code: [Select]
import urllib2, re, time, thread, traceback
from System.Collections.Generic import *
ATOM_URL='https://mail.google.com/mail/feed/atom'
gusr="daniel.gaitan.carrillo"
gpwd="********"#Disclaimer: Anyone who reads this python file can see this.

class mailChecker:

    def __init__(self, uName,pwd):
        self.username = uName
        self.password = pwd
        self.fullCount = "0"#I don't use message count as a condition in this script, but one could
        self.msgID = "dummy"
        self.timestamp = round(time.clock())
        vc.log("gmail_notifier.py - mailChecker initialized")     
           
    def get_feed(self,user, passwd):
        auth_handler = urllib2.HTTPBasicAuthHandler()
        auth_handler.add_password(realm='mail.google.com',uri='https://mail.google.com',user='{user}@gmail.com'.format(user=user),passwd=passwd)
        opener = urllib2.build_opener(auth_handler)
        urllib2.install_opener(opener)
        feed = urllib2.urlopen(ATOM_URL)
        message_text=feed.read()
       
        try:
            message_text=message_text.decode('utf-8')#try to deal with most non-Latin characters
           
        except:
            pass
       
        return message_text
               
    def readMail(self):
        timeNow = round(time.clock())
        feedData=self.get_feed(self.username, self.password)
        matchObj = re.search( r"fullcount>(\d*)<.*?title>(.*?)<.*?<summary>(.*?)</summary>.*?message_id=(.*?)&amp.*?email>(.*?)<", feedData, re.I)
       
        if matchObj:#if the match object was successfully created, then store matches as variables
       
            if self.msgID == "dummy" and timeNow-self.timestamp<10:
                self.msgID = matchObj.group(4)
                vc.log("GmailStartup.py - setting msgID to existing unread msg on 1st launch")
       
            elif matchObj.group(4)==self.msgID:
                pass#vc.log("GmailStartup.py - no new messages")
       
               
            else:   
                self.fullCount = matchObj.group(1)
                subject = matchObj.group(2)
                summary = matchObj.group(3)
                self.msgID = matchObj.group(4)
                sender = matchObj.group(5)
               
                if subject.lower()=="vc".lower():
                    vc.triggerEvent("newMsgVC", List[str]([subject,summary]))
                    vc.log("GmailStartup.py - condition matched, triggering newMsg event") 
                   
                else:
                    vc.log("No match. Message was: "+subject+"from "+sender)
                                   
        #else: -->not needed except if you're debugging/problem-hunting
            #vc.log("GmailStartup.py - no unread messages")
       
def checkMsg(delay):   

    while 1:
        try:
            myMailChecker.readMail()
            time.sleep(delay)
       
        except:
            error = traceback.format_exc().splitlines()
            vc.log("%s"%error[-1])
           
           

myMailChecker = mailChecker(gusr,gpwd)
thread.start_new_thread(checkMsg, (30,))# checks mail every 30 seconds. Change to your preference.





--- the only thing i made was to change the name of the file to "GmailStartup.py"

35
I am sorry, but i don't find a way to attach the XML other than copy-paste
in the body of the post

36
Thanks, here is the code :

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.7-->
<commandGroup open="True" name="Gmail notifier alert" enabled="False" prefix="" priority="0" requiredProcess="" description="">
  <command id="272" name="Alert received" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Alert received.</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.AddText</cmdType>
      <params>
        <param>Subject: {1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="True">
      <ifType>(A)==(B)</ifType>
      <ifParams>{2}&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Subject. {1} . Message. {2}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>OSD.AddText</cmdType>
          <params>
            <param>Message: {2}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <event>newMsgVC</event>
  </command>
  <command id="358" name="Gmail Startup" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <params>
        <param>PY\GmailStartup.py</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
</commandGroup>

37
Thank you James for the explanation, it was very informative also.

Is there a maximum number of if - then that can be used ?

I installed the .py and xml from the first post.. Gmail notifier
Everything works well, except that after 10 minutes or so
VC crashed and Windows close it, and ask me for find an online solution

I know is this script, because I disable that group an VC
Worked fine

VC Ver 2209
Problem in both version of Windows 7 and 10

Any help ?

Thanks

38
Thank you PegLegTV,

I will check it in detail, the first question that comes to my mind:

Where or how are you checking that {1} payload is empty or not ?

thanks again for your help, it is not what i have in mind (switch-case) but it could work for my needs


39
Hi Nime5ter,

One question: (i am a very new to VC)
i checked your XML from the first post, and the action (show text) is triggered IF the
message {2} is NOT empty.
so far so good :)

is there is a way to nest IF-THEN logic ?
e.g.
if {2} is NOT empty

  if {2} = "Hello, message 1"
    osd.showtext "this is message 1"
  endif

  if {2} = "Hello, message 2"
    osd.showtext "and this is message 2"
  endif

endif

in this way, you do the comparison only AND only if {2} is NOT empty
this is only a example, but i can implement it in another projects

the best could be have a switch-case instructions, but i dont know if VC have it

thank you very much

40
Arduino support / Re: Arduino Plugin
« on: December 24, 2015, 01:28:06 PM »
Thank you, yes, i was talking about the event icon

41
Arduino support / Re: Arduino Plugin
« on: December 24, 2015, 01:06:54 PM »
Yes Kalle, thats my last pm,

I will keep in touch with you

This question is probably out of this forum, but just for my information:
what is the difference between a event with number 9 and event with number 3 ?

thank you

42
Arduino support / Re: Arduino Plugin
« on: December 24, 2015, 12:36:10 PM »
Hi again Kalle,

Can you check your inbox ? i already sent you a pm

My main goal is to have the most plug-n-play system, because after what i did with
the harmony remote, and what i am going to do with mysensor, my friends are going
to ask me to install something like mine in their homes, and my rule is:
"the easiest and simplest, the better"

thank you for your support, kalle and james

43
Arduino support / Re: Arduino Plugin
« on: December 24, 2015, 12:20:29 PM »
Thanks James & Kalle

I think i finally doing some progress, i did some test with vc.triggerevent
i can now fire one event based in other command

i will probably post the XML for the buttons in a few days (hours).

have all of you a happy holidays

44
Arduino support / Re: Arduino Plugin
« on: December 24, 2015, 11:24:18 AM »
Yes, the XML that goes into the command tree, with the instructions for, lest say:

osd.showtext "button one has been pressed"

osd.showtext "button two has been pressed"

I will pm you with my info

thank you

45
Arduino support / Re: Arduino Plugin
« on: December 24, 2015, 10:59:50 AM »
I forgot to ask you... when is the mysensors-gateway will be ready for purchase?

thanks again

Pages: 1 2 [3] 4