Page 1 of 1

HTTP get command for sensor value

Posted: 07 Apr 2020, 18:19
by HeinrichB
Hello

how can i get a specific sensor value by the generic

http://<espeasyip>/control?cmd=<command>

espeasy is clear so far, but what is the specific command ?

Thank

Re: HTTP get command for sensor value

Posted: 07 Apr 2020, 22:29
by TD-er
You can get the data as JSON.
All sensor data: http://<ip>/json?view=sensorupdate
Specific for a single task: http://<ip>/json?view=sensorupdate&tasknr=2 (tasknr 2)

Re: HTTP get command for sensor value

Posted: 08 Apr 2020, 07:09
by HeinrichB
Thank you very much. Exactly what i need :)

Re: HTTP get command for sensor value

Posted: 23 May 2020, 19:48
by fury0
Hi,
Thanks for the answer.
But it looks like we get the latest taskX record value, not the actual value.
Is there any command to trigger to read the value of the device?
As I do not speak very well english I'm not sure you'll understand me :-( . So, here is what I would like:
I've configured a task which work on a ADS1115 to measure a voltage. The voltage is measured every 300 seconds and sended to domoticz through an MQTT broker.
Sometime Domoticz need to have the actual value (not the latest measured), so it will be nice to send a request to the ESP to measure immediatly the device and send the value to the controller(s).
Is it possible ?
Thank you very much.

Re: HTTP get command for sensor value

Posted: 23 May 2020, 19:52
by grovkillen
First run a "taskrun" command and you will have the latest value.

Re: HTTP get command for sensor value

Posted: 23 May 2020, 20:09
by fury0
Hi,
Thank you very much for this so quick answer !!!
I did'nt knew this command, I will give it a try.
Thank's again.
[EDIT] Yes!! It works as expected! :P Thank you:

Re: HTTP get command for sensor value

Posted: 28 Jul 2020, 17:44
by DMike92
Hi,
1) Is there a way to obtain the same result for 1 task without json (simplier) ?
2) Where can I find a list of such commands like json, taskrun etc.
Thanks a lot

Re: HTTP get command for sensor value

Posted: 28 Jul 2020, 20:12
by TD-er
See here for a list of the commands: https://espeasy.readthedocs.io/en/lates ... mmand.html

What do you need to get, not in JSON format?
For example like this? (tasks and value numbers start counting at 0)

All values of a task: http://<ip>/csv?tasknr=1
A single value of a task: http://<ip>/csv?tasknr=1&valnr=0
A single value of a task without header: http://<ip>/csv?tasknr=1&valnr=0&header=0

Re: HTTP get command for sensor value

Posted: 06 Oct 2020, 18:39
by Cdzn
How to request only 1 sensor. For exapmle i need only Temperature, so how can i get it with this json?view=sensorupdate=2

Re: HTTP get command for sensor value

Posted: 06 Oct 2020, 20:52
by TD-er
For CSV like output it is possible to address per sensor value.
See: https://espeasy.readthedocs.io/en/lates ... =json#json

Re: HTTP get command for sensor value

Posted: 06 Oct 2020, 21:43
by Cdzn
mb i did something wrong, but when i send this
i get this
URI: /csv
Method: GET
Arguments: 1
NAME:tasknr
VALUE:1
http://<espeasyip>/json?view=sensorupdate&tasknr=2
works fine

Re: HTTP get command for sensor value

Posted: 06 Oct 2020, 21:47
by Cdzn
TD-er wrote: 06 Oct 2020, 20:52 For CSV like output it is possible to address per sensor value.
See: https://espeasy.readthedocs.io/en/lates ... =json#json
Could You help me with CSV, where am i wrong

Re: HTTP get command for sensor value

Posted: 06 Oct 2020, 22:54
by TD-er
What ESPEasy version are you running?

Also keep in mind you need to count from 0.

So tasknr and valnr start counting at 0.

Re: HTTP get command for sensor value

Posted: 07 Oct 2020, 06:32
by Cdzn
Build:⋄ 20104 - Mega
System Libraries:⋄ ESP82xx Core 3d128e5c, NONOS SDK 2.2.2-dev(38a443e), LWIP: 2.1.2 PUYA support
Git Build:⋄ mega-20200222
Plugin Count:⋄ 46 [Normal]
Build Md5: 19a2bba130d3a8159d57546732ba46
Md5 check: passed.
Build Time:⋄ Feb 21 2020 23:33:15
Binary Filename:⋄ ESP_Easy_mega-20200222_normal_ESP8285_1M.bin

Re: HTTP get command for sensor value

Posted: 07 Oct 2020, 10:19
by TD-er
It was merged on May 21st this year: https://github.com/letscontrolit/ESPEas ... 2956/files
So your build doesn't have it yet.

Re: HTTP get command for sensor value

Posted: 07 Oct 2020, 11:02
by Cdzn
thnx!

Re: HTTP get command for sensor value

Posted: 14 Oct 2020, 22:07
by 2007-i
Please tell me how to convert data from

Code: Select all

/ json? View = sensorupdate & taskrun = 2
into a readable view, for example from:
{"Sensors": [
{
"TaskValues": [
{"ValueNumber": 1,
"Name": "Temperature",
"NrDecimals": 2,
"Value": 23.50
},
need to get
Temperature: 23.50?

Re: HTTP get command for sensor value

Posted: 14 Oct 2020, 22:57
by TD-er
Have you tested the csv option as suggested here: https://espeasy.readthedocs.io/en/lates ... ht=csv#csv
???

Re: HTTP get command for sensor value

Posted: 14 Oct 2020, 23:55
by 2007-i
TD-er wrote: 14 Oct 2020, 22:57 Have you tested the csv option as suggested here: https://espeasy.readthedocs.io/en/lates ... ht=csv#csv
???
Yes, but I have an old version and is not supported csv.
I can not install the new version because the plug-in for the thermostat from here is used.
https://github.com/enesbcs/ESPEasyPlugi ... rmOLED.ino
Thanks.

Re: HTTP get command for sensor value

Posted: 15 Oct 2020, 21:18
by 2007-i
Please tell me how to get clean data from a json request?
If possible

Code: Select all

/ json? View = sensorupdate & taskrun = 2

Re: HTTP get command for sensor value

Posted: 15 Oct 2020, 22:52
by TD-er
What exactly do you want?
The json URL only outputs JSON formatted text.
The csv URL was added to output a string which was way simpler to parse on other devices without the need to interpret JSON.

So if you don't want to upgrade to a later version, then I don't know how to help here.
Unless I don't understand your question...

Re: HTTP get command for sensor value

Posted: 16 Oct 2020, 07:46
by Ath
Or you parse the json output on the receiving platform, if you have the option of processing it using javascript or python, that's really easy.

Re: HTTP get command for sensor value

Posted: 18 Oct 2020, 21:14
by 2007-i
So tnank you. Updated to the latest version.
But for some reason, the latest version does not add the _P159_Pushbutton plugin. The rest after being added to define_plugin_sets.h are displayed normally. And _P159_Pushbutton is not visible after adding.

Re: HTTP get command for sensor value

Posted: 18 Oct 2020, 21:24
by Ath
Did you get that source from the Plugin PlayGround? Then it will only be included if PLUGIN_BUILD_TESTING is #defined, you might want to comment out the #ifdef PLUGIN_BUILD_TESTING line at the start of the _P159 source, and also the corresponding #endif at the end of that file.

Re: HTTP get command for sensor value

Posted: 18 Oct 2020, 21:36
by 2007-i
Ath wrote: 18 Oct 2020, 21:24 Did you get that source from the Plugin PlayGround? Then it will only be included if PLUGIN_BUILD_TESTING is #defined, you might want to comment out the #ifdef PLUGIN_BUILD_TESTING line at the start of the _P159 source, and also the corresponding #endif at the end of that file.
I thought enough to put it in
// EXPERIMENTAL (playground) #######################
#ifdef PLUGIN_SET_EXPERIMENTAL
turns out to be wrong.
Ok thanks frend.

Re: HTTP get command for sensor value

Posted: 18 Oct 2020, 21:42
by 2007-i
And now the error, commented out #ifdef PLUGIN_BUILD_TESTING и #endif
exit status 1
'SENSOR_TYPE_SWITCH' was not declared in this scope
When I added _P168_ThermOLED there was this error too, but I replaced
Device [deviceCount] .VType = SENSOR_TYPE_QUAD;
on
Device [deviceCount] .VType = Sensor_VType :: SENSOR_TYPE_QUAD;
as elsewhere and everything was compiled.

Re: HTTP get command for sensor value

Posted: 18 Oct 2020, 21:47
by TD-er
I think that's also a more recent change in the ESPEasy core source code.


Add: #include src/DataStructs/DeviceStruct.h

And append Sensor_VType:: in front of the SENSOR_TYPE_...

Like this: Sensor_VType::SENSOR_TYPE_SWITCH:

Re: HTTP get command for sensor value

Posted: 18 Oct 2020, 21:53
by 2007-i
TD-er wrote: 18 Oct 2020, 21:47 I think that's also a more recent change in the ESPEasy core source code.


Add: #include src/DataStructs/DeviceStruct.h
This add to define_plugin_sets.h or in 159_Pushbutton?

Re: HTTP get command for sensor value

Posted: 18 Oct 2020, 22:11
by 2007-i
'SENSOR_TYPE_DUAL' was not declared in this scope
In event->sensorType = SENSOR_TYPE_DUAL;
add too
event->sensorType = Sensor_VType::SENSOR_TYPE_DUAL; ?

Re: HTTP get command for sensor value

Posted: 19 Oct 2020, 00:24
by TD-er
Yes, all SENSOR_TYPE_xxx should be prefixed by Sensor_VType::

Re: HTTP get command for sensor value

Posted: 16 Aug 2021, 15:02
by DMike92
TD-er wrote: 28 Jul 2020, 20:12 See here for a list of the commands: https://espeasy.readthedocs.io/en/lates ... mmand.html

What do you need to get, not in JSON format?
For example like this? (tasks and value numbers start counting at 0)

All values of a task: http://<ip>/csv?tasknr=1
A single value of a task: http://<ip>/csv?tasknr=1&valnr=0
A single value of a task without header: http://<ip>/csv?tasknr=1&valnr=0&header=0
Hey! I did not saw tour answer (no mail ? "Notify me when a reply is posted" checked now)
Great!
Thank you very much.
Where did you find all the external http commands?
(sorry, you already answered in next post)

Re: HTTP get command for sensor value

Posted: 16 Aug 2021, 16:07
by TD-er
DMike92 wrote: 16 Aug 2021, 15:02
TD-er wrote: 28 Jul 2020, 20:12 See here for a list of the commands: https://espeasy.readthedocs.io/en/lates ... mmand.html

What do you need to get, not in JSON format?
For example like this? (tasks and value numbers start counting at 0)

All values of a task: http://<ip>/csv?tasknr=1
A single value of a task: http://<ip>/csv?tasknr=1&valnr=0
A single value of a task without header: http://<ip>/csv?tasknr=1&valnr=0&header=0
Hey! I did not saw tour answer (no mail ? "Notify me when a reply is posted" checked now)
Great!
Thank you very much.
Where did you find all the external http commands?
(sorry, you already answered in next post)
What do you mean by "external http commands" ?

You can try commands via the command field on the "tools" page via the web interface.
This will give you some feedback (not always very insightful) on the success of the command.
And maybe also very important, it will show you how the command you gave should be formatted using URL encoding in the URL bar of your browser.
This URL you can then use (and modify to your needs) for calls from other nodes/hosts in your network.

N.B. you can also use "system variables" in the commands, like %uptime% and others shown on the "sysvars" page of your ESPEasy node. (only included in "custom" or "normal" builds due to build size limitations)

Re: HTTP get command for sensor value

Posted: 16 Aug 2021, 17:49
by DMike92
TD-er wrote: 16 Aug 2021, 16:07
DMike92 wrote: 16 Aug 2021, 15:02
TD-er wrote: 28 Jul 2020, 20:12 See here for a list of the commands: https://espeasy.readthedocs.io/en/lates ... mmand.html

What do you need to get, not in JSON format?
For example like this? (tasks and value numbers start counting at 0)

All values of a task: http://<ip>/csv?tasknr=1
A single value of a task: http://<ip>/csv?tasknr=1&valnr=0
A single value of a task without header: http://<ip>/csv?tasknr=1&valnr=0&header=0
Hey! I did not saw tour answer (no mail ? "Notify me when a reply is posted" checked now)
Great!
Thank you very much.
Where did you find all the external http commands?
(sorry, you already answered in next post)
What do you mean by "external http commands" ?

You can try commands via the command field on the "tools" page via the web interface.
This will give you some feedback (not always very insightful) on the success of the command.
And maybe also very important, it will show you how the command you gave should be formatted using URL encoding in the URL bar of your browser.
This URL you can then use (and modify to your needs) for calls from other nodes/hosts in your network.

N.B. you can also use "system variables" in the commands, like %uptime% and others shown on the "sysvars" page of your ESPEasy node. (only included in "custom" or "normal" builds due to build size limitations)
Sorry to have bothered you, I saw a little later that your answered my question in the next post of my initial post. The answer was:
https://espeasy.readthedocs.io/en/lates ... ht=csv#csv
Thanks again. I'm happy now:)
My version does not have the CSV but I can get all variables values with JSON format.