HTTP communication
Moderators: grovkillen, Stuntteam, TD-er
HTTP communication
I have 2 boards named Pir_1 and Oled_2, I want them to communicate through HTTP, when pir sensor state is 1 (detection) board no. 2 displays message on oled screen. But i am getting 404 error and I can't set it up.
Pir_1 rules:
on Pir#Switch do
if [PIR#Switch]=1
SendToHTTP 192.168.0.110,80,/update?pirstate=1
else
SendToHTTP 192.168.0.110,80,/update?pirstate=0
endif
endon
Pir device name: Pir
Pir variable state name: pirstate
controller: generic HTTP controller ip 192.168.0.110, publish: /update?pirstate=%val%
Oled_2 rules:
on System#Boot do
OLED,clear
OLED,font,1
OLED,text,1,Waiting for data...
endon
on HTTP#update do
if %eventvalue1% = 1
OLED,clear
OLED,text,1,Motion Detected!
else
OLED,clear
OLED,text,1,No Motion
endif
endon
oled device name: OLED_Display
Any help would be appreciated.
Pir_1 rules:
on Pir#Switch do
if [PIR#Switch]=1
SendToHTTP 192.168.0.110,80,/update?pirstate=1
else
SendToHTTP 192.168.0.110,80,/update?pirstate=0
endif
endon
Pir device name: Pir
Pir variable state name: pirstate
controller: generic HTTP controller ip 192.168.0.110, publish: /update?pirstate=%val%
Oled_2 rules:
on System#Boot do
OLED,clear
OLED,font,1
OLED,text,1,Waiting for data...
endon
on HTTP#update do
if %eventvalue1% = 1
OLED,clear
OLED,text,1,Motion Detected!
else
OLED,clear
OLED,text,1,No Motion
endif
endon
oled device name: OLED_Display
Any help would be appreciated.
Re: HTTP communication
/update on ESPEasy is being used for OTA updates.
You should either give the command to generate an event on the other node, or use ESPEasy p2p.
To see what the URL will be like, you can enter the event command you like to give on the tools page in the command field.
When pressing enter, the page will reload and the complete command URL will be shown in the browser's address bar, including any required HTTP escape characters.
For example:
Will be converted in the address-bar like this:
Or you can use the ESPEasy p2p protocol sending commands to other nodes using the "sendto" command.
Make sure all nodes use the same UDP port (default port 8266) and each have a unique unit ID (Config tab) and don't use 0 or 255.
You should either give the command to generate an event on the other node, or use ESPEasy p2p.
To see what the URL will be like, you can enter the event command you like to give on the tools page in the command field.
When pressing enter, the page will reload and the complete command URL will be shown in the browser's address bar, including any required HTTP escape characters.
For example:
Code: Select all
event,myevent=12,34,56
Code: Select all
http://192.168.11.10/tools?cmd=event%2Cmyevent%3D12%2C34%2C56
Make sure all nodes use the same UDP port (default port 8266) and each have a unique unit ID (Config tab) and don't use 0 or 255.
Re: HTTP communication
Okay I've implemented changes sending rule looks like this:
On Pir#pirstate do
if [Pir#pirstate]=1
sendto,192.168.0.110,"event,motion=1"
else
sendto,192.168.0.110,"event,motion=0"
endif
endon
And now how do I recieve it? I have the same UDP ports
On Pir#pirstate do
if [Pir#pirstate]=1
sendto,192.168.0.110,"event,motion=1"
else
sendto,192.168.0.110,"event,motion=0"
endif
endon
And now how do I recieve it? I have the same UDP ports
Re: HTTP communication
See how the sendto command is used: https://espeasy.readthedocs.io/en/lates ... nd-publish
You need to address the other node via its unit ID, not an IP-address.
This also makes it clear why you need an unique ID per node.
When you send an event via sendto, the event will be received on the other end, so you can act on it in rules, just like local generated events.
Just assuming the 'other' node is using ID 2, then the rule will be like this:
You need to address the other node via its unit ID, not an IP-address.
This also makes it clear why you need an unique ID per node.
When you send an event via sendto, the event will be received on the other end, so you can act on it in rules, just like local generated events.
Just assuming the 'other' node is using ID 2, then the rule will be like this:
Code: Select all
On Pir#pirstate do
sendto,2,"event,motion=%eventvalue1%"
endon
Re: HTTP communication
Okay but i don't see anything about recieving data sent this way on tutorial you sent
Re: HTTP communication
You just send some event to another node, and there it is handled the same way you handle local events.
So you send some event as mentioned and on the receiving node you act on it.
For example I name my event "example#event" (or whatever you want to call it....)
Then on the receiving node (the node with node-id 2 in this example)
You can then do anything you like to do with that value, like put it into a dummy task and send it to its connected controller(s):
So you send some event as mentioned and on the receiving node you act on it.
For example I name my event "example#event" (or whatever you want to call it....)
Code: Select all
sendto,2,"event,example#event=123"
Code: Select all
on example#event do
logentry,"received event with eventvalue: %eventvalue1%"
endon
Code: Select all
on example#event do
//Assume task2 to be a dummy task
taskvalueset,2,1,%eventvalue1%"
taskrun,2 // Send all taskvalues of task 2 to the connected controllers
endon
Re: HTTP communication
Thanks so much for help i managed to display the value but i cant find how to check the value by if instruction in esp easy docs. I need to do that to display various communicates depending on the value
Re: HTTP communication
The concept of Rules is explained in the Rules documentation.
2 often used ways:
- In the event for the task-value:
Code: Select all
on Pir#pirstate do
if %eventvalue1%=1 // Use first argument of current event
// When on...
// Start an alarm
// Alert the remote server
else
// When off...
// Silence the alarm
// Update remote server
endif
endon
Code: Select all
on System#Clock=All,**:** do // Every minute
if [Pir#pirstate]=1 // Use explicit value by name
// When on...
// Start an alarm
// Alert the remote server
else
// When off...
// Silence the alarm
// Update remote server
endif
endon
/Ton (PayPal.me)
Re: HTTP communication
Really appreciate your help, I'll try when I get home
Re: HTTP communication
And just some info on why we (strongly) suggest to use %eventvalue1%... in rules.
Consider these 2 rules which may seem the same at first sight...
Keep in mind the event is something like this:
Pir#pirstate=1
The first block using %eventvalue1% is using the value as how it was when the event was generated.
The second block, using [Pir#pirstate] is using the value as it is when evaluating the event.
Most of the time, these will both result in the same behavior, but there might be situations where these might have changed in the mean time.
So it is best to evaluate %eventvalue1% where applicable, just to avoid timing-critical issues.
Consider these 2 rules which may seem the same at first sight...
Code: Select all
on Pir#pirstate do
if %eventvalue1%=1 // Use first argument of current event
// ...
endif
endon
on Pir#pirstate do
if [Pir#pirstate]=1 // Use first argument of current event
// ...
endif
endon
Pir#pirstate=1
The first block using %eventvalue1% is using the value as how it was when the event was generated.
The second block, using [Pir#pirstate] is using the value as it is when evaluating the event.
Most of the time, these will both result in the same behavior, but there might be situations where these might have changed in the mean time.
So it is best to evaluate %eventvalue1% where applicable, just to avoid timing-critical issues.
Re: HTTP communication
I think in my project there is what you describe, I will change it as well, thanks for the advice. And btw are you the only person responding on this forum? It's a pity that so few people are active.
Re: HTTP communication
And yup everything is working perfectly, thanks so much for help
Re: HTTP communication
Nope, not the only one.
Ton (Ath here on the forum) is also extremely regular
And there are some others who frequently reply, only less frequent than Ton and I do.
Me and Ton are also responsible for about 90+% of all the commits in the last few years.
Ton (Ath here on the forum) is also extremely regular

And there are some others who frequently reply, only less frequent than Ton and I do.
Me and Ton are also responsible for about 90+% of all the commits in the last few years.
Re: HTTP communication
Thanks for the explanation! I appreciate your work and commitment on the forum. It's nice to know that there are a few people who help others on a regular basis.
Re: HTTP communication
Hello colleagues. I have a problem connecting one espeasy to the Internet. There are 2 absolutely identically configured devices, but one device sends data to mqtt and narodmon, and also receives data from NTP. And the second device receives NTP data, but does not send data to mqtt and narodmon. How to check whether data is being sent from a device to the Internet?
Re: HTTP communication
Just a few pointers to check:
- Is the gateway configured correctly?
- Is DNS configured correctly?
- Is timeout of controller too low? (increase to 1000 msec for testing)
- Try saving the controller settings again (will perform a new DNS lookup on save)
- Is the gateway configured correctly?
- Is DNS configured correctly?
- Is timeout of controller too low? (increase to 1000 msec for testing)
- Try saving the controller settings again (will perform a new DNS lookup on save)
Re: HTTP communication
The fact of the matter is that the settings of the two devices are exactly the same. Only one transmits data to the Internet, the other does not. 

Re: HTTP communication
If the settings are exactly the same, does that imply that the name and unit number (Config tab) are the same? As the MQTT, and possibly narodmon, server may ignore data from the same device but using a different IP address.
For optimal operation, each ESPEasy unit should have a unique name and unitnr, where the unitnr should not be 0 or 255. For proper networking operations, they also should have a unique IP address.
/Ton (PayPal.me)
Re: HTTP communication
Can you still try to increase the timeout?
ESPEasy is internally adjusting the required timeout based on the average response time.
However if you're just on the edge of what might be usable, then it can fail and keep failing.
ESPEasy is internally adjusting the required timeout based on the average response time.
However if you're just on the edge of what might be usable, then it can fail and keep failing.
Re: HTTP communication
Hello again. I solved the problem of lack of Internet on the device! The issue was with the router. It is not clear for what reason, but after removing the IP from the router and then connecting the device, the Internet appeared on the device. Mikrotik router.
Re: HTTP communication
Maybe you should also check to see if there is >1 device running a DHCP service in your network.
Who is online
Users browsing this forum: No registered users and 16 guests