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

Reactivate connection on powersave change, misc cleanup. #45

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

Otterverse
Copy link
Member

@Otterverse Otterverse commented Nov 20, 2024

Doing a PR to Ale's branch for discussion. Needs to merge before that (#43) merges.

Tested on my Pi 5 and it works as expected. Only "catch" now is that if powersave is set explicitly, then the setting is removed entirely, the last remaining state "remains" until the next reboot (as the driver itself initially turned on powersave during boot.) That is, assuming the user hasn't manually configured their own setting.

@@ -29,6 +29,10 @@ const (
ConnCheckFilepath = "/etc/NetworkManager/conf.d/80-viam.conf"
ConnCheckContents = "[connectivity]\nuri=http://packages.viam.com/check_network_status.txt\ninterval=300\n"

wifiPowerSaveFilepath = "/etc/NetworkManager/conf.d/81-viam-wifi-powersave.conf"
Copy link
Member Author

Choose a reason for hiding this comment

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

These belonged here with similar definitions for the other files.

Also, changed filename to avoid potential collisions with user-managed/written files.

@@ -29,6 +29,10 @@ const (
ConnCheckFilepath = "/etc/NetworkManager/conf.d/80-viam.conf"
ConnCheckContents = "[connectivity]\nuri=http://packages.viam.com/check_network_status.txt\ninterval=300\n"

wifiPowerSaveFilepath = "/etc/NetworkManager/conf.d/81-viam-wifi-powersave.conf"
wifiPowerSaveContentsDefault = "# This file intentionally left blank.\n"
Copy link
Member Author

Choose a reason for hiding this comment

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

If not set, we basically want to not set anything. Explicitly setting 0 or 1 might still override another file in conf.d that a user put in place.

// When true, it will disable power save for all wifi connections managed by NetworkManager.
DisableWifiPowerSave *bool `json:"disable_wifi_power_save"`
// If set, will explicitly enable or disable power save for all wifi connections managed by NetworkManager.
WifiPowerSave *bool `json:"wifi_power_save"`
Copy link
Member Author

Choose a reason for hiding this comment

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

Double negatives are... weird. Changed to a postive. True == on == powersave. Let me know if that doesn't sound okay though.

Copy link
Member

Choose a reason for hiding this comment

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

good call

@@ -16,7 +16,7 @@ func (w *Provisioning) startGRPC() error {
bind := PortalBindAddr + ":4772"
lis, err := net.Listen("tcp", bind)
if err != nil {
return errw.Wrapf(err, "error listening on: %s", bind)
return errw.Wrapf(err, "listening on: %s", bind)
Copy link
Member Author

Choose a reason for hiding this comment

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

A bunch of these scattered around. Errors no need to say the word "error" as it's implicit in the fact that it IS an error. Saw one in the new code, and cleaned up all my own uses of this elsewhere to match.

}

// start portal with ssid list and known connections
if err := w.startPortal(inputChan); err != nil {
err = errors.Join(err, w.deactivateConnection(w.Config().HotspotInterface, w.Config().hotspotSSID))
return errw.Wrap(err, "could not start web/grpc portal")
return errw.Wrap(err, "starting web/grpc portal")
Copy link
Member Author

Choose a reason for hiding this comment

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

Another type of minor cleanup/standardization... Wrapped errors should provide context, and nothing more, as the error itself says what went wrong.

}

ssid := w.netState.ActiveSSID(w.cfg.HotspotInterface)
if w.connState.getConnected() && ssid != "" {
Copy link
Member

Choose a reason for hiding this comment

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

i guess we're checking with only do this if we're not in hotspot mode which is a good catch

Copy link
Member

@ale7714 ale7714 left a comment

Choose a reason for hiding this comment

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

thanks for the cleanup on the error logs too!

@Otterverse Otterverse merged commit 1b455bd into disable-wifi-power-save Nov 20, 2024
1 check passed
@Otterverse Otterverse deleted the powersave-james branch November 20, 2024 20:49
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