Python timer in if else statement -


i'm trying create timer starts when condition if statement met , stops , returns duration when elif condition met, possible?

the purpose of application send true or false value aws iot android application. python script subscribed aws , receives value , uses determine whether led should on or off.

the code have:

from awsiotpythonsdk.mqttlib import awsiotmqttclient import rpi.gpio gpio import sys import logging import time time import sleep timeit import default_timer timer import getopt import grovepi  msgpay = none  # custom mqtt message callback def customcallback(client, userdata, message):     print("received new message: ")     print(message.payload)     print("from topic: ")     print(message.topic)     print("--------------\n\n")     global msgpay     msgpay = message.payload    led = 5    grovepi.pinmode(led, "output")    start_time = timer()    if msgpay == "true":        print("turning on")        grovepi.digitalwrite(led, 1)        #time.sleep(3)    elif msgpay == "false":        print("turning off")        grovepi.digitalwrite(led, 0)        duration = timer() - start_time        print duration 

any how go appreciated.

thanks


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -