LowPowerLab Forum

Hardware support => General topics => Topic started by: jcsingle21 on September 24, 2014, 10:01:18 PM

Title: Python Script Email sending issue
Post by: jcsingle21 on September 24, 2014, 10:01:18 PM
First off, I am new at this so this might be simple for you guys, but I can not for the life of me find my answers anywhere.

I have a motionmote I am trying to setup sms/email notification. My thing is I want a different message for each node when it transmits the serial print.  I have tried to reverse engineer a few scripts and its been problematic since the one script seems to look at only the first letter and that doesn't do me any good.

My Gateway is using the sample gateway sketch.

My motion mote is using the motion mote sketch, and I receive the notification:
[18] MOTION   [RX_RSSI:-29] - ACK sent.

Here is the bottom part of my sms/email notification script that works:

while True:
    message = ser.readline()
    print(message)
    if message[0] == '[' :
        send_email()
    time.sleep(0.5)
Title: Re: Python Script Email sending issue
Post by: Felix on September 24, 2014, 10:54:13 PM
So, are you just trying to see if the word "MOTION" is in the line coming from serial:
If so you can use:

if "blah" not in somestring:
   sendemail()


If you want to split the message you could use the split() method as shown here: http://www.tutorialspoint.com/python/string_split.htm
Title: Re: Python Script Email sending issue
Post by: jcsingle21 on September 24, 2014, 11:01:39 PM
I would really like to use the node number since I plan to have more than one and each having it's own message per location
Title: Re: Python Script Email sending issue
Post by: jcsingle21 on September 25, 2014, 08:02:47 AM
What is the
Title: Re: Python Script Email sending issue
Post by: jcsingle21 on September 25, 2014, 09:16:00 AM
I changed

if message[0] == '[' :

to

if "[18] MOTION" in message :

And it worked, I hope with future nodes I can use the same example and just change the node number.  I only have two at the moment to test.
Title: Re: Python Script Email sending issue
Post by: Felix on September 25, 2014, 11:55:49 AM
Ok I think you just need to read a bit on python string handling, python is one of the easiest and most flexible languages to learn and use. Not sure if this is the best forum to ask or search for that, since it's mostly designed for supporting Moteino hardware and related firmware.
Title: Re: Python Script Email sending issue
Post by: jcsingle21 on September 25, 2014, 12:07:28 PM
Sorry if I showed disrespect to your forum. I admit I am learning and this is my first project.
Title: Re: Python Script Email sending issue
Post by: Felix on September 25, 2014, 01:20:53 PM
It's not a problem at all, just saying that python is very much documented on the web and you'll find a lot of resources and examples simply by searching for what you'd like to do. Like how to extract your number from the message, splitting strings and string processing.
Title: Re: Python Script Email sending issue
Post by: jcsingle21 on September 25, 2014, 01:23:49 PM
I was googling all day yesterday before I decided to post. I just wasn't getting my answer. I still haven't found the answer the what the
Title: Re: Python Script Email sending issue
Post by: Felix on September 25, 2014, 01:30:02 PM
I have no idea what you're referring to. You pasted a newline and a dot. Can you explain in words?
Title: Re: Python Script Email sending issue
Post by: jcsingle21 on September 25, 2014, 01:32:57 PM
The brackets must have been a formatting tag.

if message[0] == '[' :

I am trying to figure out the use and purpose of
[0]
Title: Re: Python Script Email sending issue
Post by: Felix on September 25, 2014, 03:50:06 PM
The square brackets are just part of array specific syntax, very common in most languages.