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

Add neutral wifi command to list Tessel Wifi Information #282

Closed
wants to merge 3 commits into from

Conversation

MrNice
Copy link
Contributor

@MrNice MrNice commented Sep 7, 2015

It does this:

~/s/t/bin ❯❯❯ /.nvm/versions/io.js/v2.2.1/bin/iojs tessel-2.js wifi
INFO Connecting to Tessel...
INFO Connected to pixel over USB
INFO Connected to "NETWORK"
INFO IP Address: 10.0.0.40
INFO Signal Strength: (61/70)
INFO Bitrate: 65mbps

Adds two commands, and a fairly painful method to wifi.js.

function closeFailedCommand(err) {
// If the returned value is an error
// Allow options to be partially applied
function closeFailedCommand(opts, err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@MrNice what's the rationale modifying this function? You could previouslyt report an error if you pass it an error or you can have it warn the user if it's just a string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Undoing, sorry.

@johnnyman727
Copy link
Contributor

@MrNice thanks for the contribution! It works really well when Tessel is connected. I added a few implementation notes on the relevant lines.

In addition, the t2 wifi command should report that it's not connected to WiFI according to the spec. Currently, it throws an angry error:

➜  t2-cli git:(add-wifi-command) t2 wifi
INFO Connecting to Tessel...
INFO Connected to Harold over USB
Unhandled rejection TypeError: Reduce of empty array with no initial value
    at Array.reduce (native)
    at /Users/Jon/Work/technical/t2-cli/lib/controller.js:467:14
    at tryCatcher (/Users/Jon/Work/technical/t2-cli/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/Users/Jon/Work/technical/t2-cli/node_modules/bluebird/js/main/promise.js:503:31)
    at Promise._settlePromiseAt (/Users/Jon/Work/technical/t2-cli/node_modules/bluebird/js/main/promise.js:577:18)
    at Promise._settlePromises (/Users/Jon/Work/technical/t2-cli/node_modules/bluebird/js/main/promise.js:693:14)
    at Async._drainQueue (/Users/Jon/Work/technical/t2-cli/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/Users/Jon/Work/technical/t2-cli/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/Jon/Work/technical/t2-cli/node_modules/bluebird/js/main/async.js:15:14)
    at processImmediate [as _immediateCallback] (timers.js:367:17)

Lastly, you'll have to run grunt when you finish writing your code. That will run our JSHinter, check for any styling issues and run our unit tests. It looks like this commit caused one of the unit tests to fail.

Let me know if you have any questions!

@johnnyman727
Copy link
Contributor

Actually, I can't reproduce the failure Travis detected... I'm restarting the test to check if it's an intermittent type of issue.

@MrNice
Copy link
Contributor Author

MrNice commented Sep 7, 2015

Re: Travis: last night it bounced this PR for jshint reasons, so I added 15
semicolons, but then it failed on a unit test that I couldn't reproduce
locally.

That specific error with the reduce will be fixed if its just passed an
array literal.

I'll work on this stuff when I get home.
On Sep 7, 2015 10:22 AM, "Jon" notifications@github.com wrote:

Actually, I can't reproduce the failure Travis detected... I'm restarting
the test to check if it's an intermittent type of issue.


Reply to this email directly or view it on GitHub
#282 (comment).

@johnnyman727
Copy link
Contributor

Ah the Travis issue is directly related to it being a build server with no USB peripherals. Somehow a path of code is running that attempts to get a USB Device List (not sure why this particular PR caused it though). I can look further into it later today.

.filter(function(addr) {
return addr.length;
});

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see this consolidated. The last three could be a single reduce

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the intent of the code is clear, why consolidate

I can replace the last three with the following

.reduce(function(list, ip) {
  if (/addr/.exec(item)) {
    var ip = chunk.split(':')[1];
    if (ip.length) list.push[ip];
  }
  return list;
});

But it doesn't make it more clear (to me) what is happening.

Copy link
Contributor

Choose a reason for hiding this comment

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

:/

This is what reduce is for: consolidating map/filter operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change it if that's wanted, but I don't think it's clearer.

On Tue, Sep 8, 2015 at 10:08 AM, Rick Waldron notifications@github.com
wrote:

In lib/controller.js
#282 (comment):

  •        .map(function(line) {
    
  •          return line.split(' ');
    
  •        })
    
  •        .reduce(function(a, b) {
    
  •          return a.concat(b);
    
  •        })
    
  •        .filter(function(item) {
    
  •          return /addr/.exec(item);
    
  •        })
    
  •        .map(function(chunk) {
    
  •          return chunk.split(':')[1];
    
  •        })
    
  •        .filter(function(addr) {
    
  •          return addr.length;
    
  •        });
    

:/

This is what reduce is for: consolidating map/filter operations.


Reply to this email directly or view it on GitHub
https://github.com/tessel/t2-cli/pull/282/files#r38951868.

@rwaldron
Copy link
Contributor

rwaldron commented Sep 8, 2015

In addition to @johnnyman727's review points and fixing the existing failure, this needs new tests to cover the new behavior.

@MrNice
Copy link
Contributor Author

MrNice commented Sep 8, 2015

@johnnyman727

Is this a reasonable error message?

~/s/t/bin ❯❯❯ iojs tessel-2.js wifi
INFO Connecting to Tessel...
INFO Connected to pixel over USB
ERR! This Tessel is not connected to Wi-Fi

@johnnyman727
Copy link
Contributor

@MrNice the issue with the spec suggests:

Not Connected (run 'tessel wifi -l' to see available networks)

I'd suggest one modification:

{TESSEL_NAME} is not connected to WiFi (run 'tessel wifi -l' to see available networks)

@johnnyman727
Copy link
Contributor

@MrNice did you need any more help with this or are you all good?

@MrNice
Copy link
Contributor Author

MrNice commented Sep 10, 2015

Oh I'm rushing around busy. Got those other 2 pr's to wrap up first :(

On Wed, Sep 9, 2015 at 7:38 PM, Jon notifications@github.com wrote:

@MrNice https://github.com/MrNice did you need any more help with this
or are you all good?


Reply to this email directly or view it on GitHub
#282 (comment).

@johnnyman727
Copy link
Contributor

No worries - just wanted to make sure you weren't hung up on anything from me.

@johnnyman727
Copy link
Contributor

@MrNice can I help merge this?

@MrNice
Copy link
Contributor Author

MrNice commented Sep 14, 2015

@johnnyman727 Wrapping this up and adding tests. Did we ever figure out travis?

@johnnyman727
Copy link
Contributor

Closing in favor of rebased and fixed #362.

@Frijol Frijol deleted the add-wifi-command branch October 6, 2015 16:20
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

3 participants