@@ -305,18 +305,63 @@ func rebaseNetworkConfiguration(nCfg utils.NetworkConfiguration) (utils.NetworkC
305305 }
306306
307307 // get default cfg. Hardcoded values + viam_defaults.json (if available - does not err if file does not exist).
308- newCfg , err := utils .StackOfflineConfig ()
308+ allDefaultsCfg , err := utils .StackOfflineConfig ()
309309 if err != nil {
310310 return nCfg , err
311311 }
312312
313313 // merge current cfg on over
314- err = json .Unmarshal (asJSON , & newCfg .NetworkConfiguration )
314+ finalCfg := allDefaultsCfg
315+ err = json .Unmarshal (asJSON , & finalCfg .NetworkConfiguration )
315316 if err != nil {
316317 return nCfg , err
317318 }
318319
319- return newCfg .NetworkConfiguration , err
320+ // because the input nCfg may be a "validated" config where validateConfig substitutes in certain missing values from utils.DefaultConfig,
321+ // we cannot tell whether that value was actually provided by the user or automatically substituted in.
322+ // for *non-bools*, assume that if one of these values is the same as the hardcoded default, it was subbed in, so replace it with the value
323+ // from allDefaultsCfg (hardcoded + viam_defaults)
324+ // This will either have no effect (if it wasn't specified in viam_defaults) or take the value from viam_defaults.
325+ // Unfortunately this will miss the case if a user has manually specified a value to overwrite the viam_defaults value,
326+ // but the user-provided value matches the hardcoded default.
327+ hardcodedCfg := utils .DefaultConfig ()
328+ if finalCfg .NetworkConfiguration .Manufacturer == hardcodedCfg .NetworkConfiguration .Manufacturer {
329+ finalCfg .NetworkConfiguration .Manufacturer = allDefaultsCfg .NetworkConfiguration .Manufacturer
330+ }
331+ if finalCfg .NetworkConfiguration .Model == hardcodedCfg .NetworkConfiguration .Model {
332+ finalCfg .NetworkConfiguration .Model = allDefaultsCfg .NetworkConfiguration .Model
333+ }
334+ if finalCfg .NetworkConfiguration .FragmentID == hardcodedCfg .NetworkConfiguration .FragmentID {
335+ finalCfg .NetworkConfiguration .FragmentID = allDefaultsCfg .NetworkConfiguration .FragmentID
336+ }
337+ if finalCfg .NetworkConfiguration .HotspotInterface == hardcodedCfg .NetworkConfiguration .HotspotInterface {
338+ finalCfg .NetworkConfiguration .HotspotInterface = allDefaultsCfg .NetworkConfiguration .HotspotInterface
339+ }
340+ if finalCfg .NetworkConfiguration .HotspotPrefix == hardcodedCfg .NetworkConfiguration .HotspotPrefix {
341+ finalCfg .NetworkConfiguration .HotspotPrefix = allDefaultsCfg .NetworkConfiguration .HotspotPrefix
342+ }
343+ if finalCfg .NetworkConfiguration .HotspotSSID == hardcodedCfg .NetworkConfiguration .HotspotSSID {
344+ finalCfg .NetworkConfiguration .HotspotSSID = allDefaultsCfg .NetworkConfiguration .HotspotSSID
345+ }
346+ if finalCfg .NetworkConfiguration .HotspotPassword == hardcodedCfg .NetworkConfiguration .HotspotPassword {
347+ finalCfg .NetworkConfiguration .HotspotPassword = allDefaultsCfg .NetworkConfiguration .HotspotPassword
348+ }
349+ if finalCfg .NetworkConfiguration .OfflineBeforeStartingHotspotMinutes ==
350+ hardcodedCfg .NetworkConfiguration .OfflineBeforeStartingHotspotMinutes {
351+ finalCfg .NetworkConfiguration .OfflineBeforeStartingHotspotMinutes =
352+ allDefaultsCfg .NetworkConfiguration .OfflineBeforeStartingHotspotMinutes
353+ }
354+ if finalCfg .NetworkConfiguration .UserIdleMinutes == hardcodedCfg .NetworkConfiguration .UserIdleMinutes {
355+ finalCfg .NetworkConfiguration .UserIdleMinutes = allDefaultsCfg .NetworkConfiguration .UserIdleMinutes
356+ }
357+ if finalCfg .NetworkConfiguration .RetryConnectionTimeoutMinutes == hardcodedCfg .NetworkConfiguration .RetryConnectionTimeoutMinutes {
358+ finalCfg .NetworkConfiguration .RetryConnectionTimeoutMinutes = allDefaultsCfg .NetworkConfiguration .RetryConnectionTimeoutMinutes
359+ }
360+ if finalCfg .NetworkConfiguration .DeviceRebootAfterOfflineMinutes == hardcodedCfg .NetworkConfiguration .DeviceRebootAfterOfflineMinutes {
361+ finalCfg .NetworkConfiguration .DeviceRebootAfterOfflineMinutes = allDefaultsCfg .NetworkConfiguration .DeviceRebootAfterOfflineMinutes
362+ }
363+
364+ return finalCfg .NetworkConfiguration , err
320365}
321366
322367// startProvisioningHotspot should only be called by 'StartProvisioning' (to
0 commit comments