Page 1 of 1

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

Posted: 27 May 2018, 19:23
by boolie
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

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

Posted: 27 May 2018, 19:36
by grovkillen
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.

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

Posted: 27 May 2018, 21:35
by boolie
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.

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

Posted: 27 May 2018, 22:39
by grovkillen
Sorry, I will look through the code tomorrow. I might have misunderstood.