Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cc-znp package not working properly on my BeagleBoneBlack. #4

Closed
kyusinyu opened this issue Jun 14, 2016 · 11 comments
Closed

cc-znp package not working properly on my BeagleBoneBlack. #4

kyusinyu opened this issue Jun 14, 2016 · 11 comments

Comments

@kyusinyu
Copy link

I have a CC2531 USB Evaluation Kit connected to the USB port on my BeagleBoneBlack (BBB). I also have two zigbee end-devices within the surroundings of my BBB which are expected to join the network once opened. When the following code

const ccznp = require('cc-znp');
const spCfg = {
    path: '/dev/ttyACM0',
    options: {
        baudrate: 115200,
        flowControl: true,
        rtscts: true
    }
};

ccznp.on('ready', () => {  
     console.log('Device is ready.');

     ccznp.sapiRequest('startRequest', {}, () => {
        });

        ccznp.sapiRequest('permitJoiningRequest', {destination: 0xFFFC, timeout: 0xAA}, (error, result) => {
            if (error) {
                throw error;
            }

            // Verify the results
            console.log(result);
        });
});

ccznp.on('AREQ', (data) => {
     console.dir(data);
});

ccznp.init(spCfg, (error) => {
    console.log(error);
});

ccznp.on('close', function() {
    console.log('Serial port closed.');
});

is run, I get the following error:

Error: request timeout
    at ccznp.sapiRequest (.../test.js:82:23)
    at CcZnp.<anonymous> (.../node_modules/cc-znp/lib/ccznp.js:190:13)
    at CcZnp.g (events.js:286:16)
    at emitOne (events.js:96:13)
    at CcZnp.emit (events.js:188:7)
    at Timeout.<anonymous> (.../node_modules/cc-znp/lib/ccznp.js:170:18)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)  

After running the script again several times (at least 6 times), the error suddenly disappears and I get the following results:

{ 
  sof: 254,
  len: 1,
  type: 'SRSP',
  subsys: 'SAPI',
  cmd: 'permitJoiningRequest',
  payload: { status: 0 },
  fcs: 111,
  csum: 111 
}

After getting the results finally, if I run the same script again it just hangs until I stop it with CRTL+C!

It is worth noting that this procedure happens with all the other commands (e.g. UTIL_GET_DEVICE_INFO etc.) I try to call i.e. I must run the script several times, get the 'Error: request timeout' message above during each run, before it finally runs without any errors and yield the results.

Am I perhaps doing something wrong or is this a bug within the cc-znp package? I would be grateful if you can investigate this issue as soon as possible and let me know your feedback/solution.

Many thanks in advance.

@simenkid
Copy link
Member

Hi kilianyusinyu,

Thanks for your feedback. We encountered an issue of messages processing performance in RaspPi-2 before, so I was wondering if BBB has the same problem. I just extend the request timeout from 3 seconds to 20 seconds, and npm publish to version 0.0.5. Would you please try it again?

By the way, did you call reset in your script? Since reset will break the connection from cc2531 to your host, and many requests will be pended until they are timed out. (Just a notice for you if you are using cc2531)

@kyusinyu
Copy link
Author

Hi simenkid,

Many thanks for your quick response! The request timeout change from 3 to 20 seconds is quite noticeable with the new version 0.0.5 and I have tested again several times. Unfortunately, the problem still persists and I only get good results after several runs, whereby each run yields a timeout error after which one (i.e. the last run) suddenly yields expected results without any timeout errors - exactly as already described above. I guess the problem lies elsewhere inside the cc-znp package or inside one of its dependencies?

Just to answer your question regarding reset. No, I did not call reset in my script. But thanks all the same for the tip!

@simenkid
Copy link
Member

simenkid commented Jun 14, 2016

Hi, kilianyusinyu,

We are now tracing down the dependencies. We will fix this issue and let you know soon. :-)

@simenkid
Copy link
Member

Hi, kilianyusinyu,

It seems that something goes wrong with node.js event loop. We just fix the problem. Would you please try it again? And let us know if the problem is solved. ^^

(The package is now updated to v0.0.6.)

@kyusinyu
Copy link
Author

Hi simenkid,
I have just tested again and the problem is still persisting. After several runs (as already described above) it suddenly works but this is not user-friendly! This implies that the cause of this request timeout problem is still elsewhere in some package.

@jackchased
Copy link
Member

Hi kilianyusinyu,

Sorry for the inconvenience. There is not event loop problem, the problem is stream broken in lower layer. We already fixed it, and tested. It should be ok. Would you please try it again, thanks :-)

(The package is now updated to v0.0.7)

@jackchased
Copy link
Member

Hi kilianyusinyu,

The following code is test ok.

const ccznp = require('cc-znp');
const spCfg = {
    path: '/dev/ttyACM0',
    options: {
        baudrate: 115200,
        flowControl: true,
        rtscts: true
    }
};

ccznp.on('ready', () => {  
    console.log('Device is ready.');

    ccznp.sapiRequest('startRequest', {}, () => {
    });
});

ccznp.on('AREQ', (Ind) => {
    // { subsys: 'ZDO', ind: 'stateChangeInd', data: { state: 8 } }
    console.dir(Ind);

    var data = Ind.data;
    if (data.state === 9) {
        ccznp.sapiRequest('permitJoiningRequest', {destination: 0xFFFC, timeout: 0xAA}, (error, result) => {
            if (error) {
                throw error;
            }

            // Verify the results
            console.log(result);
        });
    }
});

ccznp.init(spCfg, (error) => {
    console.log(error);
});

ccznp.on('close', function() {
    console.log('Serial port closed.');
});

and result:
1

@kyusinyu
Copy link
Author

Hi jackchased,

I have tested several times with the updated version 0.0.7 and each time the AREQ event is not fired and the script keeps waiting for it for quite a very long time after which I simply stop it with CTRL+C. Unfortunately, no errors are thrown to inform me about the cause of the problem and this is not helping me either.

@simenkid
Copy link
Member

Hi kilianyusinyu,

What do you mean "each time the AREQ event is not fired and the script keeps waiting for it for quite a very long time"?

Is that possible to give us your code under test?

@kyusinyu
Copy link
Author

Hi jackchased,

What I mean is that the code above that worked for you did not work for me. In my case, I have a CC2531 USB Evaluation Kit connected to the USB port on my BeagleBoneBlack which in turn is connected to the USB port of my MacBook.
image
As you can see, the AREQ event is never fired and the script keeps waiting for it for quite a very long time.

@simenkid
Copy link
Member

simenkid commented Jun 16, 2016

Hello kilianyusinyu,

I think I found the problem. The npm module did not direct to its repository properly (you will always install a v0.0.5 package). I just fix the link to the correct repository. You may like npm install cc-znp@0.0.8 to ensure the lastest release is installed on your host.

Sorry, it's my fault.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants