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

Wifi.connection(): Fetch network settings, normalize values #195

Merged
merged 9 commits into from
Sep 2, 2016

Conversation

HipsterBrown
Copy link
Contributor

@HipsterBrown HipsterBrown commented Aug 3, 2016

Fixes #178 - get connection info from system instead of in-memory cache
Fixes #190 - normalize security value on connection settings to match the standard configuration values, i.e. none, wep, psk, psk2
Fixes #192 - set a usable value to the connection ip property as opposed to of the seemingly random array of strings as ips.

This build changes how the Wifi.connection method works, making it an asynchronous request to the system requiring a callback argument to return the network settings. This will require a change of the documentation before releasing to the public, with a reference to that release version this change was made.

tessel.network.wifi.connection(callback);

function callback (error, networkSettings) {
  if (error) { throw error; }

  console.log(networkSettings); // should be an object containing the ssid, security, ip, and other network information
}

Smoke test:
Update a Tessel with the node/teasel-export.js from this PR. (See this gist for how to do this using sip)

mkdir t2-firmware-178
cd t2-firmware-178
t2 init
t2 wifi --ssid YourWifiNetwork --pass PasswordIfNeeded

Replace the content of index.js with the following:

// Import the interface to Tessel hardware
var tessel = require('tessel');

tessel.network.wifi.connection((error, settings) => {
  console.log('Callback!');

  if (error) {
    console.log(error);
  } else {
    console.log('Settings: ', settings);
  }
});

t2 run index.js

You should get a result like the following:

hipsterbrown:t2-firmware-178 $ t2 run index.js
INFO Looking for your Tessel...
INFO Connected to tessel-router.
INFO Building project.
INFO Writing project to RAM on tessel-router (3.072 kB)...
INFO Deployed.
INFO Running index.js...
INFO Connected to tessel-router.
Callback!
Settings:  { phy: 'phy0',
  ssid: 'Speak Friend',
  bssid: '54:E4:3A:E8:A0:1C',
  country: '00',
  mode: 'Client',
  channel: 1,
  frequency: 2412,
  txpower: 20,
  quality: 65,
  quality_max: 70,
  signal: -45,
  bitrate: 43300,
  encryption:
   { enabled: true,
     wpa: [ 2 ],
     authentication: [ 'psk' ],
     ciphers: [ 'ccmp' ] },
  hwmodes: [ 'b', 'g', 'n' ],
  hardware: { name: 'Generic MAC80211' },
  ip: '10.0.1.255',
  security: 'psk2' }

Pinging at least @rwaldron, @reconbot, @johnnyman727 for review and/or smoke testing.

@reconbot
Copy link
Member

reconbot commented Aug 3, 2016

I can't wait to check this out!

On Wed, Aug 3, 2016, 12:32 AM Nick Hehr notifications@github.com wrote:

Fixes #178 #178 - get
connection info from system instead of in-memory cache
Fixes #190 #190 - normalize
security value on connection settings to match the standard configuration
values, i.e. none, wep, psk, psk2
Fixes #192 #192 - set a
usable value to the connection ip property as opposed to of the seemingly
random array of strings as ips.

This build changes how the Wifi.connection method works, making it an
asynchronous request to the system requiring a callback argument to
return the network settings. This will require a change of the
documentation before releasing to the public, with a reference to that
release version this change was made.

tessel.network.wifi.connection(callback);
function callback (error, networkSettings) {
if (error) { throw error; }

console.log(networkSettings); // should be an object containing the ssid, security, ip, and other network information
}

Smoke test:
Update a Tessel with the node/teasel-export.js from this PR. (See this
gist https://gist.github.com/HipsterBrown/d0d24e9e1867ef4e5bb3 for how
to do this using scp)

mkdir t2-firmware-178
cd t2-firmware-178
t2 init

Replace the content of index.js with the following:

// Import the interface to Tessel hardwarevar tessel = require('tessel');
tessel.network.wifi.connection((error, settings) => {
console.log('Callback!');

if (error) {
console.log(error);
} else {
console.log('Settings: ', settings);
}
});

You should get a result like the following:

hipsterbrown:t2-firmware-178 $ t2 run index.js
INFO Looking for your Tessel...
INFO Connected to tessel-router.
INFO Building project.
INFO Writing project to RAM on tessel-router (3.072 kB)...
INFO Deployed.
INFO Running index.js...
INFO Connected to tessel-router.
Callback!
Settings: { phy: 'phy0',
ssid: 'Speak Friend',
bssid: '54:E4:3A:E8:A0:1C',
country: '00',
mode: 'Client',
channel: 1,
frequency: 2412,
txpower: 20,
quality: 65,
quality_max: 70,
signal: -45,
bitrate: 43300,
encryption:
{ enabled: true,
wpa: [ 2 ],
authentication: [ 'psk' ],
ciphers: [ 'ccmp' ] },
hwmodes: [ 'b', 'g', 'n' ],
hardware: { name: 'Generic MAC80211' },
ip: '10.0.1.255',
security: 'psk2' }

Pinging at least @rwaldron https://github.com/rwaldron, @reconbot
https://github.com/reconbot, @johnnyman727

https://github.com/johnnyman727 for review and/or smoke testing.

You can view, comment on, or merge this pull request online at:

#195
Commit Summary

  • chore(package): adds npm test script
  • feat(wifi): fetch connection from system, normalize security value
  • test(wifi): fetch connection from system, normalize security value
  • fix(wifi): resolve connection IP to usable value
  • test(wifi): resolve connection IP to usable value

File Changes

Patch Links:


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#195, or mute the thread
https://github.com/notifications/unsubscribe-auth/AABlbspa8X3z1NqNk9651eWmDAnb9JcHks5qcBnLgaJpZM4JbSuG
.

callback(error);
});
} else {
return callback(null, null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this return necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nope. Will fix. 👍

@HipsterBrown
Copy link
Contributor Author

@rwaldron You were correct about assuming too much success with the IP parsing. I've added a recursive check for an IP "Bcast" because an immediate check after restarting the wifi chip results in an error.

// This function keeps checking for that IP until it's available.
function recursiveIP(network) {
setImmediate(() => {
childProcess.exec('ifconfig wlan0', (error, ipResults) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since childProcess.exec is already going to call its callback asynchronously, I don't think this needs to be wrapped in setImmediate (unless I've misunderstood something)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably correct. I think this was me not really understanding the how childProcess.exec works. I'll try removing it and testing tonight. 👍

@HipsterBrown
Copy link
Contributor Author

@rwaldron You were also correct about not needing the setImmediate and that rad regex pattern. I did my smoke test with success. 🎉

@johnnyman727
Copy link
Contributor

LGTM feel free to merge

@johnnyman727 johnnyman727 merged commit 31c441d into tessel:master Sep 2, 2016
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

Successfully merging this pull request may close these issues.

None yet

4 participants