Coder Social home page Coder Social logo

Comments (5)

Trakkasure avatar Trakkasure commented on June 18, 2024

The example you are using is from older code.
The readme has updated example.
the login procedure is different, as well as the use of done handler:

    var MikroNode = require('mikronode');
    
    var device = new MikroNode('192.168.0.1');

    device.connect()
      .then(([login])=>{
        return login('username','password');
      })
      .then(function(conn) {
            chan.write('/ip/address/print');
            chan.on('done',function(data) {
             // data is all of the sentences in an array.
             data.forEach(function(item) {
                console.log('Interface/IP: '+item.data.interface+"/"+item.data.address);
             });

             chan.close(); // close the channel. It is not autoclosed by default.
             conn.close(); // when closing connection, the socket is closed and program ends.
      });

from mikronode.

ras24 avatar ras24 commented on June 18, 2024

I tried to use :

var device = new MikroNode('192.168.0.1');

device.connect()
  	.then(([login])=> {
		return login('username','password');
  	})
  	.then(function(conn) {
		chan.write('/ip/address/print');
		chan.on('done',function(data) {
		 	// data is all of the sentences in an array.
			data.forEach(function(item) {
				console.log('Interface/IP: '+item.data.interface+"/"+item.data.address);
			});

			chan.close(); // close the channel. It is not autoclosed by default.
			conn.close(); // when closing connection, the socket is closed and program ends.
		});
	});

But still get the same error :

/Users/me/Desktop/mknode/node_modules/mikronode/dist/mikronode.js:474
                _parsed$.set(this, _sentence$.get(this).do(function (d) {
                                                          ^

TypeError: _sentence$.get(...).do is not a function
    at new SocketStream (/Users/me/Desktop/mknode/node_modules/mikronode/dist/mikronode.js:474:52)
    at MikroNode.connect (/Users/me/Desktop/mknode/node_modules/mikronode/dist/mikronode.js:330:30)
    at Object.<anonymous> (/Users/me/Desktop/mknode/app.js:28:8)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
error Command failed with exit code 1.

Is there something wrong with my environment? i'm using Node.js v8.9.4

from mikronode.

Trakkasure avatar Trakkasure commented on June 18, 2024

Correct code for getting IP address. (Missed parsing the data)

device.connect()
      .then(([login])=> {
        return login('username','password');
      })
      .then(function(conn) {
        console.log("Connected");
                var chan=conn.openChannel();
        chan.write('/ip/address/print');
        chan.on('done',function(data) {
            // data is full results (data.data), with metadata.
            // Convert data from routeros data format to flat object results
            const results = data.data.map(MikroNode.resultsToObj);
            results.forEach(function(item) {
                console.log('Interface/IP: '+item.interface+"/"+item.address);
            });
            chan.close(); // close the channel. It is not autoclosed by default.
            conn.close(); // when closing connection, the socket is closed and program ends.
        });
    }).catch(error=>{
            console.log("Caught error:",error);
    });
```javascript

I ran your test, and did not have a problem.
I just noticed that you are installing rxjs v6, I make sure you only use 5 I have not updated to support the major breaking changes that v6 introduces.

from mikronode.

ras24 avatar ras24 commented on June 18, 2024

I tried to install v5 of rxjs and it works.
Thank you very much.

from mikronode.

Trakkasure avatar Trakkasure commented on June 18, 2024

No problem.

from mikronode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.