Tips about dealing with scedule time, e.g light swith timer etc

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
MicroNinja
Posts: 16
Joined: Sun Dec 29, 2019 8:38 am

Tips about dealing with scedule time, e.g light swith timer etc

Post by MicroNinja » Thu Apr 09, 2020 4:42 pm

Hi!

I am working on a basic watering system. The plan is to control when to water and for how long with some sort of timer. For example "activate pump at time x for 15 seconds". Working with time in general is quite tricky so I am asking for advice.

I dont want the time schedule to be hard corded, I will implement MQTT to send commands to the wemos unit to set the time. The action will be repeated daily until it stops. Preferably I would like to dynamically set any number of timers. Say water for 20 seconds at 10.00 and 10 seconds 20.00 etc.. Same logic could be to turn on and off a light etc.

I want to keep it rather basic. My level is basic to intermediate in python. I have less experience with micro ]python and IOT in general.

Using RTC https://docs.micropython.org/en/latest/ ... ne.RTC.irq and
RTC.alarm(id, time, *, repeat=False)
If I understand correctly, to initialize RTC the easiest way would be to make a api call comewhere to get current time.

Is there any other good ways to make a timer to start events during a particular length of time?

MicroNinja
Posts: 16
Joined: Sun Dec 29, 2019 8:38 am

Re: Tips about dealing with scedule time, e.g light swith timer etc

Post by MicroNinja » Thu Apr 09, 2020 5:57 pm

Ok, so i did some testing using the syntax from the doc

RTC.irq(*, trigger, handler=None, wake=machine.IDLE)

However my code produce an error:

Code: Select all

rtc.irq(trigger=rtc.ALARM0, handler=turn_on_led_callback, wake=machine.DEEPSLEEP) 

Code: Select all

TypeError: extra keyword arguments given 
I am using a wemos 8266 but it only take 2 arguments? How come it does not accept a handler/callback keyword? I am totally confused

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Tips about dealing with scedule time, e.g light swith timer etc

Post by jimmo » Tue Apr 14, 2020 4:42 am

Unfortunately the ESP8266 doesn't support all of the functionality that some of the other ports do. The documentation needs some work here.

In the meantime, check out http://docs.micropython.org/en/latest/e ... sleep-mode for how to use the RTC to maybe achieve what you want. (i.e. you can only use the RTC to wake from sleep).

Otherwise you might be able to use a machine.Timer or even just a loop with time.sleep_ms().

Post Reply