-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
There was a problem hiding this 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
gateway/gateway.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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