Hi
I would like to know if it is possible to create a custom rules in espeasy in order to trigger an action and do a http request
example:
http://ESPEASY/control?cmd=event,MycustomRule
on MycustomRule do
logentry,"I want to reply to a httprequest"
=> How to reply?
endon
Thanks in advance
custom http rules
Moderators: grovkillen, Stuntteam, TD-er
Re: custom http rules
Yep this is for sure possible.
You could reply to the other ESPEasy node by calling SendToHTTP.
It is also possible to give a number of event values along with the event.
The normal syntax for an event with eventvalues is:
event,"MyCustomRule=1,2,3,4"
N.B. since the event values are separated by commas, which is also the separator for command arguments, you must wrap the argument for the event command in quotes, like I did in my example.
These can be accessed via %eventvalue1% ... %eventvalueN%
See: https://espeasy.readthedocs.io/en/lates ... eventvalue
One last remark.
In the last build, there seems to be an issue with the SendToHttp command, which I'm now working on.
Another way to interact among ESPEasy nodes is to send commands via the sendto command when using ESPEasy p2p.
See: https://espeasy.readthedocs.io/en/lates ... #c013-page
You could reply to the other ESPEasy node by calling SendToHTTP.
It is also possible to give a number of event values along with the event.
The normal syntax for an event with eventvalues is:
event,"MyCustomRule=1,2,3,4"
N.B. since the event values are separated by commas, which is also the separator for command arguments, you must wrap the argument for the event command in quotes, like I did in my example.
These can be accessed via %eventvalue1% ... %eventvalueN%
See: https://espeasy.readthedocs.io/en/lates ... eventvalue
One last remark.
In the last build, there seems to be an issue with the SendToHttp command, which I'm now working on.
Another way to interact among ESPEasy nodes is to send commands via the sendto command when using ESPEasy p2p.
See: https://espeasy.readthedocs.io/en/lates ... #c013-page
Re: custom http rules
since i am not really sure to well understand what is eventvalue
i should be like this ?
example:
http://ESPEASY/control?cmd=event,MycustomRule
on MycustomRule do
logentry,"I want to reply to a httprequest"
event,"MycustomRule=actiondone"
endon
thx
i should be like this ?
example:
http://ESPEASY/control?cmd=event,MycustomRule
on MycustomRule do
logentry,"I want to reply to a httprequest"
event,"MycustomRule=actiondone"
endon
thx
Re: custom http rules
The script variables %eventvalue1%..%eventvalueN% (where N is a positive numeric value) are the arguments passed to your event after the = character
For backward compatibility, %eventvalue% represents the same value as %eventvalue1%
%eventvalue0% is the entire passed string of characters passed after the =
%eventname% is the name of the event, MycustomRule in this example
%eventpar% is the parameter for the event, between the # and the =, meaning that it is empty in your example
For passing non-numeric values as the first argument, it is required to add a * to the event trigger: ]]on MycustomRule* do[[ to enable it to parse string arguments, then you can use %eventvalue1% in your rule to pass on to the SendToHttp statement, for example
That will result in a reboot of the ESP, as you keep calling the same event from your event --> stack overflow!tchi59 wrote: ↑23 Aug 2022, 16:51 i should be like this ?
example:
http://ESPEASY/control?cmd=event,MycustomRule
Code: Select all
on MycustomRule do logentry,"I want to reply to a httprequest" event,"MycustomRule=actiondone" endon
You can call your rule externally, or from another rule, like that, f.e. from the Tools page: event,"MycustomRule=actiondone"
Example:
Code: Select all
on MycustomRule* do
logentry,"I want to reply %eventvalue1% to a httprequest"
SendToHTTP,10.0.0.1,80,"/path/with/%eventvalue1%"
endon
/Ton (PayPal.me)
Re: custom http rules
i tested your code:
on EventName* do
logentry,"I want to reply %eventvalue1% to a httprequest"
SendToHTTP,10.0.0.1,80,"/path/with/%eventvalue1%"
endon
from my workstation in my browser, i always received "OK"
and i would like to receive a message like "actiondone" for instance
it is mandatory to mention the ip address in the SendToHTTP ? my workstation is in dhcp
regards
on EventName* do
logentry,"I want to reply %eventvalue1% to a httprequest"
SendToHTTP,10.0.0.1,80,"/path/with/%eventvalue1%"
endon
from my workstation in my browser, i always received "OK"
and i would like to receive a message like "actiondone" for instance
it is mandatory to mention the ip address in the SendToHTTP ? my workstation is in dhcp
regards
Re: custom http rules
Ah, the OK response you see is the result of executing the operation, either OK or error, and has nothing to with the content of that operation. Don't know of a way to return another response there.
If your ESP is configured to use a DNS server, you can use dns-names instead of IP-addresses.
If your ESP is configured to use a DNS server, you can use dns-names instead of IP-addresses.
/Ton (PayPal.me)
Re: custom http rules
The builds not "size constraint" (the "minimal" and "collection" builds have excluded some features in a build to make it all fit) can also serve mDNS requests.
Meaning you can name your ESPEasy node and it will be available on the network via <name>.local
So when you name your node "bladiebla" it is accessible via "bladiebla.local"
When this feature is present in your build, you will see the ".local" hostname being showin on the root page of the ESPEasy interface.
But I think sending via the p2p layer is probably easier, as long as you have your nodes in the same network subnet.
Then you can give each node an unique "unit nr" (not 0 and not 255, but some value inbetween) and use the sendto command to send some command to another node, addressed via this unit nr.
Meaning you can name your ESPEasy node and it will be available on the network via <name>.local
So when you name your node "bladiebla" it is accessible via "bladiebla.local"
When this feature is present in your build, you will see the ".local" hostname being showin on the root page of the ESPEasy interface.
But I think sending via the p2p layer is probably easier, as long as you have your nodes in the same network subnet.
Then you can give each node an unique "unit nr" (not 0 and not 255, but some value inbetween) and use the sendto command to send some command to another node, addressed via this unit nr.
Who is online
Users browsing this forum: No registered users and 33 guests