Page 1 of 1

HTTP read GPIO input?

Posted: 11 Jan 2016, 06:08
by GMaster1
Heya,

I've spent quite a bit of time browsing this forum and everything online -- trying to solve the opposite of:

http://<ESP IP address>/control?cmd=GPIO,<pin>,0

It is pretty easy to SET via simple HTTP, but is there anything in place to GET/Read data from a pin?

My end goal (as one other person on this site posted back in November) is to read data from a ds18b20 or see the status of a GPIO (1/0)

This is all for an ESP 201 currently running the EasyESP firmware.

Thanks!

Re: HTTP read GPIO input?

Posted: 11 Jan 2016, 19:20
by Martinus
I'm experimenting with a simple json interface to retrieve data from the ESP sensors (actually from tasks).

Could become available with the next build and may look like this:

Code: Select all

{"Sensors":[
{
"TaskName": "PME",
"test": 3.30
},
{
"TaskName": "BMP Demo",
"Temperature": 20.06,
"Pressure": 981.87
},
{
"TaskName": "Lux sensor demo",
"Lux": 2.50
}
]}

Re: HTTP read GPIO input?

Posted: 11 Jan 2016, 20:21
by GMaster1
That would be amazing and thanks for the reply! Most little IoT things I've been working with thus far offers me at least some type of 'curl' simple output ability so I was absolutely in love with these 201 chips when I saw the HTTP commands but yeah the last piece to the puzzle is data the other direction via some JSON type utility.

I showed up late to the party regarding these chips but assume the EasyESP firmware is the best way to go as far as the most functionality without use of arduino/pi/etc?

Re: HTTP read GPIO input?

Posted: 01 Jun 2016, 12:37
by DA-Makes
I know I am late to the party, but I'm about to convert some sonoff's to run ESP Easy and this feature would be excellent to use. Did it ever get added and if so which version do I need?

Re: HTTP read GPIO input?

Posted: 06 Jun 2016, 12:02
by Tjeerd
Hello DA_Makers,

I have a sonoff and i have connected it trough the wifi whit domoticz
I can send form domoticz a "http://<ESP IP address>/control?cmd=GPIO,12,1" to switch the light on and a "http://<ESP IP address>/control?cmd=GPIO,12,0" to switch it off again.

so i think the function works.

I use version R78 on my sonoff's

Re: HTTP read GPIO input?

Posted: 06 Jun 2016, 12:10
by DA-Makes
Tjeerd wrote:Hello DA_Makers,

I have a sonoff and i have connected it trough the wifi whit domoticz
I can send form domoticz a "http://<ESP IP address>/control?cmd=GPIO,12,1" to switch the light on and a "http://<ESP IP address>/control?cmd=GPIO,12,0" to switch it off again.

so i think the function works.

I use version R78 on my sonoff's
Thanks - but are you able to read the status like the other post was suggesting with a GET request?

Re: HTTP read GPIO input?

Posted: 06 Jun 2016, 12:30
by Tjeerd
Well,

I see that in domoticz the lightbulb changes when im sending an on or off message (when sending the command not using domoticz).
So i think the sonoff is sending his state to Domoticz.

Futher i have attached a DHT22 tem/hum sensor to GPIO14 of the sonof and domoticz reads (get the data puched) the tempeture.

I dont know if this answers your question?

Re: HTTP read GPIO input?

Posted: 06 Jun 2016, 12:54
by DA-Makes
Tjeerd wrote:Well,

I see that in domoticz the lightbulb changes when im sending an on or off message (when sending the command not using domoticz).
So i think the sonoff is sending his state to Domoticz.

Futher i have attached a DHT22 tem/hum sensor to GPIO14 of the sonof and domoticz reads (get the data puched) the tempeture.

I dont know if this answers your question?

Hi. The question was around having a json interface to retrieve state so I don't think this interface is related.

Re: HTTP read GPIO input?

Posted: 07 Jun 2016, 14:00
by costo
DA-Makes wrote:I know I am late to the party, but I'm about to convert some sonoff's to run ESP Easy and this feature would be excellent to use. Did it ever get added and if so which version do I need?
I don't think there is a GET_command to read the state of an output but you can use events and rules (only available on R86 and higher) to synchronize the relais_state and the LED_state on the Sonoff with Domoticz.
Search the forum for [rules + relais] and you will find the way how to synchronize the sonoff with Domoticz.

It will be something like this:

Code: Select all

on switchon do
  gpio 12,1
  gpio 13,0
  inputswitchstate 0,1
endon

on switchoff do
  gpio 12,0
  gpio 13,1
  inputswitchstate 0,0
endon

on Switch1#Switch do
  if [Switch1#Switch]=1
    event switchon
  else
    event switchoff
  endif
endon
In ESPEasy the relais is called Switch1 on GPIO-0
In Domoticz the commands to control the sonoff relais are :
http://192.168.178.104/control?cmd=event,switchon
http://192.168.178.104/control?cmd=event,switchoff

Re: HTTP read GPIO input?

Posted: 07 Jun 2016, 15:15
by DA-Makes
costo wrote:
DA-Makes wrote:I know I am late to the party, but I'm about to convert some sonoff's to run ESP Easy and this feature would be excellent to use. Did it ever get added and if so which version do I need?
I don't think there is a GET_command to read the state of an output but you can use events and rules (only available on R86 and higher) to synchronize the relais_state and the LED_state on the Sonoff with Domoticz.
Search the forum for [rules + relais] and you will find the way how to synchronize the sonoff with Domoticz.

It will be something like this:

Code: Select all

on switchon do
  gpio 12,1
  gpio 13,0
  inputswitchstate 0,1
endon

on switchoff do
  gpio 12,0
  gpio 13,1
  inputswitchstate 0,0
endon

on Switch1#Switch do
  if [Switch1#Switch]=1
    event switchon
  else
    event switchoff
  endif
endon
In ESPEasy the relais is called Switch1 on GPIO-0
In Domoticz the commands to control the sonoff relais are :
http://192.168.178.104/control?cmd=event,switchon
http://192.168.178.104/control?cmd=event,switchoff

I don't have Domoticz (or want it) and was hoping that the suggestion from GMaster1 above had been added as direct JSON get requests would have been very useful.

Re: HTTP read GPIO input?

Posted: 07 Jun 2016, 15:29
by costo
It does not need to be Domoticz to control your sonoff relais.
As long as your controlling server can fire the command: "IPofYourESPEasy/control?cmd=event,switchon" or switchoff it will work

Re: HTTP read GPIO input?

Posted: 07 Jun 2016, 15:34
by DA-Makes
costo wrote:It does not need to be Domoticz to control your sonoff relais.
As long as your controlling server can fire the command: "IPofYourESPEasy/control?cmd=event,switchon" or switchoff it will work

I was looking for a way to query the sonoff for its current state as per the post from GMaster1 asking if he can make a JSON get request against the sonoff.

Re: HTTP read GPIO input?

Posted: 07 Jun 2016, 17:07
by costo
DA-Makes wrote: I was looking for a way to query the sonoff for its current state as per the post from GMaster1 asking if he can make a JSON get request against the sonoff.
To my knowledge, there is no command to read the state of an output in ESPEasy.

Re: HTTP read GPIO input?

Posted: 07 Jun 2016, 18:56
by dduley
costo wrote:
DA-Makes wrote: I was looking for a way to query the sonoff for its current state as per the post from GMaster1 asking if he can make a JSON get request against the sonoff.
To my knowledge, there is no command to read the state of an output in ESPEasy.
Sure there is!!

See: http://www.esp8266.nu/forum/viewtopic.php?f=4&t=1431


Regards

Dave

Re: HTTP read GPIO input?

Posted: 08 Jun 2016, 08:29
by DA-Makes
dduley wrote:
costo wrote:
DA-Makes wrote: I was looking for a way to query the sonoff for its current state as per the post from GMaster1 asking if he can make a JSON get request against the sonoff.
To my knowledge, there is no command to read the state of an output in ESPEasy.
Sure there is!!

See: http://www.esp8266.nu/forum/viewtopic.php?f=4&t=1431


Regards

Dave
Thanks but this isn't quite the same thing, I wanted to be able to check state from non ESP devices. The JSON get that was discussed at the beginning of this thread would have been perfect.