njh/node-owfs

problems with concurrent requests to same device

palsbo opened this issue · 12 comments

Hi
I am loopeing thru a dir request in order to analyse the devices.
if a DS1820 I wnat to read the temperature which goes well

if a DS2438 I want to read Temperature, VAD and VDD - this will fail with the following:

/volume2/server/owfstest/node_modules/owfs/build/base/convert.js:19
result = messageToUse.payload.replace(new RegExp(" ", "g"), "");
^
TypeError: Cannot call method 'replace' of undefined
at /volume2/server/owfstest/node_modules/owfs/build/base/convert.js:19:39
at callbackOnce (/volume2/server/owfstest/node_modules/owfs/build/base/communication.js:23:9)
at Socket. (/volume2/server/owfstest/node_modules/owfs/build/base/communication.js:32:14)
at Socket.emit (events.js:117:20)
at _stream_readable.js:943:16

at process._tickCallback (node.js:419:13)

What can I do?

I tried to make the read for VAD inside the result for Temerature read result and the read for VDD inside the read for VAD result in order to prevent multible outstanding requests for one device, but it still fails

Hi,

please post the simplest code to reproduce this issue and send me the debug output. See the readme on how to enable debug mode.
Since I only own a 1820 I rely on this information and on fake devices, but sometimes they behave a litle different.
Regards
Ben

Hi
Thanks for quick response.

Her comes the source code (test.js)

var

Client = require("owfs").Client;
var con = new Client("localhost", 4304);
Dev1820 = '10.';
Dev1923 = '41.';
Dev2405 = '05.';
Dev2406 = '12.';
Dev2408 = '29.';
Dev2413 = '3A.';
Dev2423 = '1D.';
Dev2438 = '26.';
Dev2450 = '20.';
Dev2490 = '81.';
Dev =

function (device) { return device.substr(1, 3);}
get = function (cmd, dev, callback) {
con.read(dev + "/"+cmd, function (err, val) { if (!err)
callback(dev, val)
console.log(dev, val)
})
}
setInterval(

function () {
con.dir("/", function (err, devs) {
devs.forEach(function (dev) {
switch (Dev(dev)) {
case Dev1820:
get("temperature", dev, function (dev, val) {
console.log(dev, val)
})
break;
case Dev2438:
get("temperature", dev, function (dev, val) {
console.log(dev, val)
})
get("VAD", dev, function (dev, val) {
console.log(dev, val)
});
get("VDD", dev, function (dev, val) {
console.log(dev, val)
});
break;
case Dev2405:
get("PIO", dev, function (dev, val) {
console.log(dev, val)
});
break;
}
});
})
}, 1000)----------------------------------------------

Here comes the output:


NAS212> DEBUG=owfs* node test.js
owfs:convert extractDirectories +0ms
owfs:communication Sending[object Object] +87ms
owfs:communication Receiving header [object Object] +65ms
owfs:communication Receiving payload /20.91200E000000 +1ms
owfs:communication Receiving header [object Object] +6ms
owfs:communication Receiving payload /10.9A4DE9000800 +0ms
owfs:communication Receiving header [object Object] +17ms
owfs:communication Receiving payload /26.8C629F010000 +1ms
owfs:communication Receiving header [object Object] +19ms
owfs:communication Receiving payload /81.D71D2A000000 +1ms
owfs:communication Receiving header [object Object] +19ms
owfs:communication Receiving payload /05.0A202D000000 +1ms
owfs:communication Receiving header [object Object] +19ms
owfs:communication Receiving payload /05.6A852C000000 +1ms
owfs:communication Receiving header [object Object] +20ms
owfs:communication Receiving payload /05.091C2D000000 +1ms
owfs:communication Receiving header [object Object] +18ms
owfs:communication Receiving payload /05.DF032D000000 � +1ms
owfs:convert [ { header: { version: 0, payload: 17, ret: 0,
controlflags: 32, size: 16, offset: 0 }, payload:
'/20.91200E000000\u0000' }, { header: { version: 0, payload: 17, ret: 0,
controlflags: 32, size: 16, offset: 0 }, payload:
'/10.9A4DE9000800\u0000' }, { header: { version: 0, payload: 17, ret: 0,
controlflags: 32, size: 16, offset: 0 }, payload:
'/26.8C629F010000\u0000' }, { header: { version: 0, payload: 17, ret: 0,
controlflags: 32, size: 16, offset: 0 }, payload:
'/81.D71D2A000000\u0000' }, { header: { version: 0, payload: 17, ret: 0,
controlflags: 32, size: 16, offset: 0 }, payload:
'/05.0A202D000000\u0000' }, { header: { version: 0, payload: 17, ret: 0,
controlflags: 32, size: 16, offset: 0 }, payload:
'/05.6A852C000000\u0000' }, { header: { version: 0, payload: 17, ret: 0,
controlflags: 32, size: 16, offset: 0 }, payload:
'/05.091C2D000000\u0000' }, { header: { version: 0, payload: 17, ret: 0,
controlflags: 32, size: 16, offset: 0 }, payload:
'/05.DF032D000000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000
\u0000\u0000\u0000\u0000\u0000\u0000�\u0006' } ] +12ms
owfs:convert extracted directories +46ms
owfs:convert [ [ '/20.91200E000000' ], [ '/10.9A4DE9000800' ], [
'/26.8C629F010000' ], [ '/81.D71D2A000000' ], [ '/05.0A202D000000' ], [
'/05.6A852C000000' ], [ '/05.091C2D000000' ], [ '/05.DF032D000000', '�'
] ] +1ms
owfs:communication Sending[object Object] +33ms
owfs:communication Sending[object Object] +3ms
owfs:communication Sending[object Object] +3ms
owfs:communication Sending[object Object] +2ms
owfs:communication Sending[object Object] +1ms
owfs:communication Sending[object Object] +2ms
owfs:communication Sending[object Object] +1ms
owfs:communication Sending[object Object] +2ms
owfs:communication Receiving header [object Object] +684ms
owfs:communication Receiving payload 26.125 +0ms
/10.9A4DE9000800 26.125
/10.9A4DE9000800 26.125
owfs:communication Receiving header [object Object] +53ms
owfs:communication Receiving payload 0 +0ms
/05.6A852C000000 0
/05.6A852C000000 0
owfs:convert extractDirectories +24ms
owfs:communication Sending[object Object] +3ms
owfs:communication Receiving header [object Object] +11ms
owfs:communication Receiving payload 0 +0ms
/05.DF032D000000 0
/05.DF032D000000 0
owfs:communication Receiving header [object Object] +38ms
owfs:communication Receiving payload 0 +1ms
/05.0A202D000000 0
/05.0A202D000000 0
owfs:communication Receiving header [object Object] +79ms
owfs:communication Receiving payload 25.6875 +1ms
/26.8C629F010000 25.6875
/26.8C629F010000 25.6875
owfs:communication Receiving header [object Object] +39ms
owfs:communication Receiving payload 0 +1ms
/05.091C2D000000 0
/05.091C2D000000 0
owfs:communication Receiving header [object Object] +67ms
owfs:communication Receiving payload +1ms
owfs:communication Receiving header [object Object] +1ms
owfs:communication Receiving payload +0ms
owfs:communication Receiving header [object Object] +39ms
owfs:communication Receiving payload 1.55 +1ms
owfs:convert Received multiple messages in simple read[object
Object],[object Object] +4ms

/volume2/server/owfstest/node_modules/owfs/build/base/convert.js:19
result = messageToUse.payload.replace(new RegExp(" ", "g"), "");
^
TypeError: Cannot call method 'replace' of undefined
at
/volume2/server/owfstest/node_modules/owfs/build/base/convert.js:19:39
at callbackOnce
(/volume2/server/owfstest/node_modules/owfs/build/base/communication.js:23:9)
at Socket.
(/volume2/server/owfstest/node_modules/owfs/build/base/communication.js:32:14)
at Socket.emit (events.js:117:20)
at _stream_readable.js:943:16
at process._tickCallback (node.js:419:13)

NAS212>

Regards

Erik

------ Original Message ------
From: "Benedikt Arnold" notifications@github.com
To: "benediktarnold/owfs" owfs@noreply.github.com
Cc: "palsbo" erik@palsbo.com
Sent: 27-11-2014 07:43:23
Subject: Re: [owfs] problems with concurrent requests to same device
(#11)

Hi,

please post the simplest code to reproduce this issue and send me the
debug output. See the readme on how to enable debug mode.
Since I only own a 1820 I rely on this information and on fake devices,
but sometimes they behave a litle different.
Regards
Ben


Reply to this email directly or view it on GitHub.

Great! Tomorrow I will have some time to dig into it.

Hi!
Sorry for the delay. I am not able to reproduce your error. But I don't have a physical DS2438 and I am only using the fakeserver. Are you using the latest version 0.2.2?
I am missing some log statements, I already fixed. In your log output I am seeing this line

owfs:communication Receiving header [object Object] +39ms

a lot of times but it used to print the header human readable. I you are using the latest version, please add a console.log statement at this position.

Greetings,
Ben

Hi
Tnx for reply.
I was using v. 2.1.0 but have now changed to 2.2.
It takes a bit longer, before the error occurs, but within 30 sec it
will happen.
I made a new debug file using v2.2 - enclosed
Regards
Erik

------ Original Message ------
From: "Benedikt Arnold" notifications@github.com
To: "benediktarnold/owfs" owfs@noreply.github.com
Cc: "palsbo" erik@palsbo.com
Sent: 09-12-2014 12:58:12
Subject: Re: [owfs] problems with concurrent requests to same device
(#11)

Hi!
Sorry for the delay. I am not able to reproduce your error. But I don't
have a physical DS2438 and I am only using the fakeserver. Are you
using the latest version 0.2.2?
I am missing some log statements, I already fixed. In your log output I
am seeing this line

owfs:communication Receiving header [object Object] +39ms
a lot of times but it used to print the header human readable. I you
are using the latest version, please add a console.log statement at
this position.

Greetings,
Ben


Reply to this email directly or view it on GitHub.

Did you reply by email with an attachment? I think this is not working - There is no debug output enclosed.

How can I send you the attachment?
Erik

Den 10/12/2014 kl. 08.41 skrev Benedikt Arnold notifications@github.com:

Did you reply by email with an attachment? I think this is not working - There is no debug output enclosed.


Reply to this email directly or view it on GitHub.

The easiest way would be a gist.

I don't know how to use gist

Den 10/12/2014 kl. 21.41 skrev Benedikt Arnold notifications@github.com:

The easiest way would be a gist.


Reply to this email directly or view it on GitHub.

njh commented

Hello,

I have found that owserver doesn't cope will with multiple concurrent reads.
To solve this problem in my code, I originally used the eachSeries function from async:
http://caolan.github.io/async/docs.html#eachSeries

And later switch to using promises from Bluebird:
https://github.com/njh/node-red-contrib-owfs/blob/master/owfs.js

This makes the code synchronous, and only allows a single read at a time - and I stopped seeing errors.

nick.

njh commented

Going to close this - no response from original poster for 2 years.