GPIO mode: input or output?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

GPIO mode: input or output?

#1 Post by bonti69 » 14 May 2021, 14:18

Today I tried to assign a GPIO as a switch. My intention was to be an output switch.Defined a new task, gpio15 as "switch", "normal switch". After that tried the toggle command via http. Response: "Failed" in browser. In log we have:
58221346: HTTP: GPIOtoggle,15
58221347: HTTP after parseTemplate: GPIOtoggle,15
58221349: Command: GPIOtoggle
58221350: GPIOtoggle,15
58221351: Par1: 15 Par2: 0 Par3: 0 Par4: 0 Par5: 0
58221352: GPIO : port#15 is not an output port
gpio toggle.png
gpio toggle.png (33.68 KiB) Viewed 7742 times
Strange...
Tried with http commands:
http://192.168.4.32/control?cmd=GPIO,15,0
http://192.168.4.32/control?cmd=GPIO,15,1
Response OK:
gpio toggle 0.png
gpio toggle 0.png (6.41 KiB) Viewed 7742 times
After that device responds normally on gpiotoggle command:
gpio toggle 1.png
gpio toggle 1.png (66.8 KiB) Viewed 7738 times
FEATURE REQUEST
One more proof to REDEFINE the switch plugin. As INPUT PORT or as OUTPUT PORT.

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

Re: GPIO mode: input or output?

#2 Post by TD-er » 14 May 2021, 14:31

For toggling using the "GPIO" command, you don't need to assign a switch plugin on that GPIO pin to a task.
Roughly a year ago, the "GPIO" commands have been moved to be internal commands of ESPEasy, meaning you don't need to have a task configured for it.

This also means the "switch" plugin can put the pin into "input" mode, which explains your error message.
So my advice is to disable (or remove) that task using GPIO-15 and just use the GPIO commands.
This command can be sent via rules, HTTP or MQTT. (not exclusive OR :) )

Not sure if the mode is reset to the default if you disable the switch task, so maybe reboot just to make sure.
You can also switch the mode using the GPIO command.
The state of "2" is setting it to be an input, so setting it to 0 or 1 is setting it to be an output.

See: https://espeasy.readthedocs.io/en/lates ... ernal-gpio

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: GPIO mode: input or output?

#3 Post by bonti69 » 14 May 2021, 17:00

Thank you, TD-er
I'm hardware orientated, so it's somehow difficult for me to understand. For my point of view, input and outputs are totally different things.The behaviour of a certain pin should be well defined at boot.If it's an input ,then CPU will monitor the logicall level of that pin, the internal output driver should be disabled,or High-Z. If is an output, then the the pin will be driven by internal driver of that pin.[strong pull up/down, push-pull...]
G1kYN.jpg
G1kYN.jpg (74.45 KiB) Viewed 7730 times
STM32 GPIO.png
STM32 GPIO.png (166 KiB) Viewed 7730 times
You say: "the "switch" plugin can put the pin into "input" mode" "For toggling using the "GPIO" command, you don't need to assign a switch plugin on that GPIO pin to a task.". But I need the "output#state" of that gpio for further mqtt use in a specific format."The state of "2" is setting it to be an input, so setting it to 0 or 1 is setting it to be an output."
I think things should be more clear.
When a gpio is assigned as switch input, then the internal driver(output transistors) should be in high-Z, state2 ,as long the task is enabled, and the pin act as an input, internal logic levels follows the voltage applied on that pin (that scenario also involves pullup/pulldown resistors- weak pull up/down)...
When a gpio is assigned as output,then the output transistors can generate or absorb current,push-pull, they follow the logic levels of internal buffer,register.
So,I think a two plugin should be on a gpio: SWITCH INPUT and SWITCH OUTPUT( Relay = output 0 or 1, or Dimmer = output pwm ). SWITCH INPUT disable GPIO,<GPIO>,<state>;GPIOtoggle,<GPIO>;LongPulse,<GPIO>,<state>,<duration> etc...enables Status,G,<GPIO>.
Moreover, when a task is Relay, automatically appear in webgui the toggle button with state,[enable GPIO,<GPIO>,<state>;GPIOtoggle,<GPIO>;LongPulse,<GPIO>,<state>,<duration> etc.] when a task is Dimmer, automatically appear in webgui the toggle button with slider for pwm [enable PWM,<GPIO>,<duty> / PWM,<GPIO>,<duty>,<duration> /PWM,<GPIO>,<duty>,<duration>,<frequency>.]
That's a feature request...
Last edited by bonti69 on 14 May 2021, 23:13, edited 1 time in total.

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

Re: GPIO mode: input or output?

#4 Post by TD-er » 14 May 2021, 21:54

Oh don't get me wrong, I totally agree that the current switch plugin has grown into a way too complex piece of code, trying to "do it all" (and fail), which makes it impossible to grasp all side-effects and thus also to maintain.

I am totally in favour of splitting the functionalities of the switch plugin into at least 2 new plugins (or a plugin with very specific state) which make it clear what they should do.
Something as basic as handling a GPIO pin is perfectly obfuscated by the current switch plugin and that's a big frustration for me for quite some time.

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: GPIO mode: input or output?

#5 Post by bonti69 » 14 May 2021, 22:56

How about this way?
Screenshot_2021-05-14 PSF A85 - Configure Module.png
Screenshot_2021-05-14 PSF A85 - Configure Module.png (41.46 KiB) Viewed 7714 times
Screenshot_2021-05-14 PSF A85 - Main Menu.png
Screenshot_2021-05-14 PSF A85 - Main Menu.png (31.07 KiB) Viewed 7713 times

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: GPIO mode: input or output?

#6 Post by bonti69 » 16 May 2021, 09:09

@TD-er
In Log we have instead of current time of the device those numbers, incremental. How can be those numbers converted in current time, some Hh:mm:ss. Will be more useful for forensic analysis...
Something like that:
log.png
log.png (49.26 KiB) Viewed 7682 times
log.png
log.png (47.14 KiB) Viewed 7681 times

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

Re: GPIO mode: input or output?

#7 Post by TD-er » 16 May 2021, 20:05

You can't.
The numbers are the uptime in msec.
And since the internal clock of the ESP isn't that accurate, you might see some jumps when NTP updates the time.
Also at boot you don't have the system time and it is rather confusing to switch to a different notation when running.
You could also send it to a syslog server, those will append the timestamp when the item was received by the syslog server.

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests