HTTP get command for sensor value

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
HeinrichB
New user
Posts: 6
Joined: 08 Mar 2020, 17:59

HTTP get command for sensor value

#1 Post by HeinrichB » 07 Apr 2020, 18:19

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

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

Re: HTTP get command for sensor value

#2 Post by TD-er » 07 Apr 2020, 22:29

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)

HeinrichB
New user
Posts: 6
Joined: 08 Mar 2020, 17:59

Re: HTTP get command for sensor value

#3 Post by HeinrichB » 08 Apr 2020, 07:09

Thank you very much. Exactly what i need :)

fury0
New user
Posts: 3
Joined: 26 Feb 2017, 19:56

Re: HTTP get command for sensor value

#4 Post by fury0 » 23 May 2020, 19:48

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.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: HTTP get command for sensor value

#5 Post by grovkillen » 23 May 2020, 19:52

First run a "taskrun" command and you will have the latest value.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

fury0
New user
Posts: 3
Joined: 26 Feb 2017, 19:56

Re: HTTP get command for sensor value

#6 Post by fury0 » 23 May 2020, 20:09

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:

User avatar
DMike92
Normal user
Posts: 29
Joined: 28 Jul 2020, 02:06
Location: Paris - France

Re: HTTP get command for sensor value

#7 Post by DMike92 » 28 Jul 2020, 17:44

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

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

Re: HTTP get command for sensor value

#8 Post by TD-er » 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

Cdzn
Normal user
Posts: 58
Joined: 06 Oct 2020, 18:15

Re: HTTP get command for sensor value

#9 Post by Cdzn » 06 Oct 2020, 18:39

How to request only 1 sensor. For exapmle i need only Temperature, so how can i get it with this json?view=sensorupdate=2

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

Re: HTTP get command for sensor value

#10 Post by TD-er » 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

Cdzn
Normal user
Posts: 58
Joined: 06 Oct 2020, 18:15

Re: HTTP get command for sensor value

#11 Post by Cdzn » 06 Oct 2020, 21:43

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

Cdzn
Normal user
Posts: 58
Joined: 06 Oct 2020, 18:15

Re: HTTP get command for sensor value

#12 Post by Cdzn » 06 Oct 2020, 21:47

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

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

Re: HTTP get command for sensor value

#13 Post by TD-er » 06 Oct 2020, 22:54

What ESPEasy version are you running?

Also keep in mind you need to count from 0.

So tasknr and valnr start counting at 0.

Cdzn
Normal user
Posts: 58
Joined: 06 Oct 2020, 18:15

Re: HTTP get command for sensor value

#14 Post by Cdzn » 07 Oct 2020, 06:32

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

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

Re: HTTP get command for sensor value

#15 Post by TD-er » 07 Oct 2020, 10:19

It was merged on May 21st this year: https://github.com/letscontrolit/ESPEas ... 2956/files
So your build doesn't have it yet.

Cdzn
Normal user
Posts: 58
Joined: 06 Oct 2020, 18:15

Re: HTTP get command for sensor value

#16 Post by Cdzn » 07 Oct 2020, 11:02

thnx!

2007-i
Normal user
Posts: 18
Joined: 10 Oct 2020, 22:34

Re: HTTP get command for sensor value

#17 Post by 2007-i » 14 Oct 2020, 22:07

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?

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

Re: HTTP get command for sensor value

#18 Post by TD-er » 14 Oct 2020, 22:57

Have you tested the csv option as suggested here: https://espeasy.readthedocs.io/en/lates ... ht=csv#csv
???

2007-i
Normal user
Posts: 18
Joined: 10 Oct 2020, 22:34

Re: HTTP get command for sensor value

#19 Post by 2007-i » 14 Oct 2020, 23:55

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.

2007-i
Normal user
Posts: 18
Joined: 10 Oct 2020, 22:34

Re: HTTP get command for sensor value

#20 Post by 2007-i » 15 Oct 2020, 21:18

Please tell me how to get clean data from a json request?
If possible

Code: Select all

/ json? View = sensorupdate & taskrun = 2

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

Re: HTTP get command for sensor value

#21 Post by TD-er » 15 Oct 2020, 22:52

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...

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: HTTP get command for sensor value

#22 Post by Ath » 16 Oct 2020, 07:46

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.
/Ton (PayPal.me)

2007-i
Normal user
Posts: 18
Joined: 10 Oct 2020, 22:34

Re: HTTP get command for sensor value

#23 Post by 2007-i » 18 Oct 2020, 21:14

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.

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: HTTP get command for sensor value

#24 Post by Ath » 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.
/Ton (PayPal.me)

2007-i
Normal user
Posts: 18
Joined: 10 Oct 2020, 22:34

Re: HTTP get command for sensor value

#25 Post by 2007-i » 18 Oct 2020, 21:36

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.

2007-i
Normal user
Posts: 18
Joined: 10 Oct 2020, 22:34

Re: HTTP get command for sensor value

#26 Post by 2007-i » 18 Oct 2020, 21:42

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.
Last edited by 2007-i on 18 Oct 2020, 21:47, edited 1 time in total.

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

Re: HTTP get command for sensor value

#27 Post by TD-er » 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

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

Like this: Sensor_VType::SENSOR_TYPE_SWITCH:

2007-i
Normal user
Posts: 18
Joined: 10 Oct 2020, 22:34

Re: HTTP get command for sensor value

#28 Post by 2007-i » 18 Oct 2020, 21:53

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?

2007-i
Normal user
Posts: 18
Joined: 10 Oct 2020, 22:34

Re: HTTP get command for sensor value

#29 Post by 2007-i » 18 Oct 2020, 22:11

'SENSOR_TYPE_DUAL' was not declared in this scope
In event->sensorType = SENSOR_TYPE_DUAL;
add too
event->sensorType = Sensor_VType::SENSOR_TYPE_DUAL; ?

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

Re: HTTP get command for sensor value

#30 Post by TD-er » 19 Oct 2020, 00:24

Yes, all SENSOR_TYPE_xxx should be prefixed by Sensor_VType::

User avatar
DMike92
Normal user
Posts: 29
Joined: 28 Jul 2020, 02:06
Location: Paris - France

Re: HTTP get command for sensor value

#31 Post by DMike92 » 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)

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

Re: HTTP get command for sensor value

#32 Post by TD-er » 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)

User avatar
DMike92
Normal user
Posts: 29
Joined: 28 Jul 2020, 02:06
Location: Paris - France

Re: HTTP get command for sensor value

#33 Post by DMike92 » 16 Aug 2021, 17:49

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests