Get PWM value in any way

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
darkchris90
New user
Posts: 6
Joined: 27 Aug 2019, 19:24

Get PWM value in any way

#1 Post by darkchris90 » 27 Aug 2019, 19:30

Hi,

is it possible to get the current PWM status in the version 20190817? I need it for fhem. In some early versions it was in the state variable but now there is only 0,1,-1 and sometimes -2.

Where can I change the source code to get the value? I changed the code on my own and tried to modify the globalMapPortStatus directly or with the function savePortStatus. I prepared a struct which has the PWM value in the state and the output variable, but it doesnt work. I also changed the type of state to uint16_t like in the older versions.

Thanks

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

Re: Get PWM value in any way

#2 Post by grovkillen » 27 Aug 2019, 20:00

I use a custom event and send the wanted value, which I store as in internal variable as well as setting the pwm.

So conclusion, you cannot get the value any other way currently.
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:

darkchris90
New user
Posts: 6
Joined: 27 Aug 2019, 19:24

Re: Get PWM value in any way

#3 Post by darkchris90 » 27 Aug 2019, 20:43

Good evening,

thank you for the fast answering. Can you explain the custom event and how to use it?

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

Re: Get PWM value in any way

#4 Post by grovkillen » 28 Aug 2019, 07:34

Using rules you create an event using the event command.

https://espeasy.readthedocs.io/en/lates ... Rules.html
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:

darkchris90
New user
Posts: 6
Joined: 27 Aug 2019, 19:24

Re: Get PWM value in any way

#5 Post by darkchris90 » 28 Aug 2019, 20:55

Ah ok, I thought you talked about something in the code, because of the internal variable. I will try it. Thank you!

Cdzn
Normal user
Posts: 58
Joined: 06 Oct 2020, 18:15

Re: Get PWM value in any way

#6 Post by Cdzn » 05 Sep 2023, 17:42

How to store adn read PWM to/from Dummy values?
I read this but can`t understand syntax. What exactly used here and what not
For any plugin that registers the used pin(s), the last set pin state can be retrieved, either regular pin state or PWM state, by using this syntax: [Plugin#<pluginId>#Pinstate#N]
Also where i can find plugin and pluginid?

TD-er
Core team member
Posts: 8729
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Get PWM value in any way

#7 Post by TD-er » 05 Sep 2023, 18:05

See the documentation on referring to the pinstate of a specific pin:
https://espeasy.readthedocs.io/en/lates ... task-names

And some example here: https://espeasy.readthedocs.io/en/lates ... tem-events
You need to scroll to the "Matching events" section as the example is at the end of the section above it.

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Get PWM value in any way

#8 Post by chromo23 » 05 Sep 2023, 18:08

Cdzn wrote: 05 Sep 2023, 17:42 How to store adn read PWM to/from Dummy values?

To put a value in a dummy device use taskvalueset:
https://espeasy.readthedocs.io/en/lates ... skvalueset

The pwm value you would get with:

Code: Select all

[Plugin#GPIO#Pinstate#12]
...assuming your GPIO is 12
As also discussed here: viewtopic.php?t=9801

So to write to a dummy device simply use:

Code: Select all

TaskValueSet,<name_of_dummy_device,<value_name>,[Plugin#GPIO#Pinstate#12]
To read the value use:

Code: Select all

[<name_of_dummy_device>#<value_name>]
e.g.:

Code: Select all

 LogEntry,'[MyDummy#MyValue]'

Cdzn
Normal user
Posts: 58
Joined: 06 Oct 2020, 18:15

Re: Get PWM value in any way

#9 Post by Cdzn » 05 Sep 2023, 18:19

This is what i can`t understand) I though should use "status,g,5" in command line or something! Thanks a lot. I have PWM fan and wanted to store and restore the last duty.

Cdzn
Normal user
Posts: 58
Joined: 06 Oct 2020, 18:15

Re: Get PWM value in any way

#10 Post by Cdzn » 07 Sep 2023, 05:00

Stil can`t get success.
I wrote 3 rules
1st for restore the last PWM value:

Code: Select all

on System#Boot do
  PWM,5,[TestMemory#Dummy]
endon
2nd for triggering pwm:

Code: Select all

on pwm do
  PWM,5,%eventvalue1%
  //Publish %sysname%/GPIO/GPIO5,[Plugin#GPIO#Pinstate#5]
endon
3rd when the PWM changing duty this should store in memory last value:

Code: Select all

on pwm#state do
  TaskValueSet,TestMemory,Dummy,[Plugin#GPIO#Pinstate#5]
endon
When i push the button with this code

Code: Select all

http://192.168.0.123/control?cmd=event,PWM=1023
fan start spining at max speed and should store this value in Dummy device, but it`s empty.
Image.jpg
Image.jpg (22.53 KiB) Viewed 2554 times

Cdzn
Normal user
Posts: 58
Joined: 06 Oct 2020, 18:15

Re: Get PWM value in any way

#11 Post by Cdzn » 07 Sep 2023, 05:50

I guess this is not working because the PWM#State is still 0 and did`t change value when u call it via http. This is why taskvalueset wont work. I could see changes in logs but i dunno.

Micha_he
Normal user
Posts: 372
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Get PWM value in any way

#12 Post by Micha_he » 07 Sep 2023, 06:30

Maybe, because evantname and command are the same !?

TD-er
Core team member
Posts: 8729
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Get PWM value in any way

#13 Post by TD-er » 07 Sep 2023, 08:31

When in doubt whether events are handled and if so with which eventvalues, you can always use "logEntry" to create logs.

Code: Select all

on pwm do
  PWM,5,%eventvalue1%
  //Publish %sysname%/GPIO/GPIO5,[Plugin#GPIO#Pinstate#5]
  logentry,"On pwm Do: EventValue: %eventvalue1% PinState: [Plugin#GPIO#Pinstate#5]"
endon
And please note that rules parsing ends when a matching event is found.
So if "on pwm do" is before "on pwm#state do", the latter one may not be processed. (not 100% sure this is the correct example, but you get the idea)

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Get PWM value in any way

#14 Post by chromo23 » 07 Sep 2023, 09:12

Cdzn wrote: 07 Sep 2023, 05:00 2nd for triggering pwm:
...
3rd when the PWM changing duty this should store in memory last value:
...
Why not combining these two?

Like:

Code: Select all

On pwm Do
  PWM,5,%eventvalue1%
  TaskValueSet,TestMemory,Dummy,%eventvalue1%
  //Publish %sysname%/GPIO/GPIO5,%eventvalue1%
Endon
Last edited by chromo23 on 07 Sep 2023, 09:35, edited 1 time in total.

Cdzn
Normal user
Posts: 58
Joined: 06 Oct 2020, 18:15

Re: Get PWM value in any way

#15 Post by Cdzn » 07 Sep 2023, 09:16

Micha_he wrote: 07 Sep 2023, 06:30 Maybe, because evantname and command are the same !?
Nope, coz this only rule is working fine, except others. command successfully executed when i send the duty cycle. But it wont save value in dummy

Cdzn
Normal user
Posts: 58
Joined: 06 Oct 2020, 18:15

Re: Get PWM value in any way

#16 Post by Cdzn » 07 Sep 2023, 10:00

chromo23 wrote: 07 Sep 2023, 09:12
Cdzn wrote: 07 Sep 2023, 05:00 2nd for triggering pwm:
...
3rd when the PWM changing duty this should store in memory last value:
...
Why not combining these two?

Like:

Code: Select all

On pwm Do
  PWM,5,%eventvalue1%
  TaskValueSet,TestMemory,Dummy,%eventvalue1%
  //Publish %sysname%/GPIO/GPIO5,%eventvalue1%
Endon
it`s working. YAASS))
Td-er was right, i guess there problem was in sequence.
Thank You all for help!
Attachments
Image.jpg
Image.jpg (16.73 KiB) Viewed 2506 times

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 17 guests