generic HTTP Request: length and variables of template?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
groovy
Normal user
Posts: 39
Joined: 14 Oct 2016, 11:32
Location: Chemnitz, Germany

generic HTTP Request: length and variables of template?

#1 Post by groovy » 14 Oct 2016, 13:00

Hi from Germany,

I just discovered this project and I like it.
I set up my first ESP some hours ago and configured almost everything without a hassle.
When it comes to sending the data, I want to use "Generic HTTP" as I have a server running, which receives a request (currently nodeMCU, but want to switch to ESPEasy) in the form:

Code: Select all

index.php?app=shc&a&ajax=pushsensorvalues&spid=3&sid=30&type=2&v1=22.4&v2=43.2
where "spid" is actually the "sensorpoint-ID", "sid" is the sensor-ID, "type" is the type of sensor (and 2 is for DHT) and "v1" and "v2" are the actual values for temperature and humidity.

For a DS18b20, there will be only "v1", for a BME280 there would be "v1", "v2" and "v3".

Given the above example, I:
- named the device "3", being the sensorpoint-ID with the variable %sysname%
- named the task for the DHT "30", being the sensor-ID with the variable %tskname%
- gave the IDX the number "2", being the sensortype with the variable %IDX% (which doesn't work)
- named the value 1 "v1", with the variable %valname%
- named the value 2 "v2", with the variable %valname% (?)

So I assembled the following template-string:

Code: Select all

index.php?app=shc&a&ajax=pushsensorvalues&spid=%sysname%&type=%IDX%&sid=%tskname%&%valname%=%value%
This doesn't work.
The first problem is the length. The resulting request is cut right after %tskname, so the allowed length seems to be 80 chars only. I can enter the whole string, but by submitting it, it gets cut.

Second problem so far, the %IDX% is not getting "translated" into the value. I did not found a documentation where all possible variables are listed, only for the system-variables.
There's only an example string with some possible variables before one replaces this with his own template.

So I have 3 questions:

1. Is there any documentation with possible variables for putting together the template?
2. How is the varying number of possible %valname%=%value%-pairs, depending on the sensortype, handled? When I put that in my template only once (as above), will the other 1 or 2 be appended? Or will they be discarded? What's the "best practice" for this?
3. Is it possible to expand the length of the template when I build the firmware on my own? Will do this anyway, as I want to read VCC.



Thanks in advance

groovy
Normal user
Posts: 39
Joined: 14 Oct 2016, 11:32
Location: Chemnitz, Germany

Re: generic HTTP Request: length and variables of template?

#2 Post by groovy » 15 Oct 2016, 13:00

Just took a look at the code.
For my third question I think I found the corresponding line in _C008.ino:

Code: Select all

url.toCharArray(log, 80);
Am I right with my assumption? Can I simply rise that value?

For the not-working %IDX% variable I found the line:

Code: Select all

url.replace("%id%", String(event->idx));
So that is solved too, I think.

What I didn't found until now is: How can I form the template to send more than one %valname%=%value%-pairs. Can anyone help me on this?

Thanks

groovy
Normal user
Posts: 39
Joined: 14 Oct 2016, 11:32
Location: Chemnitz, Germany

Re: generic HTTP Request: length and variables of template?

#3 Post by groovy » 16 Oct 2016, 14:47

Giving myself an answer again :)

In addition to my found

Code: Select all

url.toCharArray(log, 80);
in _C008.ino changing to 120, I changed the following:

in Webserver.ino, line 1767:

Code: Select all

mqttpublish.toCharArray(tmpString, 121);
(was 81) and in line 1812:

Code: Select all

reply += F("'><TR><TD>Publish Template:<TD><input type='text' name='mqttpublish' size=120 value='");
(was 80). And in ESPEasy.ino, line 315:

Code: Select all

char          MQTTpublish[121];
(was 81).

This gave me the complete string for my template and actually works for a DHT22 and VCC.

For a DS18b20, also connected, the ESP crashes/reboots after a successful read. Have to investigate more on this. The log shows:

Code: Select all

WD : Uptime 0 ConnectFailures 0 FreeMem 28392
34996 : SYS : 3.24
34997 : EVENT: 99#v1=3.24
36020 : DHT : Temperature: 27.30
36020 : DHT : Humidity: 32.60
36020 : EVENT: 30#v1=27.30
36020 : EVENT: 30#v2=32.60
41631 : DS : Temperature: 26.44 (28-ff-bc-77-3b-4-0-2c)
41631 : EVENT: 28-abcdef0003#v1=26.44
and then the ESP reboots.

For this:
What I didn't found until now is: How can I form the template to send more than one %valname%=%value%-pairs
I found, that ESPEasy just sends a separate HTTP-request for every %valname%=%value%-pair. Will have a look, how to manage this behaviour.

sibianul
Normal user
Posts: 28
Joined: 28 Jun 2017, 11:53

Re: generic HTTP Request: length and variables of template?

#4 Post by sibianul » 28 Jun 2017, 12:38

I just found out this awesome project yesterday, today I got a spare D1 mini and flashed the firmware to it .. Awesome guys! Well done, you made everything so simple :)

Now, my problem is related to pushing the data to my BananaPi server, I also use Generic HTTP protocol but if I check the apache access.log on the BananaPi i get the exact same text I saved in the Publish template, not the actual values.

Anyone around to give me some instructions ?

Apache log

Code: Select all

192.168.1.103 - - [28/Jun/2017:12:55:15 +0300] "GET /push.php?name=%esp_sys_info%&id=%41%&value=%esp_sys_info% HTTP/1.1" 200 166 "-" "-"
192.168.1.103 - - [28/Jun/2017:12:56:12 +0300] "GET /push.php?name=%esp_sys_info%&id=%41%&value=%esp_sys_info% HTTP/1.1" 200 166 "-" "-"
192.168.1.103 - - [28/Jun/2017:12:56:15 +0300] "GET /push.php?name=%esp_sys_info%&id=%41%&value=%esp_sys_info% HTTP/1.1" 200 166 "-" "-"
esp_easy_sys_info.png
esp_easy_sys_info.png (24.34 KiB) Viewed 9667 times
esp easy advanced.png
esp easy advanced.png (32.21 KiB) Viewed 9667 times
Any help is appreciated!

krikk
Normal user
Posts: 118
Joined: 28 Feb 2017, 07:57
Location: Austria
Contact:

Re: generic HTTP Request: length and variables of template?

#5 Post by krikk » 28 Jun 2017, 13:33

give the Generic HTTP Advanced Protocol a try, you have to use a -dev or -testing build of th 2.x firmware... could probably solve your issues?

sibianul
Normal user
Posts: 28
Joined: 28 Jun 2017, 11:53

Re: generic HTTP Request: length and variables of template?

#6 Post by sibianul » 28 Jun 2017, 15:45

I flashed the v2.0.0 dev10 firmware, but I still need some help understanding the URL structure.

I seen it's a big difference from the latest stable Ihad before to this dev firmware, alot more sensors, the controller and notification tab .. but I still don;t know how to setup the controller to send the data from all the devices I have setup. So far as I didn't connected any sensor to the ESP I want just to send the sys information like load ..uptime, if I will make this work I will be able to setup other sensors also :)

The ESP was pushing the URL to my BananaPi but for sure it was me that made a mistake, as even now with the dev firmware it still push the text I wrote ion the URL instead of the value, can you guys tell me what I should write in the controller page , is there any documentation regarding General HTTP?

PS. I noticed the ping response is also faster, can you guys tell me if the stable firmware version should be the same as this, because I noticed multiple times the stable firmware not responding to my browser request, also ping response was even 300ms, now I have it constant at 1ms (sometimes 2ms .. but rarely) but so far the uptime is just a few minutes.

Thank you
esp-dev10-devices.png
esp-dev10-devices.png (32.07 KiB) Viewed 9656 times
esp_controller.png
esp_controller.png (41.74 KiB) Viewed 9656 times

krikk
Normal user
Posts: 118
Joined: 28 Feb 2017, 07:57
Location: Austria
Contact:

Re: generic HTTP Request: length and variables of template?

#7 Post by krikk » 28 Jun 2017, 21:03

please read the info on the wiki i linked in my post!

Code: Select all

push.php?sensor_name=%vname1%&value=%val1%
this should work for every sensor which only publishes one value like the sysinfo

sibianul
Normal user
Posts: 28
Joined: 28 Jun 2017, 11:53

Re: generic HTTP Request: length and variables of template?

#8 Post by sibianul » 28 Jun 2017, 21:16

Thanks krikk, I just figured out minutes ago that I have to use exactly the variable %vname1% and %val1% for the first sensor, instead the name of the sensor , that I used in my test :)

I checked apache log and found exactly what I wanted :)

Code: Select all

192.168.1.41 - - [28/Jun/2017:22:03:50 +0300] "GET /push.php?esp%5fsys%5finfo%5fvalue=23.00&=0.00 HTTP/1.1" 200 166 "-" "-"
192.168.1.41 - - [28/Jun/2017:22:03:51 +0300] "GET /push.php?load%5fvalue=7.00&=0.00 HTTP/1.1" 200 166 "-" "-"
Now I will start mounting the relay and temperature/humidity sensor, the relay is for my office led lights, now a few months ago I made all the HTML code on the ESP to look as nice as I could, but I don't know what I messed up and it didn't work anymore, but now I will use the BananaPi to store all the values and to have the dashboard of all my sensors.

But as now I have so little time to play with those thinkgs, I really appreciate your firmware, as this will help me acomplish my goal faster, with spending fewer time on codding all the sensors reading and activation. .. this is how it look in the past, with all the code loaded from ESP .. the graph ware looking great, led light was working ... but that was it, now the Dashboard I work on will contain much more informations

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 28 guests