Page 1 of 1

SendToHTTP to its own environment does not work

Posted: 26 Sep 2022, 10:47
by joost d
It looks like that the SendToHTTP -in Rules- does not work for hiss own ESPeasy-environment .

To test this isseu, I used the commands:

SendToHTTP 192.168.2.10,80,/control?cmd=pcd8544cmd,backlight,1
SendToHTTP 192.168.2.10,80,/control?cmd=GPIO,12,1

192.168.2.10 is the ip of the environment of the Rules.

Result in the log is:
1075861: ACT : SendToHTTP 192.168.2.10,80,/control?cmd=pcd8544cmd,backlight,1
1080868: HTTP : SendToHTTP 192.168.2.10 GET... failed HTTP code: -1 connection refused
1080872: ACT : SendToHTTP 192.168.2.10,80,/control?cmd=GPIO,12,1
1085879: HTTP : SendToHTTP 192.168.2.10 GET... failed HTTP code: -1 connection refused

If i use the ip of another ESPeasy then the SendToHTTP command works correct and the result in the log is :

902971: ACT : SendToHTTP 192.168.2.7,80,/control?cmd=pcd8544cmd,backlight,1
903016: HTTP : SendToHTTP 192.168.2.7 GET... HTTP code: 200
903026: ACT : SendToHTTP 192.168.2.7,80,/control?cmd=GPIO,12,1
903080: HTTP : SendToHTTP 192.168.2.7 GET... HTTP code: 200
903092: EVENT: http#192.168.2.7=200
903106: EVENT: http#192.168.2.7=200

A bug......?!

Re: SendToHTTP to its own environment does not work

Posted: 26 Sep 2022, 11:04
by TD-er
Not sure if this can be considered a bug...
Problem is, we're running this all single threaded.
So when handling a call to a SendToHTTP command, we're not handling the actual request via the web server and vice verse.

Also I don't really see the purpose for this as these commands can all be run from within the rules anyway, so why add such a rather extreme overhead?

The only thing I can think of how this might be working is when the sendtohttp command is made aware of whether it is calling itself. But that's probably a lot of work to then hook into the webserver and fetching the result etc.
And what to do with other commands like sendto which is used to send data to other nodes via the p2p layer?

So in short, no I don't think this should be considered a bug.

Re: SendToHTTP to its own environment does not work

Posted: 26 Sep 2022, 11:46
by joost d
"Also I don't really see the purpose for this as these commands can all be run from within the rules anyway, so why add such a rather extreme overhead?""

Well, I tried to find a way to change a plugin-setting-value (P141, backlight) to switch te backlight automatically on/off. The only way i found, is to do this by the SendToHTTP command.....

Re: SendToHTTP to its own environment does not work

Posted: 26 Sep 2022, 11:49
by Ath
The pcd8544cmd,backlight,<value> command can be used directly from the rules, without the http... prefix. I already wrote that in my email... ;)

Re: SendToHTTP to its own environment does not work

Posted: 26 Sep 2022, 11:52
by TD-er
Both of these below call the same command:

Code: Select all

SendToHTTP 192.168.2.7,80,/control?cmd=pcd8544cmd,backlight,1
pcd8544cmd,backlight,1
However, the SendToHTTP version does allow to call the command on another unit.

The actual command is then included in an URL right after the "?cmd=" part.

Re: SendToHTTP to its own environment does not work

Posted: 26 Sep 2022, 11:54
by Ath
Similar to this?

Code: Select all

on APDS9960#Light do
  if %eventvalue1%>100
    pcd8544cmd,backlight,0 // Backlight off
  else
    pcd8544cmd,backlight,30 // Backlight on
  endif
endon

Re: SendToHTTP to its own environment does not work

Posted: 26 Sep 2022, 12:23
by joost d
Great.
I misunderstand your(Ath) advise by mail. I thought that with " http prefix" the start of the URL was meant.
Now I'm using pcd8544cmd,backlight,0. Thats works great :-)

Thanks