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

RSDK-9808 Persist OTAA data across restarts #22

Merged
merged 17 commits into from
Feb 3, 2025
Merged

RSDK-9808 Persist OTAA data across restarts #22

merged 17 commits into from
Feb 3, 2025

Conversation

oliviamiller
Copy link
Collaborator

Currently, if the module is restarted the dev addr and keys will be lost and the device needs to resend a join request. This PR writes the OTAA info of each device to a file during the join procedure. When a previously known device is registered to the gateway through the docommand, the device's info is pulled from the file and added to the device object. Now the device does not need to be manually reset if the module gets restarted.

Testing: Added unit tests for each function, tested manually using tilt sensor.

To do:
[ ] more manual testing

Copy link
Collaborator

@JohnN193 JohnN193 left a comment

Choose a reason for hiding this comment

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

LGTM, random nit thoughts I'm having

  • wondering if all of the read/write/create stuff for the deviceInfo file should be in its own devicefile.go file, but the way things are organized now is fine.

  • it was alittle hard to parse the gateway.go DoCommand code, wondering if there could be another helper function in there. Gut says no because of how the deviceInfo != nil check is used

@@ -389,6 +410,22 @@ func (g *gateway) DoCommand(ctx context.Context, cmd map[string]interface{}) (ma
return nil, err
}
g.devices[node.NodeName] = mergedNode

// Check if the device is in the persistent data file, if it is add the OTAA info.
deviceInfo, err := g.searchForDeviceInFile(mergedNode.DevEui)
Copy link
Collaborator

Choose a reason for hiding this comment

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

spoke offline about this, technically the DoCommand and handlePacket can both interact with the file at the same time.

Possibly want a mutex just for reading the file? unsure of the right way to handle, or if its such a small chance of happening maybe we don't worry about it

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch, John - let's get some data. I can imagine Chris running this document with a user that has a file with many sensors; Olivia, can you fold that into your manual tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added 10 sensors to my config and sometimes got a nil pointer in docommand that locking the mutex fixed. I didn't see any issues with the handlepacket routine writing to the file but it might be because the join requests don't happen very often.

gateway/gateway.go Show resolved Hide resolved
gateway/uplink_test.go Outdated Show resolved Hide resolved
@oliviamiller oliviamiller merged commit 8fd19a3 into main Feb 3, 2025
2 checks passed
@oliviamiller oliviamiller deleted the savedata branch February 14, 2025 22:35
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.

3 participants