Interprete HTTP Server answer
Moderators: grovkillen, Stuntteam, TD-er
Interprete HTTP Server answer
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.
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:~ $
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Interprete HTTP Server answer
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
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: Interprete HTTP Server answer
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]
[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:~ $
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Interprete HTTP Server answer
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
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: Interprete HTTP Server answer
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?
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:~ $
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Interprete HTTP Server answer
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
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: Interprete HTTP Server answer
Nope, it does nothing.
ESPEasy:
Arduino diy Time Switch:
Log ESPEasy:
Serial log Time Switch (logging minimized info):
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.
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
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();
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!
Code: Select all
New Client.
GET /S
Code: Select all
pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Interprete HTTP Server answer
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
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: Interprete HTTP Server answer
OK, a lot of try&error, still no success.
Rules ESPEasy:
Code Time Switch Arduino:
Log ESPEasy:
Serial Log Time Switch at call from ESPEasy:
Serial Log Time Switch Entering the url "192.168.101.91/S" in Firefox:
Firefox shows:
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?
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: 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;
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
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
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
Code: Select all
/control?cmd=event,HeizStatus=0
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:~ $
Re: Interprete HTTP Server answer
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.
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:~ $
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Interprete HTTP Server answer
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
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 133 guests