This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

connman-simplified-resin

0.1.6 • Public • Published

Connman simplified

Node.js package that simplifies Connman (Opensource connection manager) usage.
Enables you to easilly control connections over wifi and ethernet. Get realtime status changes.
Uses Connman-api package internally.
Connman: http://www.connman.net/

  • Abstracts Connman API making your code shorter and simpler.
  • Includes network cache system (for when scanning is impossible in hotspot mode).
  • Uses regular Node.js naming conventions.

Examples

Try to connect to favorite wifi network, if fails become hotspot. Log the wifi state changes.

var connman = require('connman-simplified')();
connman.init(function(err) {
  connman.initWiFi(function(err,wifi,properties) {
  
    if(!properties.connected) { // not yet connected? 
      wifi.joinFavorite(function(err) {
        if(err) wifi.openHotspot();
      });
    }
    wifi.on('state',function(value) {
      console.log("WiFi state change: ",value);
    });
    
  });
});

Join specific network, disconnect after 5 seconds.

var connman = require('connman-simplified')();
connman.init(function(err) {
  connman.initWiFi(function(err,wifi,properties) {
  
    wifi.join("myhomenetwork",'myPassphrase');
    
    setTimeout(function() {
      wifi.disconnect();
    },5000);
    
  });
});

Open a hotspot, get cached available networks, close after 5 seconds, get fresh available networks. Retrieving networks from cache is usefull because usually hardware can't scan while being hotspot.

var connman = require('connman-simplified')();
connman.init(function(err) {
  connman.initWiFi(function(err,wifi,properties) {
    
    wifi.openHotspot("myhotspot","aPassphrase",function(err) {
      // get cached available networks (collected earlier)
      wifi.getNetworksCache(function(err,list) {
        console.log("networks from cache: ",list);
      });
      
      setTimeout(function() {
        wifi.closeHotspot(function(err) {
          // get fresh available networks
          wifi.getNetworks(function(err,list) {
            console.log("networks: ",list);
          });
        });
      },5000);
    });
    
  });
});

Get a more readable networks list.
Uses common Connman services format, see: https://01.org/connman/documentation

var connman = require('connman-simplified')();
connman.init(function(err) {
  connman.initWiFi(function(err,wifi,properties) {
    
    wifi.getNetworks(function(err,list) {
      // get more readable list using getServicesString:
      console.log("networks: ",wifi.getServicesString(list));
    });
    
  });
});

Bigger interactive example is included.

Debugging

Uses Debug package, to see all logs run:

$export DEBUG=*

License

Licensed under the MIT License

Author

Peter Uithoven @ Doodle3D

Package Sidebar

Install

npm i connman-simplified-resin

Weekly Downloads

1

Version

0.1.6

License

MIT

Last publish

Collaborators

  • balena.io