Python Script Email sending issue

Started by jcsingle21, September 24, 2014, 10:01:18 PM

jcsingle21

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)

Felix

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

jcsingle21

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

jcsingle21

What is the
  • infront of message calling?  I am lost by that. I first thought it was calling the first character.

jcsingle21

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.

Felix

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.

jcsingle21

Sorry if I showed disrespect to your forum. I admit I am learning and this is my first project.

Felix

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.

jcsingle21

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
  • means. I tried changing it and testing as well. I never post unless I have just about given up on ideas.  What I have works but didn't aolve my mystery.

Felix

I have no idea what you're referring to. You pasted a newline and a dot. Can you explain in words?

jcsingle21

The brackets must have been a formatting tag.

if message[0] == '[' :


I am trying to figure out the use and purpose of
[0]

Felix

The square brackets are just part of array specific syntax, very common in most languages.