Python Forum
execute function at a certain time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
execute function at a certain time
#1
Hi guys
I'm new at Python and programming, so I found myself with difficulties at it.
As I wrote in the subject, I'm trying to run a function at a certain time. I don't think it can be that difficult but I just don't get it. It seems like "schedule" is the solution but I still couldn't make it.

I know that the code is wrong right now but everything I have tried to change ended in an Error.
At line 33 I have the function I want to execute at a certain time, after that I want it to move on to the next function.

Can you guys give me hint on how to do that?
Thanks a lot
StevenLewis



import Adafruit_DHT
import time
from rrb3 import *
import schedule

def test():

        humidity1, temperature1 = Adafruit_DHT.read_retry(Adafruit_DHT .AM2302, 4)
        humidity2, temperature2 = Adafruit_DHT.read_retry(Adafruit_DHT .AM2302, 18)

        print('Temp_innen={0:0.1f}*C  Humidity={1:0.1f}%'.format(temperature1, humidity1))
        print('Temp_aussen={0:0.1f}*C  Humidity={1:0.1f}%'.format(temperature2, humidity2))

        if temperature1 < 19 and temperature2 >21 or temperature1 >23 and temperature2 <21:
                motortemp()

        else:
                timewindow()


def motortemp():

        rr = RRB3(12, 6)

        rr.set_led1(0)
        rr.set_led2(0)

        rr.forward(2, 1)
        time.sleep(5)
        rr.reverse(2, 1)


def timewindow(t): # that part at a certain time

        rr = RRB3(12, 6)

        rr.set_led1(0)
        rr.set_led2(0)

        rr.forward(2, 1)
        time.sleep(5)
        rr.reverse(2, 1)

        print "I'm working...", t
        return

schedule.every().day.at("16:59").do(timewindow,'It is 16:59')

while True:
    schedule.run_pending()
    time.sleep(60) # wait one minute

while True:
        test()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  return next item each time a function is executed User3000 19 2,164 Aug-06-2023, 02:29 PM
Last Post: deanhystad
  time function does not work tester_V 4 2,946 Oct-17-2021, 05:48 PM
Last Post: tester_V
  Why recursive function consumes more of processing time than loops? M83Linux 9 4,128 May-20-2021, 01:52 PM
Last Post: DeaD_EyE
  Picking a function to execute palladium 1 1,575 Feb-09-2021, 04:47 PM
Last Post: deanhystad
  Can you end the Time.sleep function boier96 9 9,219 Jan-16-2021, 10:09 PM
Last Post: Serafim
  function call at defined system time? Holon 5 3,154 Oct-06-2020, 03:58 PM
Last Post: snippsat
  Having hard time understanding the function self-returning itself twice jagasrik 2 2,448 Aug-15-2020, 08:50 PM
Last Post: deanhystad
  Writing a function to calculate time range in Unix Epoch Time t4keheart 2 2,932 Jul-15-2020, 01:55 AM
Last Post: t4keheart
  How to assess elapsed time to execute a .exe file or opening a desktop application? Sudershan 2 2,095 Apr-18-2020, 01:40 PM
Last Post: buran
  How to execute code WHILE a function runs t4keheart 4 2,592 Jan-27-2020, 01:47 PM
Last Post: t4keheart

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020