Generic HTTP Documentation

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
garnold
Normal user
Posts: 93
Joined: 17 Jun 2019, 03:59

Generic HTTP Documentation

#1 Post by garnold » 12 Mar 2021, 17:51

I'm trying to learn more about how to format and use the Generic HTTP controller. I've searched both the old and new wiki sites but can't seem to get info on how to correctly format the URL. For testing I'm just using a RequestBin site to see the data being pushed out from this controller. I'm having a device trigger the controller every 5 seconds but I'm not even using any of that data. If you look at the attached image, I'm just trying to pass a hard coded value to the requestbin for testing. I also don't understand what the idx number is for when I tell a device to send info to this controller. There is the option to send all data to the controller rather then multiple calls. Since I want to pass all the data at once I think this is what I should have checked off.
Attachments
Screen Shot 2021-03-12 at 11.51.18 AM.png
Screen Shot 2021-03-12 at 11.51.18 AM.png (62.01 KiB) Viewed 5844 times
Screen Shot 2021-03-12 at 11.48.26 AM.png
Screen Shot 2021-03-12 at 11.48.26 AM.png (76.18 KiB) Viewed 5844 times

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Generic HTTP Documentation

#2 Post by TD-er » 12 Mar 2021, 17:54

You have "https://" in the hostname.
That should not be there, just the hostname.
As a matter of fact, you cannot use https, so also make sure your site is reachable via http instead of https.

garnold
Normal user
Posts: 93
Joined: 17 Jun 2019, 03:59

Re: Generic HTTP Documentation

#3 Post by garnold » 12 Mar 2021, 17:57

Thank you very much! I'll go do more testing.

garnold
Normal user
Posts: 93
Joined: 17 Jun 2019, 03:59

Re: Generic HTTP Documentation

#4 Post by garnold » 12 Mar 2021, 20:13

That 100% helped but I still don't understand the "Single event with all values" option under a device. I read that if a device has more than one task (like temp and humidity) that the device will pub to the controller twice. I thought that the "Single event with all values" option would send both reading to the controller so that I could send everything out together. I think I'm miss understanding this feature.

garnold
Normal user
Posts: 93
Joined: 17 Jun 2019, 03:59

Re: Generic HTTP Documentation

#5 Post by garnold » 12 Mar 2021, 20:24

OK, got it :D
?%val1%&%val2%

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Generic HTTP Documentation

#6 Post by TD-er » 12 Mar 2021, 20:32

garnold wrote: 12 Mar 2021, 20:13 That 100% helped but I still don't understand the "Single event with all values" option under a device. I read that if a device has more than one task (like temp and humidity) that the device will pub to the controller twice. I thought that the "Single event with all values" option would send both reading to the controller so that I could send everything out together. I think I'm miss understanding this feature.
The "single event" is about the events handled in the rules.
When it is unchecked (default behavior), ESPEasy will generate an event per task value.
For example for the task named "bme280" with task variables "T", "H" and "P" you will see 3 events being generated when there are new readings:

- bme280#T=21.3
- bme280#H=71.0
- bme280#P=1003.1

With the "single event" checked, you will get 1 event:
- bme280#all=21.3,71.0,1003.1

These event values can be referred to in the rules via %eventvalue1%, ... , %eventvalue3% (max. of 4, but the BME280 only outputs 3 values)

garnold
Normal user
Posts: 93
Joined: 17 Jun 2019, 03:59

Re: Generic HTTP Documentation

#7 Post by garnold » 12 Mar 2021, 20:38

Getting so much closer!

This is what I'm using to send the data out and it works perfect
sensorData?t=%val1%&h=%val2%&sId=sensor_001

But it is still making 2 calls to the controller, one for each measurement. I'm missing the meaning of that check box on the device about sending everything in one call. Does that mean it's going to send everything in one call but make a call for each measurement?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Generic HTTP Documentation

#8 Post by TD-er » 12 Mar 2021, 20:41

That checkbox is for sending events to the rules.
It has nothing to do with the connected controllers.

But if you would like to use a more advanced approach, you could generate a HTTP call via the rules using the SendToHttp command and the %eventvalue1% reference I mentioned.

garnold
Normal user
Posts: 93
Joined: 17 Jun 2019, 03:59

Re: Generic HTTP Documentation

#9 Post by garnold » 12 Mar 2021, 20:54

Understood. So the controller will always get called for each measurement, regardless of that checkbox. I'll have to move over to rules then. Thank you :-)

garnold
Normal user
Posts: 93
Joined: 17 Jun 2019, 03:59

Re: Generic HTTP Documentation

#10 Post by garnold » 12 Mar 2021, 21:41

I have it working now thanks to the help I have received here! I still do have a question. I ended up doing this on a timer so that the data was posted every 5 seconds. Because of this I did not use the eventvalue option. I completely understand why I did what I had to do in this rule below. What I do not understand is, what would trigger my device to call my rule? So if I created a rule that fired off the change in my DTH22, what would have to change? The temp or humidity or does it fire when either change?

Here is my rule that works great.
On System#Boot do //When the ESP boots, do
timerSet,1,5 //Set Timer 1 for the next event in 5 seconds
endon

On Rules#Timer=1 do //When Timer1 expires, do
SendToHTTP enm6ldg2gcm5.x.pipedream.net,80,?t=[DHT22#Temperature]&h=[DHT22#Humidity]&sId=sensor_001
timerSet,1,5 //Resets the Timer 1 for another 5 seconds
endon

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Generic HTTP Documentation

#11 Post by TD-er » 12 Mar 2021, 22:31

You named your task and your variables of that task right?
A task with name "taskname" and a task variable called "taskvar" will generate an event "taskname#taskvar=..." with some value of that task variable.
For example task named "bme" and variable "temperature" may generate an event "bme#temperature=20.1"

That's what you may use in your rules:

Code: Select all

on bme#temperature do
....
endon

Post Reply

Who is online

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