Read GPIO via HTTP
Moderators: grovkillen, Stuntteam, TD-er
Read GPIO via HTTP
There is a way to set GPIO like:
http://<ESP IP address>/control?cmd=PWM,<pin>,<level>
How to read state or PWM <level> of GPIO (to synchronize with application)?
http://<ESP IP address>/control?cmd=PWM,<pin>,<level>
How to read state or PWM <level> of GPIO (to synchronize with application)?
Re: Read GPIO via HTTP
you mean reading PWM from the GPIO-PIN into the ESP
(like on an arduino here, with programcode.ino: http://www.benripley.com/diy/arduino/th ... h-arduino/)
and than get this result via a HTTP-url-grab?
maybe it is _not_ (yet) in the ESPEasy firmware?
(like on an arduino here, with programcode.ino: http://www.benripley.com/diy/arduino/th ... h-arduino/)
and than get this result via a HTTP-url-grab?
maybe it is _not_ (yet) in the ESPEasy firmware?
Re: Read GPIO via HTTP
i cannot read source-code well, but partly whats possible to get with http-request is here to see in the plugin..
(a dimmer is mentioned, but....)
https://github.com/ESP8266nu/ESPEasy/bl ... /_C008.ino
(a dimmer is mentioned, but....)
https://github.com/ESP8266nu/ESPEasy/bl ... /_C008.ino
Re: Read GPIO via HTTP
Consider this scenario:
1. Client set PWM level by http://<ESP IP address>/control?cmd=PWM,<pin>,<level>
2. After reset client or other client want to initialize self state by request to ESPEasy: "Hi, what is your PWM level of GPIOx?", and ESPEasy should respond with info about level.
I just want to receive <level> form ESPEasy that previous was set by http://<ESP IP address>/control?cmd=PWM,<pin>,<level>
1. Client set PWM level by http://<ESP IP address>/control?cmd=PWM,<pin>,<level>
2. After reset client or other client want to initialize self state by request to ESPEasy: "Hi, what is your PWM level of GPIOx?", and ESPEasy should respond with info about level.
I just want to receive <level> form ESPEasy that previous was set by http://<ESP IP address>/control?cmd=PWM,<pin>,<level>
Re: Read GPIO via HTTP
You can't.rjackr wrote:There is a way to set GPIO like:
http://<ESP IP address>/control?cmd=PWM,<pin>,<level>
How to read state or PWM <level> of GPIO (to synchronize with application)?
PWM is a integer number which is sent to ESPEasy and transformed into a PWM signal on a certain pin.
I assume this number is stored somewhere in a hardware register inside the ESP. There is no support to read the content of this register.
On a Arduino it is not so difficult to access hardware registers of the ATMEL processor. In the ESP libraries there is no support for accessing the ESP8266 hardware directly so you have to keep track of registervalues somewhere in the program or application and resend it to synchronise.
Re: Read GPIO via HTTP
workaround...?
grab it from syslog?
one has to configure syslog/rsyslog. create a rule to store/send the http-"SET"-request or send it to the other ESP...
not really elegant...but..
or set/get it via MQTT....?
grab it from syslog?
one has to configure syslog/rsyslog. create a rule to store/send the http-"SET"-request or send it to the other ESP...
not really elegant...but..
or set/get it via MQTT....?
Re: Read GPIO via HTTP
I thought there is any simple way to do it.
It would be a good feature. Complete solution.
It would be a good feature. Complete solution.

Re: Read GPIO via HTTP
there is a "node-feature". i only saw it in the gui, maybe somtime it is used for this?
to have a "swarm"-esp#s ... whoooowwwww
i started a thread with a christmas-wishlist here, maybe a point to add ...
to have a "swarm"-esp#s ... whoooowwwww
i started a thread with a christmas-wishlist here, maybe a point to add ...

Re: Read GPIO via HTTP
This is modification I made to support command: http://<ESP IP address>/control?cmd=GETPWM,<pin>
I can't Attach file, and this is diff to _P001_Switch.ino file from BUILD 76
This can be added to GitHub.
I can't Attach file, and this is diff to _P001_Switch.ino file from BUILD 76
This can be added to GitHub.
Code: Select all
@@ -6,6 +6,9 @@
#define PLUGIN_ID_001 1
#define PLUGIN_NAME_001 "Switch input"
#define PLUGIN_VALUENAME1_001 "Switch"
+#define NO_GPIOS 17
+
+uint16_t pwm_level[17] = {0,};
boolean Plugin_001(byte function, struct EventStruct *event, String& string)
{
@@ -181,7 +184,7 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
if (tmpString.equalsIgnoreCase("GPIO"))
{
success = true;
- if (event->Par1 >= 0 && event->Par1 <= 16)
+ if (event->Par1 >= 0 && event->Par1 < NO_GPIOS)
{
pinMode(event->Par1, OUTPUT);
digitalWrite(event->Par1, event->Par2);
@@ -199,10 +202,14 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
if (tmpString.equalsIgnoreCase("PWM"))
{
success = true;
- if (event->Par1 >= 0 && event->Par1 <= 1023)
+ if (event->Par1 >= 0 && event->Par1 < NO_GPIOS && event->Par2 >= 0 && event->Par2 <= PWMRANGE)
{
pinMode(event->Par1, OUTPUT);
analogWrite(event->Par1, event->Par2);
+
+ if (event->Par1 < NO_GPIOS)
+ pwm_level[event->Par1] = event->Par2;
+
if (printToWeb)
{
printWebString += F("GPIO ");
@@ -212,12 +219,42 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
printWebString += F("<BR>");
}
}
+ else
+ {
+ printWebString += F("Set pin in [0..");
+ printWebString += NO_GPIOS-1;
+ printWebString += F("] and level in [0..");
+ printWebString += PWMRANGE;
+ printWebString += F("]");
+ }
+ }
+
+ if (tmpString.equalsIgnoreCase("GETPWM"))
+ {
+ success = true;
+ if (printToWeb)
+ {
+ if (event->Par1 >= 0 && event->Par1 < NO_GPIOS)
+ {
+ printWebString += F("GPIO ");
+ printWebString += event->Par1;
+ printWebString += F(" PWM level ");
+ printWebString += pwm_level[event->Par1];
+ }
+ else
+ {
+ printWebString += F("Set pin in [0..");
+ printWebString += NO_GPIOS-1;
+ printWebString += F("]");
+ }
+ printWebString += F("<BR>");
+ }
}
if (tmpString.equalsIgnoreCase("Pulse"))
{
success = true;
- if (event->Par1 >= 0 && event->Par1 <= 1023)
+ if (event->Par1 >= 0 && event->Par1 < NO_GPIOS)
{
pinMode(event->Par1, OUTPUT);
digitalWrite(event->Par1, event->Par2);
Re: Read GPIO via HTTP
It's quite an old topic but I found on this forum that there is a way to ask for the PWM level. Just use http://espeasy/control?cmd=status,gpio,
Who is online
Users browsing this forum: No registered users and 14 guests