Timer problem a- and how to flash a GPIO LED easily

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
boolie
Normal user
Posts: 20
Joined: 23 May 2018, 21:35

Timer problem a- and how to flash a GPIO LED easily

#1 Post by boolie » 27 May 2018, 19:23

Hi All,

I've a problem with a timer not working. I think the code is ok, but maybe I've looked at it for too long now and I'm missing something really silly! I've simplified it down to a very minimal piece of code, which still doesn't work, and I've tried it on two different ESP boards.

I can't work out what's wrong here... can anyone help?

Code: Select all

On timerstart do
	timerSet,1,2
        TaskValueSet,12,1,0
endon

On timerstop do
	timerSet,1,0
endon

On Rules#Timer = 1 do
  if [MyVars#ctr] = 0
        gpio,4,1
        TaskValueSet,12,1,1
  else
        gpio,4,0
        TaskValueSet,12,1,0
  endif
  timerSet,1,2
endon
The dummy device "MyVars" is defined thus:
Type: Generic - dummy device
Name: MyVars
Enabled: [tick]
Interval: 60
Simulate: SENSOR_TYPE_SINGLE
Values:
#1 ctr 0 decimals
#2-#4 names empty, 2 decimals

I expect that code to turn the LED alternately on and off every 2 seconds. But the LED remains stubbornly off! A quick "gpio,4,1" turns it on just fine.
I've tried changing the GPIO: GPIO2 (D4), GPIO14 (D5) and GPIO4 (D2), none works.

ESP image is ESP_Easy_mega-20180519_test_ESP8266_4096.

Also - is there a smart way to set a GPIO-connected LED to flash at a given frequency, rather than using timers? I was hoping that the PWM commands might provide something, but they seem only intended to control brightness.

Thanks!

Jeff
Various D1 & Sonoffs with ESPEasy, some Tasmota. Domoticz, Z-wave.
ESPEasy Patreon - keep up the good stuff, guys!

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Timer problem a- and how to flash a GPIO LED easily

#2 Post by grovkillen » 27 May 2018, 19:36

You haven't studied the wiki right? I don't see you declaring events called "timerstart" and "timerstop". You should use "Rules#Timer=N" where N is your timer number.

But please study the wiki.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

boolie
Normal user
Posts: 20
Joined: 23 May 2018, 21:35

Re: Timer problem a- and how to flash a GPIO LED easily

#3 Post by boolie » 27 May 2018, 21:35

Grovkillen, I have studied the wiki! I've read the entire rules tutorial from top to bottom several times and looked at the examples. I wouldn't be asking here if I hadn't. I'm asking because I can't see anything wrong and I've used similar syntax in other cases, where it works; this case has me puzzled.

Please be clear; what do you mean by "declaring" events? I don't see any syntax in the rules wiki for declaring an event. The examples just code "on <eventname> do" and then trigger the event from http, the tools page, or "event <eventname>" in other code. The event values example, the repeating timers example have the same basic structure as my code. There's no express declaration of anything.
In this case, I'm triggering the events from the tools page for the purposes of testing. I have code on other ESPs that does exactly this and it works fine; I write "on <eventname>" and then trigger it from http or send "event,<eventname>" from the tools -> the code runs.

Not clear what you mean in saying that I should use "Rules#timer = N" either - look at my code: you'll see the main block starts with "On Rules#Timer = 1 do".

So, please could you be a bit more specific? What is missing from my code, if anything?

Thanks for your help!


ps - an update: I checked the log too. When I trigger the event (from tools... event,timerstart), the log shortly shows Rules#Timer being triggered, but only once. Then all is quiet again.
Various D1 & Sonoffs with ESPEasy, some Tasmota. Domoticz, Z-wave.
ESPEasy Patreon - keep up the good stuff, guys!

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Timer problem a- and how to flash a GPIO LED easily

#4 Post by grovkillen » 27 May 2018, 22:39

Sorry, I will look through the code tomorrow. I might have misunderstood.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Post Reply

Who is online

Users browsing this forum: No registered users and 42 guests