Skip to content

Version 2: Optimised connection flow and bug fixes#1

Open
jayeheffernan wants to merge 10 commits intomysticpants:masterfrom
jayeheffernan:master
Open

Version 2: Optimised connection flow and bug fixes#1
jayeheffernan wants to merge 10 commits intomysticpants:masterfrom
jayeheffernan:master

Conversation

@jayeheffernan
Copy link
Copy Markdown

This pull request implements the following optimised connection flow:

  1. Try to connect to the currently configured network. This should normally be the last successfully configured network, and should have a high success rate if the device doesn't move around too much.
  2. Try to connect to any visible, known networks. Pick networks closer to the front of wifiList first if there are multiple candidates.
  3. If WIFIQUEUE_HIDDEN is set, try to connect to any other networks remaining in wifiList.
  4. If WIFIQUEUE_OPEN is set, call imp.scanwifinetworks() once to get a list of visible, open networks. Try to connect to each in turn, as long as it remains visible at the time of attempting to connect.
  5. If we have still not managed to connect to any network, call the onFail callback.

@dbns97 please review

@dbns97
Copy link
Copy Markdown
Collaborator

dbns97 commented Nov 22, 2017

Might be a good idea to allow the user to set whether it should connect in order of the wifiList or in order of signal strength

@dbns97 dbns97 self-requested a review November 22, 2017 06:17
Comment thread README.md Outdated

## Constructor: WifiQueue(*cm[, flags[, logger]]*)

The WifiQueue class is instantiated with a ConnectionManager object and two optional parameters, wifiList and logs.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This statement doesn't match the constructor...

Comment thread README.md
Flags are boolean options passed as the 3rd argument to the constructor. Multiple flags should be "added"/"stacked" with the binary "or" operator, `|`. All flags are off/`false` by default.

# setWifiList(wifiList)
#### WIFIQUEUE\_HIDDEN
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As discussed, I would keep this but also add the ability to specify individually on each network whether it is hidden or not. I would prioritise connections like this:
If the user has set priority to be based on RSSI:
1. Visible networks in order of RSSI
2. Any network in the list that is set to be hidden
3. Other open networks
If the user has set priority to be based on the list order, then just follow the list.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree with this but am not going to do it right now. If you want you can make an issue to request this as a v3.1.0 and someone will get to it eventually.

Comment thread WifiQueue.class.nut Outdated

// -----------------------
// `cm` is a connection manager instance
// `wifis` is an [ { ssid, pw } ]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This isn't actually a param in the constructor...

Comment thread WifiQueue.class.nut Outdated
_wifis = clone(wifis || []);

// Remove invalid entries
for (local i = _wifis.len() - 1; i >= 0; i--) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I probably wouldn't check if they're valid. Would just assume they are and let it fail if they're not.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

"let it fail" could mean an unhandled exception which causes the device to reboot and then repeatedly fail to connect

Comment thread README.md Outdated
### onConnect(*callback*)

This function sets a callback to be trigger whenever the device connects.
Sets a callback to be trigger whenever the device connects.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Make sure to document that it will also be called if connect() is called when the device is already connected.

Comment thread WifiQueue.class.nut
// `logger` is a logger object with `.log()` and `.error()` methods
constructor(cm, flags = null, logger = server) {
_cm = cm;
_logger = logger;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You shouldn't log unless the user has set a debug flag and if they have the logs should be prepended with: "WifiQueue:"

Comment thread README.md Outdated
})
.onFail(function() {
logger.error("WifiQueue failed to connect");
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This semi-colon shouldn't be here.
Also, you haven't defined logger but have used it.

@jayeheffernan jayeheffernan changed the title Version 3: Optimised connection flow and bug fixes Version 2: Optimised connection flow and bug fixes Nov 26, 2017
@dbns97
Copy link
Copy Markdown
Collaborator

dbns97 commented Nov 26, 2017

@blindman2k I've reviewed and think it's ready to merged.

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.

2 participants