Page 1 of 1

Interprete HTTP Server answer

Posted: 30 Oct 2018, 18:19
by Wiki
Pre-ESPEasy I have built a time switch for my old house heating using an ESP32, manageable using a Webinterface. I would like to extend the webinterface with a few lines of code to respond to a resquest of ESPEasy concerning the status of the relay.

Question: is it possible to use the sendtohttp command for interpreting the answer of the server? Means: from ESPEasy I send somewhat like "http://xxx.xxx.xxx.xxx/S" to get an answer however formatted to trigger an event.

Re: Interprete HTTP Server answer

Posted: 30 Oct 2018, 18:28
by grovkillen
Using rules and custom events and you can have the unit respond to any incoming commands.

Re: Interprete HTTP Server answer

Posted: 30 Oct 2018, 23:03
by Wiki
So, if I fire out of the rules of my ESPEasy device the request "http://xxx.xxx.xxx.xxx/S" the answer of my Webinterface of the timer "control?cmd=event,State=1" will be interpreted correctly by ESPEasy and fire an event named "State" within the ESPEasy? Or has the server to answer "/control?cmd=event,State=1"?

[edit]
Mark: the requesting device shall be the ESPEasy, the responding device shall be the webinterface of the timer towards the ESPEasy. And ESPEasy shall interprete the answer of the server and act using rules.
[/edit]

Re: Interprete HTTP Server answer

Posted: 30 Oct 2018, 23:14
by grovkillen
Yes that should be fine ;)

Re: Interprete HTTP Server answer

Posted: 30 Oct 2018, 23:21
by Wiki
Thank you for encouraging me, this is exactly the answer I was waiting for. I don't want to disassemble my house heating - not in end of october - for reprogramming my stable diy time switch ending in an endless circle of try and error.

I am using inside of my Arduino-routine the function "client.print(...)". Please, precise, do I have to print leading slash or no slash? Or doesn't matter?

Re: Interprete HTTP Server answer

Posted: 30 Oct 2018, 23:25
by grovkillen
I believe that you should use the leading front slash to get the unit interpret it since it'll be sent to the correct function that way

Re: Interprete HTTP Server answer

Posted: 31 Oct 2018, 01:16
by Wiki
Nope, it does nothing.

ESPEasy:

Code: Select all

on System#Boot do
  timerSet,1,10
endon

on Rules#Timer=1 do
  SendToHTTP 192.168.101.91,80,/S
  timerSet,1,10
endon
on HeizStatus do
// do whatever with %eventvalue%
endon 
Arduino diy Time Switch:

Code: Select all

    while (client.connected()) {            // loop while the client's connected
.
.
.
       else if (currentLine.endsWith("GET /S")) {
          int LevelCheck = digitalRead(RELAY_PIN);
              if (LevelCheck == HIGH){              
                client.print("/control?cmd=event,HeizStatus=1");
              }
              else{
                client.print("/control?cmd=event,HeizStatus=0");
              }
            client.println();
            // break out of the while loop:
            client.stop();
            break;
 .
 .
 .
    }
    client.stop();
 
Log ESPEasy:

Code: Select all

1413792: EVENT: Rules#Timer=1
1413876: ACT : SendToHTTP 192.168.101.91,80,/S
1413887: ACT : timerSet,1,10
1413940: Command: sendtohttp
1415003: Timeout while reading input data!
Serial log Time Switch (logging minimized info):

Code: Select all

New Client.
GET /S
I'm doing somethin wrong, but I don't know what and where. Time switch disassembled, heating off, house cold, I'm at my end. Pls help.

Re: Interprete HTTP Server answer

Posted: 31 Oct 2018, 06:16
by grovkillen
Send a HTTP requests upon the call but maybe wait a second before doing it?

Re: Interprete HTTP Server answer

Posted: 31 Oct 2018, 13:26
by Wiki
OK, a lot of try&error, still no success.

Rules ESPEasy:

Code: Select all

on System#Boot do
  timerSet,1,60
endon

on Rules#Timer=1 do
  SendToHTTP 192.168.101.91,80,/S
  timerSet,1,60
endon

on HeizStatus=1 do
  NEXTION,page0.r0.bco=65217
// do whatever with %eventvalue%
endon 

on HeizStatus=0 do
  NEXTION,page0.r0.bco=50712
  
endon
Code Time Switch Arduino:

Code: Select all

            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html;charset=UTF-8");
.
.
.
            client.println();
            int LevelCheck = digitalRead(RELAY_PIN);
            if (LevelCheck == HIGH){              
            client.print("/control?cmd=event,HeizStatus=1");
              }
              else{
                client.print("/control?cmd=event,HeizStatus=0");
              }
            client.println();
            break;
Log ESPEasy:

Code: Select all

1011795: EVENT: Rules#Timer=1
1011878: ACT  : SendToHTTP 192.168.101.91,80,/S
1011889: ACT  : timerSet,1,60
1011946: Command: sendtohttp
1012163: Command: timerset
Serial Log Time Switch at call from ESPEasy:

Code: Select all

New Client.
GET /S HTTP/1.1
Host: 192.168.101.91
User-Agent: ESP Easy/20102/Oct  8 2018 02:22:21
Connection: close
Serial Log Time Switch Entering the url "192.168.101.91/S" in Firefox:

Code: Select all

New Client.
GET /S HTTP/1.1
Host: 192.168.101.91
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Firefox shows:

Code: Select all

/control?cmd=event,HeizStatus=0 
The request of ESPEasy is received by the server.

The server responds with the correct string, Firefox is able to display it.

The serial log of the time switch tells me by "Connection: close" that the ESPEasy even is not further interested staying in connection. So its not possible to receive and interpret a server response because ESPEasy doesn't wait for an answer, isn't it?

Re: Interprete HTTP Server answer

Posted: 01 Nov 2018, 00:54
by Wiki
OK, meanwhile I am able to answer my question by myself.

No. The ESPEasy doesn't care about anything answered to its sendtohttp.

The only way I have figured out to get status information from a non-ESPEasy-device is to initiate a procedure on the server of sending its own http-request towards the ESPEasy as an answer. Not the smartest way, but works finally.

What a pity that I had to try out this way by following wrong informations.

Re: Interprete HTTP Server answer

Posted: 01 Nov 2018, 06:22
by grovkillen
Sorry for misunderstanding you and thus giving you wrong info. :?