getHistory is TIMEOUT
mscDev24 opened this issue · 11 comments
Trying to get an objects history with "servConn.getHistory(" is always ending in an TIMEOUT.
I tried every combination of "instance, options" and giving up now :)
Can you help me with an example? Tried with no success ->
servConn.getHistory('history.0', { id: '0_userdata.0.datenpunkt', end: new Date().getTime(), count: 50, aggregate: 'onchange' }, (error, data, step, sessionId) => { ... });
servConn.getHistory('0_userdata.0.datenpunkt', { end: new Date().getTime(), count: 50, aggregate: 'onchange' }, (error, data, step, sessionId) => { ... });
Thanks! servConn.init is done with success and i can get objects-val's....but no history :(
From where the timeout comes? Can you show more logs? Can you also post debuglog from e.g. history to see if an answer was sent?
"timeout" comes from the callback of "servConn.getHistory(" and the class "conn.js"
`getHistory: function (id, options, callback) {
if (!this._checkConnection('getHistory', arguments)) {
return;
}
options = options || {};
options.timeout = options.timeout || 2000;
var timeout = setTimeout(function () {
timeout = null;
callback('timeout');
}, options.timeout);
this._socket.emit('getHistory', id, options, function (err, result) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
callback(err, result);
});
},`
There is no other log on the "chrome"-side, it just prints out "timeout" in the console.
In iobroker-log i can only find
socketio.0 | 2021-04-25 06:46:16.787 | info | (428) ==>Connected system.user.admin from ::????? -- | -- | -- | -- socketio.0 | 2021-04-25 06:46:16.633 | info | (428) <==Disconnect system.user.admin from ::?????
I tried a script in iobroker to check if history is working...all is fine
sendTo('history.0', 'getHistory', { id: '0_userdata.0.helligkeit_aussen', options: { end: new Date().getTime(), count: 50, aggregate: 'onchange' } }, function (result) { for (var i = 0; i < result.result.length; i++) { console.log(result.result[i].id + ' ' + result.result[i].val); } });
Using socket.io 3.1.4 & history 1.9.12 - Danke :)
please put the Admin instance you want to query data from into debug mode ... a getHistory call received and answer sent should be logged there. maybe just the zimeout of 2s is too short?
Seems where on the right way :)
`socketio.0 | 2021-04-25 14:45:01.615 | debug | (23491) sendTo "getHistory" to system.adapter.sql.0 from system.adapter.socketio.0 |
---|---|---|---|
socketio.0 | 2021-04-25 14:45:01.233 | debug | (23491) Subscribes: * |
` |
I changed back from sql.0 to history.0 but socket still want to get it from SQL? So....i think i need to tell socket.io to getHistory from history.0.
My
servConn.getHistory('history.0', {.....
seems to be ignored?
Thanks for the sunday-help :)
When checking code then
https://github.com/ioBroker/ioBroker.socketio/blob/master/lib/socket.js#L1256 is expecting id of the datapoint as first parameter and then options object!
And this is passed through directly to
https://github.com/ioBroker/ioBroker.js-controller/blob/master/lib/adapter.js#L6881
so you code should be:
servConn.getHistory('my.datapoint.to.get.history.for', {}, callback)
and in the object you can pass "instance": "history.0" if you want to use history.0, else the "system default" history instance is used.
You can also set sql to debug, should also log stuff on getistory
Perfect! Thank's for the support...workin' now.
servConn.getHistory('0_userdata.0.datenpunkt_blahh_blahhh', { instance : 'history.0', end: new Date().getTime(), count: 50, aggregate: 'onchange' }, (error, data, step, sessionId) => { console.log(error); console.log(data); console.log(step); console.log(sessionId); });
What do you think is needed to simplify this for others? Isthere any documentation wrong or what we could change?
Don't want to criticize anything. This a "freetime" project and i think people should be grateful. :)
My problem was that i missed a point of documentation about the "options" in "getHistory" in the README.md
https://github.com/ioBroker/ioBroker.socketio#gethistory
function (instance, options, callback)
Should be maybe be function('id', options, callback) and a small documentation of the possible options (as you showed me in the adapter.js
* Possible options:
*
* - instance - (optional) name of instance, where to read the historian data, e.g. 'history.0', 'sql.1'. By default will be taken from system settings.
* - start - (optional) time in ms - Date.now()', by default is (now - 1 week)
* - end - (optional) time in ms - Date.now()', by default is (now + 5000 seconds)
* - step - (optional) used in aggregate (m4, max, min, average, total) step in ms of intervals
* - count - number of values if aggregate is 'onchange' or number of intervals if other aggregate method. Count will be ignored if step is set.
* - from - if from field should be included in answer
* - ack - if ack field should be included in answer
* - q - if q field should be included in answer
* - addId - if id field should be included in answer
* - limit - do not return more entries than limit
* - ignoreNull - if null values should be include (false), replaced by last not null value (true) or replaced with 0 (0)
* - sessionId - (optional) identifier of request, will be returned back in the answer
* - aggregate - aggregate method:
* - minmax - used special algorithm. Splice the whole time range in small intervals and find for every interval max, min, start and end values.
* - max - Splice the whole time range in small intervals and find for every interval max value and use it for this interval (nulls will be ignored).
* - min - Same as max, but take minimal value.
* - average - Same as max, but take average value.
* - total - Same as max, but calculate total value.
* - count - Same as max, but calculate number of values (nulls will be calculated).
* - none - No aggregation at all. Only raw values in given period.
@mscDev24 could you do a PR against README.md to adjust as you think it is correct? That would be awesome
A Pull Request against README.MD ? Currently i don't see any changes, Ingo.
Aber ich helfe gerne wenn ich kann :)
Der von Dir zitierte Text stammt aus der README.md. Dukannst die in GitHub anklicken, oben rechts auf den Stift und annst es editieren. Dann am besten das anpassen was Du denkst das sinn macht wegen dem Thema hier und dann unten die Änderung vorschlagen . Da kommt dann ein PullRequest raus