Interprete HTTP Server answer

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Wiki
Normal user
Posts: 413
Joined: 23 Apr 2018, 17:55
Location: Germany

Interprete HTTP Server answer

#1 Post by Wiki » 30 Oct 2018, 18:19

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.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

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

Re: Interprete HTTP Server answer

#2 Post by grovkillen » 30 Oct 2018, 18:28

Using rules and custom events and you can have the unit respond to any incoming commands.
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:

Wiki
Normal user
Posts: 413
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Interprete HTTP Server answer

#3 Post by Wiki » 30 Oct 2018, 23:03

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]

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

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

Re: Interprete HTTP Server answer

#4 Post by grovkillen » 30 Oct 2018, 23:14

Yes that should be fine ;)
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:

Wiki
Normal user
Posts: 413
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Interprete HTTP Server answer

#5 Post by Wiki » 30 Oct 2018, 23:21

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?

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

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

Re: Interprete HTTP Server answer

#6 Post by grovkillen » 30 Oct 2018, 23:25

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
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:

Wiki
Normal user
Posts: 413
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Interprete HTTP Server answer

#7 Post by Wiki » 31 Oct 2018, 01:16

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.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

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

Re: Interprete HTTP Server answer

#8 Post by grovkillen » 31 Oct 2018, 06:16

Send a HTTP requests upon the call but maybe wait a second before doing it?
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:

Wiki
Normal user
Posts: 413
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Interprete HTTP Server answer

#9 Post by Wiki » 31 Oct 2018, 13:26

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?

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

Wiki
Normal user
Posts: 413
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Interprete HTTP Server answer

#10 Post by Wiki » 01 Nov 2018, 00:54

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.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

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

Re: Interprete HTTP Server answer

#11 Post by grovkillen » 01 Nov 2018, 06:22

Sorry for misunderstanding you and thus giving you wrong info. :?
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:

Post Reply

Who is online

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