mikronode icon indicating copy to clipboard operation
mikronode copied to clipboard

Getting unexpected clean exit on login :(

Open hostmit opened this issue 5 years ago • 3 comments

Hello! I'm getting really strange behavior with mikronode login method.

On some devices I connect It does clean exit (I assume process.exit(0) somewhere in package) on connect() method.

Here is code I use

async function mtkApiValidate(host, user, pass) {
  let Device = new mikroNode(host, 8728, 3);
  let result = false;
  await Device.connect(user, pass)
  .then(([login]) => login(user, pass))
    .then(async function (conn) {
      result = true;
      await conn.close()
    })
    .catch(async function (err) {
      let msg;
      if (typeof (err) == 'string') {
        msg = err;
      } else {
        msg = JSON.stringify(err)
      }
      logger.error(`Unable to connect to ${host} => ${user}:${pass}, error was : ${msg}`);
    })
  return result;

Try this IP 94.230.155.137 with any login/pass. It wont get pass login() line, doesnt go into catch. Just clean exit???

Please help.

hostmit avatar Apr 13 '19 19:04 hostmit

your code mixing between async await and promise. please recheck your code. this is example

    try {
                    let device = new MikroNode('192.168.1.1');
                    let conn = await device.connect()
                        .then(([login]) => {
                            return login('admin','123456');
                        });
                    conn.closeOnDone(true);

                    let c1 = conn.openChannel();
                    c1.closeOnDone(true);
 
                    let data = await c1.write(`/system/routerboard/print`);
                    let v = MikroNode.resultsToObj(data.data);
                    console.log(v);
                 
                } catch (error) {
                    console.log(error)
                }  

                    

xeleniumz avatar May 03 '19 04:05 xeleniumz

hello when i try to connect router i am getting this error

 try {
                    let device = new MikroNode('192.168.1.1');
                    let conn = await device.connect()
                        .then(([login]) => {
                            return login('admin','123456');
                        });
                    conn.closeOnDone(true);
                    let c1 = conn.openChannel();
                    c1.closeOnDone(true);

                    let data = await c1.write(`/system/routerboard/print`);
                    let v = MikroNode.resultsToObj(data.data);
                    console.log(v);
                } catch (error) {
                    console.log(error)
                } 

ypeError: _sentence$.get(...).do is not a function at new SocketStream (C:\Workspaces\SysSoft AG\NodeJS\api.routerboard\node_modules\mikronode\dist\mikronode.js:474:52) at MikroNode.connect (C:\Workspaces\SysSoft AG\NodeJS\api.routerboard\node_modules\mikronode\dist\mikronode.js:330:30) at C:\Workspaces\SysSoft AG\NodeJS\api.routerboard\api.surflog.js:16:33 at Layer.handle [as handle_request] (C:\Workspaces\SysSoft AG\NodeJS\api.routerboard\node_modules\express\lib\router\layer.js:95:5) at next (C:\Workspaces\SysSoft AG\NodeJS\api.routerboard\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (C:\Workspaces\SysSoft AG\NodeJS\api.routerboard\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (C:\Workspaces\SysSoft AG\NodeJS\api.routerboard\node_modules\express\lib\router\layer.js:95:5) at C:\Workspaces\SysSoft AG\NodeJS\api.routerboard\node_modules\express\lib\router\index.js:281:22 at Function.process_params (C:\Workspaces\SysSoft AG\NodeJS\api.routerboard\node_modules\express\lib\router\index.js:335:12) at next (C:\Workspaces\SysSoft AG\NodeJS\api.routerboard\node_modules\express\lib\router\index.js:275:10)

BurakOgutken avatar Jul 24 '19 12:07 BurakOgutken

await need async

melsonmascarenhas avatar May 19 '20 04:05 melsonmascarenhas