dbLog retrieve data in json via jsonlist2

Begonnen von newb, 01 August 2020, 17:04:49

Vorheriges Thema - Nächstes Thema

newb

Hi, is it possible to get history data ,recorded by the dbLog module via jsonList2 interface?
I read about "GET for webcharts" and tried like so:

get myDbLog - webchart "" "" mySensor daystats temp

to retrieve the the daily temperatures from mySensor, however I get empty array.
If this is possible can this data be retrieved via http request with jsonlist2?

newb

Ok, so the actual syntax for getting the history data is:

get myDbLog - webchart "" "" mySensor timerange TIMESTAMP temp

However this prints json within FHEM web interface and not as separate json page. Is there a way to get this json as a separate data, not within fhem web view?


rudolfkoenig

jsonlist2 is built to return the contents of the %defs and %attributes internal datastructures.
It is not meant to reformat arbitrary datastructures to JSON.

On the other hand according to the documentation the webchart DbLog command already returns a JSON formatted data.
If you know how to query FHEMWEB via jsonlist2, then you should be able to replace it with the DbLog get command .

newb

#3
Thanks, Rudolf. However the problem I get is when I do:

curl -k -0 https://localhost:8083/fhem?cmd=get+myDbLog+-+webchart+2020-08-01_23+2020-08-02_23+mySensor+timerange+TIMESTAMP+temp

I'm getting the full fhem HTML with the json in it and I have to do some RegEx to remove the html and keep only the json.
Is there a way to get only the pure json output of the GET command?

rudolfkoenig

Yes, by adding &XHR=1. This is valid for all FHEM commands, jsonlist2 being no exception.

newb

#5
Sadly, it's still returning html+json even if I add &XHR=1
I'm using the latest updates with "update" command. It's not working even with jsonlist2 (outputs html as well). Strange.

Here are the modules I have:


Latest Revision: 22505

File                  Rev   Last Change

fhem.pl               22475 2020-07-26 17:17:03Z rudolfkoenig
96_allowed.pm         21197 2020-02-14 14:32:04Z rudolfkoenig
98_apptime.pm         19468 2019-05-26 07:13:48Z martinp876
90_at.pm              21639 2020-04-11 08:45:19Z rudolfkoenig
98_autocreate.pm      21659 2020-04-13 10:08:36Z rudolfkoenig
98_CustomReadings.pm  15098 2017-09-19 16:46:33Z HCS
95_Dashboard.pm       21180 2020-02-11 21:04:55Z DS_Starter
93_DbLog.pm           22246 2020-06-23 21:12:11Z DS_Starter
98_dummy.pm           20665 2019-12-06 11:05:35Z rudolfkoenig
10_EnOcean.pm         21679 2020-04-14 17:06:44Z klaus.schauer
91_eventTypes.pm      14888 2017-08-13 12:07:12Z rudolfkoenig
No Id found for 99_FHEMControlPush.pm
98_fheminfo.pm        21552 2020-03-31 11:21:04Z betateilchen
01_FHEMWEB.pm         22244 2020-06-23 19:31:06Z rudolfkoenig
98_help.pm            21551 2020-03-31 11:01:06Z betateilchen
98_HTTPMOD.pm         21141 2020-02-07 19:36:06Z StefanStrobel
49_IPCAM.pm           18505 2019-02-05 21:50:23Z rudolfkoenig
98_JsonList2.pm       22270 2020-06-26 09:25:18Z rudolfkoenig
00_MQTT.pm            22046 2020-05-27 21:59:44Z hexenmeister
10_MQTT_DEVICE.pm     17362 2018-09-17 12:57:29Z hexenmeister
91_notify.pm          21427 2020-03-15 10:10:32Z rudolfkoenig
73_PRESENCE.pm        20782 2019-12-19 10:51:06Z markusbloch
70_Pushover.pm        20897 2020-01-06 12:16:20Z loredo
33_readingsGroup.pm   21151 2020-02-08 16:00:45Z justme1968
33_readingsProxy.pm   16299 2018-03-01 08:06:55Z justme1968
39_siri.pm            14044 2017-04-20 07:48:44Z justme1968
99_SUNRISE_EL.pm      22216 2020-06-20 19:06:47Z rudolfkoenig
98_SVG.pm             22457 2020-07-24 07:22:09Z rudolfkoenig
00_TCM.pm             19607 2019-06-13 08:06:53Z klaus.schauer
98_telnet.pm          21647 2020-04-12 12:13:17Z rudolfkoenig
99_Utils.pm           21768 2020-04-24 14:22:12Z rudolfkoenig
98_version.pm         15140 2017-09-26 09:20:09Z markusbloch
98_weblink.pm         16293 2018-02-28 21:33:57Z rudolfkoenig
71_ZM_Monitor.pm      20463 2019-11-06 14:11:20Z delmar
70_ZoneMinder.pm      22251 2020-06-24 13:13:36Z delmar

AttrTemplate.pm       22304 2020-06-29 15:21:16Z rudolfkoenig
Blocking.pm           17553 2018-10-17 15:56:35Z rudolfkoenig
No Id found for ConnAck.pm
No Id found for Connect.pm
No Id found for Constants.pm
DevIo.pm              22235 2020-06-23 08:30:14Z rudolfkoenig
No Id found for Disconnect.pm
GPUtils.pm            19666 2019-06-20 11:17:29Z CoolTux
HttpUtils.pm          22132 2020-06-07 09:06:48Z rudolfkoenig
No Id found for JustMessageId.pm
No Id found for Message.pm
Meta.pm               21008 2020-01-18 10:22:10Z loredo
No Id found for PingReq.pm
No Id found for PingResp.pm
No Id found for PubAck.pm
No Id found for PubComp.pm
No Id found for Publish.pm
No Id found for PubRec.pm
No Id found for PubRel.pm
RTypes.pm             10476 2016-01-12 21:03:33Z borisneubert
SetExtensions.pm      19208 2019-04-17 19:27:09Z rudolfkoenig
No Id found for SubAck.pm
No Id found for Subscribe.pm
TcpServerUtils.pm     21344 2020-03-03 11:10:07Z rudolfkoenig
No Id found for UnsubAck.pm
No Id found for Unsubscribe.pm

fhemweb.js                 22372 2020-07-09 14:55:10Z rudolfkoenig
fhemweb_readingsGroup.js   15189 2017-10-03 17:53:27Z justme1968
svg.js                     22349 2020-07-05 13:08:43Z rudolfkoenig

rudolfkoenig

This feature was implemented 6-8 years ago, and is still used extensively by fhemweb.js.
Calling jsonlist2 looks like:
wget -q -O - 'http://localhost:8083/fhem?cmd=jsonlist2&fwcsrf=csrf_167500186482727&XHR=1' | gzip -d -
You have to exchange the fwcsrf parameter for your version.

newb

ok, so it's all my fault :) It seems I was not passing the "XHR=1" parameter correctly to Curl.
The correct syntax is curl --data "XHR=1" -k https://localhost:8083/fhem?cmd=jsonlist2
I've got in my config csrfToken none, so this works also without csrf token.

Thanks for the clue and your help :)